Problem A. Standing Ovation
Problem's Link: https://code.google.com/codejam/contest/6224486/dashboard#s=p0
Mean:
题目说的是有许多观众,每个观众有一定的羞涩值,只有现场站起来鼓掌的人数达到该值才会站起来鼓掌,问最少添加多少羞涩值任意的人,才能使所有人都站起来鼓掌。
analyse:
贪心模拟一下,从前往后扫一遍就行。
Time complexity: O(n)
Source code:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std; const int MAXN=;
int n;
char s[MAXN];
int main()
{
// freopen("E:\\Code_Fantasy\\C\\A-small-attempt0.txt","r",stdin);
// freopen("E:\\Code_Fantasy\\C\\A-small-attempt1.txt","w",stdout);
int t;
scanf("%d",&t);
for(int Cas=;Cas<=t;++Cas)
{
scanf("%d",&n);
scanf("%s",s);
int ans=;
int shy=s[]-'';
for(int i=;i<=n;++i)
{
if(s[i]-''!=)
{
if(shy>=i)
shy+=(s[i]-'');
else
{
ans+=(i-shy);
shy=i+(s[i]-'');
}
}
}
printf("Case #%d: %d",Cas,ans);
if(Cas!=t) puts("");
}
return ;
}
Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation的更多相关文章
-
dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes
Problem B. Infinite House of Pancakes Problem's Link: https://code.google.com/codejam/contest/6224 ...
-
[C++]Store Credit——Google Code Jam Qualification Round Africa 2010
Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...
-
Google Code Jam 2010 Round 1C Problem A. Rope Intranet
Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...
-
[Google Code Jam (Qualification Round 2014) ] B. Cookie Clicker Alpha
Problem B. Cookie Clicker Alpha Introduction Cookie Clicker is a Javascript game by Orteil, where ...
-
[Google Code Jam (Qualification Round 2014) ] A. Magic Trick
Problem A. Magic Trick Small input6 points You have solved this input set. Note: To advance to the ...
-
[C++]Saving the Universe——Google Code Jam Qualification Round 2008
Google Code Jam 2008 资格赛的第一题:Saving the Universe. 问题描述如下: Problem The urban legend goes that if you ...
-
Google Code Jam 2010 Round 1C Problem B. Load Testing
https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...
-
Google Code Jam 2010 Round 1A Problem A. Rotate
https://code.google.com/codejam/contest/544101/dashboard#s=p0 Problem In the exciting game of Jo ...
-
Google Code Jam 2010 Round 1B Problem B. Picking Up Chicks
https://code.google.com/codejam/contest/635101/dashboard#s=p1 Problem A flock of chickens are runn ...
随机推荐
-
Angular依赖注入详解
Angular算是将后端开发工程化引入前端的先驱之一,而Dependency injection依赖注入(后面简称为DI)又是Angular内部运作的核心功能,所以要深入理解Angular有必要先理解 ...
-
加载默认图片,如何避免img标签陷入onerror事件死循环
当图片加载失败的时候,我们可以利用onerror事件赋予它默认图片,但是问题来了,假如默认图片又不存在呢,即加载失败,这个时候就会陷入死循环. 为了避免死循环的情况,我们可以在执行完onerror事件 ...
-
java并发编程(十一)线程间的通信notify通知的遗漏
notify通知的遗漏很容易理解,即threadA还没开始wait的时候,threadB已经notify了,这样,threadB通知是没有任何响应的,当threadB退出synchronized代码块 ...
-
存储过程返回布尔值以及C#相关处理
前段时间有在数据库以及程序之间使用到布尔(bool,Boolean)值的问题. 比如在SQL中,你想判断记录是否存? 通常你会这样写: FROM [dbo].[SixSResponsiblePerso ...
-
std result_of
#include <type_traits> auto call(const auto& f) -> typename std::result_of<decltype( ...
-
Bzoj4556: [Tjoi2016&;Heoi2016]字符串 后缀数组
4556: [Tjoi2016&Heoi2016]字符串 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 169 Solved: 87[Sub ...
-
[LINQ]查询关键字
摘自https://msdn.microsoft.com/zh-cn/library/bb310804.aspx,方便以后翻阅. from子句 查询表达式必须以 from 子句开头.另外,查询表达式还 ...
-
ORA-00845 Oracle 启不来修改 MEMORY_TARGET
1.内存减小导致Oracle启动不了 Last login: Sun Nov 4 15:09:06 2012 from 192.168.5.222 [oracle@h1 ~]$ sqlplus ...
-
Oracle DBA管理包脚本系列(二)
该系列脚本结合日常工作,方便DBA做数据管理.迁移.同步等功能,以下为该系列的脚本,按照功能划分不同的包.功能有如下: 1)数据库对象管理(添加.修改.删除.禁用/启用.编译.去重复.闪回.文件读写. ...
-
easy-ui treegrid 实现分页 并且添加自定义checkbox
首先第一点easy-ui treegrid 对分页没有好的实现, 因为在分页的过程中是按照 根节点来分页的 后台只能先按照 根节点做分页查询 再将子节点关联进去, 这样才能将treegrid 按 ...