您的位置:首页 > 其它

pku 2586 Y2K Accounting Bug 第一周训练——贪心

2012-02-24 21:21 239 查看
http://poj.org/problem?id=2586

刚开始看了很长时间都没看懂题意,最后还是看了discuss里面讲的才懂了。开始还把连续五个月都会抱亏的题意理解错了。我理解成1 - 5 6 - 10 11-12 了。。心想怎么会一年8次呢。最后才看到原来是1-5 2-6 3 -7 4 - 8 5 -9 6 -10 7 -11 8 -12这8次报表时都是亏空的。而每个月可能盈利,也可能亏空所以这样就会导致全年盈利的情况了。

这题的贪心在于,这8次中,出了第一次每一次都会和上一次重复利用连续的四个月的盈亏情况,所以我们贪心的让他们共用亏空,这样就会使盈利的月份增多,所以能够获得最大利润。

View Code

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#define maxn 13
using namespace std;

int main()
{

int s,d;
while (~scanf("%d%d",&s,&d))
{
int sum = -1;
if (4*s < d)
sum = 10*s - 2*d;
else if (3*s < 2*d)
sum = 8*s - 4*d;
else if (2*s < 3*d)
sum = 6*s - d*6;
else if (s < 4*d)
sum = 3*s - 9*d;
if (sum > 0)
{
printf("%d\n",sum);
}
else
printf("Deficit\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: