2251: Code Cleanups

原题:http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2251

题意:a[i]天会出现一个垃圾,如果不清扫每天都会+1个垃圾.不能超过20个垃圾不清扫,问你最少清扫几次

题解:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int main(){
 5     std::ios::sync_with_stdio(false);
 6     std::cin.tie(0);
 7     std::cout.tie(0);
 8     
 9     int n,ans=0,x=0,t=1;//ans计数 x表示累积的垃圾 t每天増率 
10     int a[366];
11     cin>>n;
12     for(int i=0;i<n;i++){
13         cin>>a[i];
14     }
15     for(int i=0;i<n-1;i++){
16         
17         if((19-x+t)/t>a[i+1]-a[i]) {//(19-x+t)/t表示可以以t増率增加垃圾的天数>a[i+1]与a[i]间天数,即a[i+1]天之前不清理 
18             
19             x+=(a[i+1]-a[i])*t;//加上a[i]->a[i+1]期间累积的垃圾 
20             t++;
21         }
22         else {
23             ans++;
24             x=0;
25             t=1;
26         }
27     }
28     ans++;
29     cout<<ans<<endl;
30     return 0;
31 }

  

原文地址:https://www.cnblogs.com/YJing814/p/10509925.html