http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22007#problem/EE - Y2K Accounting Bug
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit Status
Description
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc.
All what they remember is that MS Inc. posted a surplus or a deficit each month of 1999 and each month when MS Inc. posted surplus, the amount of surplus was s and each month when MS Inc. posted deficit, the deficit was d. They do not remember which or how many months posted surplus or deficit. MS Inc., unlike other companies, posts their earnings for each consecutive 5 months during a year. ACM knows that each of these 8 postings reported a deficit but they do not know how much. The chief accountant is almost sure that MS Inc. was about to post surplus for the entire year of 1999. Almost but not quite.
Write a program, which decides whether MS Inc. suffered a deficit during 1999, or if a surplus for 1999 was possible, what is the maximum amount of surplus that they can post.Input
Input is a sequence of lines, each containing two positive integers s and d.
Output
For each line of input, output one line containing either a single integer giving the amount of surplus for the entire year, or output Deficit if it is impossible.
Sample Input
59 237
375 743
200000 849694
2500000 8000000
Sample Output
116
28
300612
Deficit
/*题意:
给出每个月可能出现的亏空和盈利,d,s,
每连续五个月中的总额必产生赤字,在此前提下求,全年可能出现最大盈利的情况,若无盈利则输出“Deficit”
由于每连续五个月中都要出现赤字,且每次都要出现赤字
了解题意问题就不那么难了
这里分为五种情况,
SSSSDSSSSDSS
SSSDDSSSDDSS
SSDDDSSDDDSS
SDDDDSDDDDSD
DDDDDDDDDDD
*/
#include<stdio.h> #include<string.h> #include <iostream> using namespace std; int main() { int p[50]; int s[25],w[25]; int T,n,i,j,k,c; scanf("%d",&T); while(T--) { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&s[i]); memset(p,0,sizeof(p)); memset(w,0,sizeof(w)); k=1; s[0]=0; for(i=1;i<=n;i++) { for(j=0;j<s[i]-s[i-1];j++) p[k++]=1; k++; } c=1; for(i=1;i<k;i++) if(p[i]==0) { for(j=i-1;j>=1;j--) if(p[j]!=0) {w[c]++; if(p[j]==1) { p[j]=-1; c++; break; } } } for(i=1;i<c-1;i++) printf("%d ",w[i]); printf("%d\n",w[c-1]); } return 0; }
Y2K Accounting Bug(简单枚举)
最新推荐文章于 2022-03-26 18:59:50 发布