【贪心】POJ2586-Y2K Accounting Bug

【思路】

为了让最终盈利尽可能多,每五个月中要保证亏损月数尽可能最少;其次,五个月中亏损的月份要尽可能靠后。先计算出要保证每五个月亏损需要的最多盈利月数smonth,对于smonth(其中0表示亏损月份,1表示盈利月份):

如果smonth=0,必然亏损;

如果smonth=1,最优方案为100001000010,此时盈利3个月,亏损9个月;

如果smonth=2,最优方案为110001100011,此时盈利6个月,亏损6个月;

如果smonth=3,最优方案为111001110011,此时盈利8个月,亏损4个月;

如果smonth=4,最优方案为111101111011,此时盈利10个月,亏损2个月。

根据上述情形直接计算出结果即可。

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int s,d;
 5
 6 int main()
 7 {
 8     while (scanf("%d%d",&s,&d)!=EOF)
 9     {
10         int smonth;
11         for (smonth=4;smonth>=0;smonth--)
12             if (s*smonth-d*(5-smonth)<0) break;
13         int ans;
14         switch (smonth)
15         {
16             case 0:ans=-1;break;
17             case 1:ans=s*3-d*9;break;
18             case 2:ans=s*6-d*6;break;
19             case 3:ans=s*8-d*4;break;
20             case 4:ans=s*10-d*2;break;
21         }
22         if (ans>0) cout<<ans<<endl;
23                     else cout<<"Deficit"<<endl;
24     }
25     return 0;
26 }
时间: 2025-01-14 06:54:25

【贪心】POJ2586-Y2K Accounting Bug的相关文章

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

POJ2586——Y2K Accounting Bug

Y2K Accounting Bug 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

[POJ2586]Y2K Accounting Bug

试题描述 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

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.

贪心 --- Y2K Accounting Bug

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

Y2K Accounting Bug(poj2586)

题意: 有一个公司由于某个病毒使公司赢亏数据丢失,但该公司每月的 赢亏是一个定数,要么一个月赢利s,要么一月亏d.现在ACM只知道该公司每五个月有一个赢亏报表,而且每次报表赢利情况都为亏.在一年中这样的报表总共有8次(1到5,2到6,…,8到12),现在要编一个程序确定当赢s和亏d给出,并满足每张报表为亏的情况下,全年公司最高可赢利多少,若存在,则输出多多额,若不存在,输出"Deficit". 分析: 在保证连续5个月都亏损的前提下,使得每5个月中亏损的月数最少.          

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

Y2K Accounting Bug(贪心)

Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10945   Accepted: 5499 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 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

Y2K Accounting Bug(贪心)

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