C.Code Cleanups---Gym101933(暴力枚举)

Code Cleanups

Time Limit: 1 Sec Memory Limit: 128 Mb
上面的链接是比赛的,已经交不了了,如果想练一练的话可以在这里:
练习链接https://codeforces.com/gym/101933/problem/C
Description
The management of the software company JunkCode has recently found, much to their surprise and disappointment, that productivity has gone down since they implemented their enhanced set of coding guidelines. The idea was that all developers should make sure that every code change they push to the master branch of their software repository strictly follows the coding guidelines. After all, one of the developers, Perikles, has been doing this since long before these regulations became effective so how hard could it be?

Rather than investing a lot of time figuring out why this degradation in productivity occurred, the line manager suggests that they loosen their requirement: developers can push code that weakly violates the guidelines as long as they run cleanup phases on the code from time to time to make sure the repository is tidy.

She suggests a metric where the “dirtiness” of a developer’s code is the sum of the pushes that violate the guidelines – so-called dirty pushes – made by that developer, each weighted by the number of days since it was pushed. The number of days since a dirty push is a step function that increases by one each midnight following the push. Hence, if a developer has made dirty pushes on days 1, 2, and 5, the dirtiness on day 6 is 5+4+1=10. She suggests that a cleanup phase, completely fixing all violations of the coding guidelines, must be completed before the dirtiness reaches 20. One of the developers, Petra, senses that this rule must be obeyed not only because it is a company policy. Breaking it will also result in awkward meetings with a lot of concerned managers who all want to know why she cannot be more like Perikles? Still, she wants to run the cleanup phase as seldomly as possible, and always postpones it until it is absolutely necessary. A cleanup phase is always run at the end of the day and fixes every dirty push done up to and including that day. Since all developers are shuffled to new projects at the start of each year, no dirtiness should be left after midnight at the end of new year’s eve.

Input
The first line of input contains an integer n (1 ≤ n ≤ 365), the number of dirty pushes made by Petra during a year. The second line contains n integers d1, d2, …, dn (1 ≤ di ≤ 365 for each 1 ≤ i ≤ n) giving the days when Petra made dirty pushes. You can assume that di < dj for i < j​.

Output
Output the total number of cleanup phases needed for Petra to keep the dirtiness strictly below 20 at all times.

Sample Input
5
1 45 65 84 346


3
310 330 350

Sample Output
4


3


有时候读题真的是一件很痛苦的事情emmm。。。
题目大意是这样的,概念一个数组,a[i]代表第i天做了“污秽”的事,其每天的污秽度为前面有做污秽之事的时间与这天的差,比如,第一天、第二天和第五天做了“污污污”的事,则第六天的污秽度为5+4+1=10(即6-1=5 ,6-2=3 ,6-5=1),我们必须在污秽度达到20之前(严格小于20)将它清理干净,当然最后要为0,问你需要清理的天数;

题目的数据不大,为了节省思考的时间,我们可以直接暴力枚举,询问1-365每一天是否为必须清理的一天,如果是(即污秽度>=20),则天数++,记得最后的时候特判。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define max(a,b) (a>b)?a:b
#define ll long long
using namespace std;
int a[500],v[500]= {0};
int main() {
	int n,l,r,ans=0,maxx=0;
	scanf ("%d",&n);
	for (int i=1; i<=n; i++) {
		scanf ("%d",&a[i]);
		maxx=max(a[i],maxx);
		v[a[i]]=1;
	}
	int k=1,sum=0;
	for (int i=1; i<=maxx; i++) {
		for (int j=k; j<=i; j++) {
			if (v[j]) sum+=i-j;      //如果第j天有污,则累加
		}
		if (sum>=20) {
			for (int j=k; j<i; j++) 
				v[j]=0;
			k=i;
			ans++;	
			sum=0;
		}
		if (i==maxx && v[i])     //最后特判
		    ans++;
		sum=0;
	}
	printf ("%d\n",ans);
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值