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.选择一个盘子里面的饼,分到其他盘子里面去; 目标是让盘子里的饼在最少的分钟数内吃完,问最少的分钟数。
785 0
|
4月前
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
1958 1
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
4月前
|
编解码 人工智能 算法
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
71 0
|
4月前
|
编解码 人工智能 数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
104 0
|
4月前
|
编解码
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
60 0
|
4月前
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
176 0
|
4月前
|
传感器 编解码 数据处理
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
89 0