Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation
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 ...
随机推荐
- 使用6to5,让今天就来写ES6的模块化开发!
http://es6rocks.com/2014/10/es6-modules-today-with-6to5/?utm_source=javascriptweekly&utm_medium= ...
- c10k问题及其解决方案
本文主要讲述高并发http应用中的c10k瓶颈问题:在很多服务器初始状态下,无法服务1w左右的并发连接.这与每次服务的资源消耗.服务器的硬件配置固然有关,但很多时候是被linux的默认配置以及软件st ...
- 用户管理 之 Linux 用户(User)查询篇
用户(User)和用户组(Group)的配置文件,是系统管理员最应该了解和掌握的系统基础文件之一,从另一方面来说,了解这些文件也是系统安全管理的重要组成部份:做为一个合格的系统管理员应该对用户和用户组 ...
- 通信错误:(-1)[描述:无法解析路由器DDNS地址,请检查DDNS状态.] 解析办法
EasyRadius提示:通信错误:(-1)[描述:无法解析路由器DDNS地址,请检查DDNS状态.] 出现以上问题,和easyradius没有直接的联系,主要产生原因有两种可能: 可能1:easyr ...
- SQL语句 - 嵌套查询
嵌套查询的意思是,一个查询语句(select-from-where)查询语句块可以嵌套在另外一个查询块的where子句中,称为嵌套查询.其中外层查询也称为父查询,主查询.内层查询也称子查询,从查询. ...
- 精选19款华丽的HTML5动画和实用案例
下面是本人收集的19款超酷HTML5动画和实用案例,觉得不错,分享给大家. 1.HTML5 Canvas火焰喷射动画效果 还记得以前分享过的一款HTML5烟花动画HTML5 Canvas烟花特效,今天 ...
- getRequestURI,getRequestURL的区别
转自:http://www.cnblogs.com/JemBai/archive/2010/11/10/1873764.html test1.jsp======================= &l ...
- 把Arraylist转换成GameObject[]
ArrayList a = new ArrayList(); GameObject g = new GameObject("g"); a.Add(g); GameObject[] ...
- ImageSource的使用
很多时候,我们会使用图片来装饰UI,比如作为控件背景等.而这些图片可以分为两种形式,即存在于本地文件系统中的图片和存在于内存中的图片对于这两种形式的图片,在WPF中,使用方法不同,下面主要说明针对这两 ...
- 看上去很美 国内CDN现状与美国对比
CDN的理想与现实 多年以前,当<Kingdom of Heaven>这部史诗电影发行的时候,中国的影迷使用电驴和BT来寻找种子,而那个时候,高清也才刚刚进入电影领域,我的同事不惜用自家的 ...