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:  题目说的是有许多观众,每个观众有一定的羞涩值,只有现场站起来鼓掌的人数达到该值才会站起来鼓掌,问最少添加多少羞涩值任意的人,才能使所有人都站起来鼓掌。

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=1110;
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=1;Cas<=t;++Cas)
        {
                scanf("%d",&n);
                scanf("%s",s);
                int ans=0;
                int shy=s[0]-'0';
                for(int i=1;i<=n;++i)
                {
                        if(s[i]-'0'!=0)
                        {
                                if(shy>=i)
                                        shy+=(s[i]-'0');
                                else
                                {
                                        ans+=(i-shy);
                                        shy=i+(s[i]-'0');
                                }
                        }
                }
                printf("Case #%d: %d",Cas,ans);
                if(Cas!=t) puts("");
        }
        return 0;
}
View Code

 

 

目录
相关文章
|
人工智能
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/6224486/dashboard#s=p1   Mean:  有无限多个盘子,其中有n个盘子里面放有饼,每分钟你可以选择两种操作中的一种: 1.n个盘子里面的饼同时减少1; 2.选择一个盘子里面的饼,分到其他盘子里面去; 目标是让盘子里的饼在最少的分钟数内吃完,问最少的分钟数。
805 0
|
9月前
|
存储 编解码 数据可视化
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
【2月更文挑战第14天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,按照给定的地表分类数据,对每一种不同的地物类型,分别加以全球范围内随机抽样点自动批量选取的方法~
761 1
Google Earth Engine获取随机抽样点并均匀分布在栅格的不同数值区中
|
9月前
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
2911 1
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
9月前
|
机器学习/深度学习 算法 数据可视化
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
294 0
|
9月前
|
数据处理
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
141 0
|
9月前
|
编解码 人工智能 算法
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
126 0
|
9月前
|
数据采集 编解码 人工智能
Google Earth Engine(GEE)——全球每日近地表空气温度(2003-2020年)
Google Earth Engine(GEE)——全球每日近地表空气温度(2003-2020年)
294 0