您的位置:首页 > 其它

Y2K Accounting Bug

2016-07-28 19:42 309 查看
C - Y2K Accounting Bug
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld
& %llu
Submit Status Practice POJ
2586

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


     POJ 2586   t题目意思大概如下

  占计算机机械师(ACM)患了千年虫,失去了一些重要数据为女士准备年度报告公司。   所有他们记住女士inc .)发布盈余或赤字1999每个月,每个月当女士inc .)发布盈余,盈余的数量和每个月当女士inc .)公布的赤字,赤字是d。他们不记得多少个月发布的盈余或赤字。女士公司,与其他公司不同,职位收入为每个连续5个月在一年。ACM知道这些8帖子报道赤字,但他们不知道多少。总会计师几乎是确保公司女士即将发布1999年全年顺差。但不完全。
     编写一个程序,它决定是否女士inc .在1999年遭受了赤字,或者如果盈余1999是可能的,什么是盈余的最大数量,他们可以。   输入   行输入序列,每个包含两个正整数s和d。   输出   每一行的输入、输出一行包含一个整数给盈余全年的数量,或输出赤字,如果这是不可能的。  

<span style="font-size:10px;">题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D。</span>
<span style="font-size:12px;"><span style="font-size:10px;">公司每五个月进行一次统计,<span style="color: rgb(204, 0, 0);">全年共统计8次(1-5、2-6、3-7、4-8、5-9、6-10、7-11、8-12),</span></span></span>
<span style="font-size:12px;"><span style="font-size:10px;"><span style="color: rgb(204, 0, 0);">已知这8次统计的结果全部是亏空</span>(盈利-亏空<0)。题目给出S和D,判断全年是否能盈利,如果能则</span></span>
<span style="font-size:10px;">求出盈利的最大值,如果不能盈利则输出Deficit</span>
<span style="font-size:10px;">输入:每月盈利和亏空的数值(每月都一样)</span>
<span style="font-size:10px;">输出:能最大盈利多少,不能则输出Deficit</span>
<span style="font-size:10px;">题意懂了,其他都不难了,一共统计8次,8次都是亏空的,要保证尽量盈利。所以把亏空放到5月份,</span>
<span style="font-size:10px;">如果还不能保证1-5月总额亏空,再在4月亏空,以此类推,直到1-5月亏空,6-10月复制1-5月。</span>
<span style="font-size:10px;">全年的盈亏情况可以由前五个月直接决定</span>
<span style="font-size:10px;">1、若SSSSD亏空,那么全年最优情况为SSSSDSSSSDSS
2、若SSSDD亏空,那么全年最优情况为SSSDDSSSDDSS
3、若SSDDD亏空,那么全年最优情况为SSDDDSSDDDSS
4、若SDDDD亏空,那么全年最优情况为SDDDDSDDDDSD
5、若DDDDD亏空,全年必亏空...</span>
直接上代码

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