题解归档 - cf427A
本文最后由方少年更新于2026 年 6 月 28 日,已超过0天没有更新。如果文章内容或图片资源失效,请留言反馈,将会及时处理,谢谢!
题解归档 - cf427A
本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。
- 本地编号:
cf427A - 本地来源:
problems/cf427A/idea.md - 题目链接:https://codeforces.com/contest/427/problem/A
- 原始标题:cf427A — Police Recruits
思路
cf427A — Police Recruits
题意
按时间顺序处理 n 个事件:-1 表示一起犯罪,正整数表示同时招募的警员数。每名警员一生只能处理一起犯罪;犯罪发生时若有空闲警员则消耗一名,否则该犯罪未处理。求未处理犯罪数。
做法
维护当前空闲警员数 cnt:
- 事件为
-1:若cnt>0则cnt--,否则ans++ - 否则
cnt += 招募人数
验证
- 官方样例 3 组
- 边界:仅招募、无犯罪 → 答案 0
代码
来源:problems/cf427A/solution.cpp
/* Author: likely
* Time: 2026-06-08 04:39:18
**/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,i,j,k,zc,pd,cur,dq,cnt,ans;
int main(){
cin>>n;
cnt=0;
ans=0;
for(i=1;i<=n;i++){
cin>>zc;
if(zc==-1){
if(cnt>0) cnt--;
else ans++;
}else cnt+=zc;
}
cout<<ans<<"\n";
return 0;
}
~ ~ The End ~ ~
文章标题:题解归档 - cf427A
文章链接:https://www.fangshaonian.cn/archives/341/
最后编辑:2026 年 6 月 28 日 19:07 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)