poj 2586Y2K Accounting Bug

//这道题用到了贪心的思想,首先题目意思如下:ACM遭到了一个bug使得重要数据丢失,然后只知道s(盈余)和d(亏损),每个月的盈余和亏损是一样的,然后该公司每5个月统计一次,即1到5,2到6,3到7,……,8到12,都是亏损的,然后问你该公司今年收入最多是多少?

//所谓的贪心就是想尽办法达到最多的盈余,稍微分析可知,亏损放在越后面越好,因为已知每次统计都有重叠,一开始没有重叠,然后2,3,等都有共有的,用区间表示更加清楚,然后在有盈余和亏损一样的特点可知每次5个月的统计亏损的数量都是一样的,这样才能保证收入最大(贪心的重要体现),然后就有如下:

如果ssssd <0 ,那么每个月都是只有1次亏损,即ssssd,ssssd,ss;共10次s;

如果sssdd<0,那么每个月都是只有2次亏损,即sssdd,sssdd,ss;共8次s;

如果ssddd<0,那么每个月都是只有3次亏损,即ssddd,ssddd,ss;共6次s;

如果sdddd<0,那么每个月都是只有4次亏损,即sdddd,sdddd,sd;共3次s;

5次直接赋值为-1;

 1 #include <iostream>
 2 #include <cmath>
 3 #include <cstdio>
 4 using namespace std;
 5
 6 int main()
 7 {
 8     int s, d, numd, sum;
 9     while(~scanf("%d%d", &s, &d)){
10         for(int i = 1; i <= 5; i++)
11             if((5-i)*s-i*d < 0){
12                 numd = i;
13                 break;
14             }
15         if(numd == 1)
16             sum = 10*s-2*d;
17         else if(numd == 2)
18             sum = 8*s-4*d;
19         else if(numd == 3)
20             sum = 6*s-6*d;
21         else if(numd == 4)
22             sum = 3*s-9*d;
23         else if(numd == 5)
24             sum = -1;
25         if(sum < 0)
26             printf("Deficit\n");
27         else
28             printf("%d\n", sum);
29     }
30     return 0;
31 }

时间: 2024-12-28 20:13:30

poj 2586Y2K Accounting Bug的相关文章

** poj Y2K Accounting Bug 2586

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10117   Accepted: 5043 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc

poj 2586 Y2K Accounting Bug (贪心)

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9632   Accepted: 4806 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc.

Poj 2586 / OpenJudge 2586 Y2K Accounting Bug

1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10520   Accepted: 5257 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some

POJ 2586:Y2K Accounting Bug(贪心)

Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10024 Accepted: 4990 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc. Al

POJ 2586 Y2K Accounting Bug(枚举大水题)

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 5344 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc

poj 2586 Y2K Accounting Bug

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10150   Accepted: 5061 题目大意:有家公司每个月有盈余s 和亏损d但不知道具体是那个月 只知道一年中每个连续的五个月都是亏损的.要求求出该公司这一年里最大的盈利的可能金额 若不能盈利就输出Deficit 注意如果s>4d也是要输出Deficit的 可以用分类方法去做 注意要保证每连续的五个月中都有n个d保证这五个月是

POJ 2580 Y2K Accounting Bug 贪心

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10120   Accepted: 5046 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc

poj 2586 Y2K Accounting Bug【贪心】【刷题计划】

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16154   Accepted: 8111 Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc

poj2586 Y2K Accounting Bug(贪心)

转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 Language: Default Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9979   Accepted: 4970 Description Accounting for Computer