CodeForces 427A Police Recruits

题意:给定 n 个数,有正数和-1, -1表示罪犯,正数表示招了几个警察,一个警察只能看一个罪犯,并且要按顺序,问你有多少罪犯逃脱。

析:很简单么,从开始扫到最后,把是正数就加上,是-1判断剩余警察大于0,如果是就让警察数减1,如果不是答案加1.

代码如下:

 #include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int a[maxn];

int main(){
    int n;
    while(cin >> n){
        for(int i = 0; i < n; ++i)  scanf("%d", &a[i]);
        int ans = 0;
        int of = 0;
        for(int i = 0; i < n; ++i){
            if(a[i] == -1){
                if(of)  --of;
                else  ++ans;
            }
            else  of += a[i];
        }
        cout << ans << endl;
    }
    return 0;
}
时间: 2024-08-24 14:49:36

CodeForces 427A Police Recruits的相关文章

Codeforces Round #244 (Div. 2) A. Police Recruits

题目的意思就是找出未能及时处理的犯罪数, #include <iostream> using namespace std; int main(){ int n; cin >> n; int a,recruit = 0, crimes = 0;; for(int i = 0 ; i < n; ++ i){ cin >> a; if(a > 0) recruit+=a; else recruit?recruit-- : crimes++; } cout<&

Round #244 (Div. 2) A. Police Recruits

A. Police Recruits The police department of your city has just started its journey. Initially, they don't have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police f

Codeforces Round #244 (Div. 2)

A. Police Recruits B. Prison Transfer A,B两个是水题. C. Checkposts DFS找出所有的环就行了. 每次搜索一个结点u时,给u加一个递增标号low[u],同时记录搜索u及u的子结点过程中遇到的最小标号minc,也就是当搜索u的子结点v时,minc = min(minc, low[v]).搜索完成后,如果minc < low[u],说明搜索u的子结点时又回到了u的父结点,也就是说u在一个环中,然后求出这个环的最小费用及取到最小费用的结点数. D.

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734

codeforces 359 C - Robbers&#39; watch

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their ow

Gym 101149I I - It&#39;s the Police

http://codeforces.com/gym/101149/problem/I 考虑下面这个例子 4 3 1 2 1 3 1 4 应该是选 0 0 1 1这样是最优的,我们不选1号,因为如果选1号作为非法分子点,那么2.3.4也不能有警察了,这不行. 那么究竟选呢? 很明显的一个道理是,选出儿子数最小的那个点,作为非法分子点,那么不放警察的地方就变得小了. #include <cstdio> #include <cstdlib> #include <cstring>

Codeforces Round #356 (Div. 2) [Codeforces680]

此处有目录↑ Codeforces Round #356(Div. 2):http://codeforces.com/contest/680 A. Bear and Five Cards (贪心) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A little bear Limak plays a game. He has

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b