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的更多相关文章

  1. 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 ...

  2. [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 ...

  3. 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 ...

  4. [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 ...

  5. [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 ...

  6. [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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. C#使用Dotfuscator混淆代码以及加密

    http://www.cnblogs.com/tianguook/archive/2012/10/06/2713105.html C#编写的代码如果不进行一定程度的混淆和加密,那么是非常容易被反编译进 ...

  2. python环境中运行程序

    运行Python程序,我们比较常用的是直接在Windows命令提示窗口或者Linux终端或shell窗口中,直接:Python *.py,或者在Linux环境下,在投不中,加入: #!/usr/bin ...

  3. Ant自动编译打包&发布 android项目

    Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我们自动编译打包了. ...

  4. NVelocity-0.4.2.8580 的修改记录[发个vs2008能用的版本] -- "It appears that no class was specified as the ResourceManager..." bug 修正等

    因为另有开发记录工具最新没怎么在 cnblog 写开发备忘.不过我觉得这个是个比较严重的问题,觉得有必要让更多的人知道处理方法,所以在 cnblog 也放上一篇希望广为传播. 因为现在网络上vs200 ...

  5. 菜鸟学JS(五)——window.onload与$(document).ready()

    我们继续说JS,我们常常在页面加载完成以后做一些操作,比如一些元素的显示与隐藏.一些动画效果.我们通常有两种方法来完成这个事情,一个就是window.onload事件,另一个就是JQuery的read ...

  6. 面向.Net程序员的Sql版本管理

    代码版本管理基本上程序员们都知道 TFS GIT SVN等等 但是对于数据库版本管理 java程序员或许会了解一些 但是.Net程序员收获的资料应该不多. 特别是现在云概念使用越来越广的情况下,与应用 ...

  7. WinDbg 命令集锦

    //断点相关 bp + 地址 设置断点bl  显示已经设定的断点bu + 地址 设置断点,但是这种类型断点再下一次启动时被记录bc 清除断点对于断点范围,可以用*匹配,-表示一个范围,表达多个可用,号 ...

  8. JS实现移动端图片延迟加载

    图片延迟加载常见的有,jquery.lazyload.js,原生JS实现的echo.js.但是都是必须给图片设置宽高. 因为项目是移动端,而且无法在加载前知道图片的宽高,所以,只好自己写了一个. 既然 ...

  9. Gson整合Volley返回对象--GsonRequest

    Gson是一个使用映射支持JSON与Java对象之间相互转换的库文件.你可以定义和JSON keys相对应名称的Java对象.把对象传递给传递Gson,然后Gson会帮你为对象填充字段值. 下面是一个 ...

  10. JAVA IO NIO

    http://www.cnblogs.com/handsome1013/p/4882862.html http://www.cnblogs.com/dolphin0520/ http://www.cn ...