本文主要是介绍Codeforces 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 force can investigate only one crime during his/her lifetime.
If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.
Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
The first line of input will contain an integer n (1 ≤ n ≤ 105), the number of events. The next line will contain n space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
Print a single integer, the number of crimes which will go untreated.
3 -1 -1 1
2
8 1 -1 1 -1 -1 1 1 1
1
11 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1
8
Lets consider the second example:
- Firstly one person is hired.
- Then crime appears, the last hired person will investigate this crime.
- One more person is hired.
- One more crime appears, the last hired person will investigate this crime.
- Crime appears. There is no free policeman at the time, so this crime will go untreated.
- One more person is hired.
- One more person is hired.
- One more person is hired.
The answer is one, as one crime (on step 5) will go untreated.
#include<iostream>
#include <cstring>
using namespace std;
int main()
{int n;while(cin>>n){int count=0,flag=0;for(int i=0;i<n;i++){int a;cin>>a;if(a>0)count+=a;else{if(count>0){count--;}elseflag++;}}cout<<flag<<endl;}return 0;
}
B. Prison Transfer
For this reason, he made the n prisoners to stand in a line, with a number written on their chests. The number is the severity of the crime he/she has committed. The greater the number, the more severe his/her crime was.
Then, the mayor told you to choose the c prisoners, who will be transferred to the other prison. He also imposed two conditions. They are,
- The chosen c prisoners has to form a contiguous segment of prisoners.
- Any of the chosen prisoner's crime level should not be greater then t. Because, that will make the prisoner a severe criminal and the mayor doesn't want to take the risk of his running away during the transfer.
Find the number of ways you can choose the c prisoners.
The first line of input will contain three space separated integers n (1 ≤ n ≤ 2·105), t (0 ≤ t ≤ 109) and c (1 ≤ c ≤ n). The next line will contain n space separated integers, the ith integer is the severity ith prisoner's crime. The value of crime severities will be non-negative and will not exceed 109.
Print a single integer — the number of ways you can choose the c prisoners.
4 3 3 2 3 1 1
2
1 1 1 2
0
11 4 2 2 2 0 7 3 2 2 4 9 1 4
6
#include <iostream>
#include <cstring>
using namespace std;
int main()
{int n,t,c;while(cin>>n>>t>>c){int num=0,a;int ans=0;for(int i=0;i<n;i++){cin>>a;if(a>t){if(ans>c-1)num+=ans-c+1;ans=0;}elseans++;}if(ans>c-1)num+=ans-c+1;cout<<num<<endl;}return 0;
}
这篇关于Codeforces Round #244 (Div. 2)——A. Police Recruits(水)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!