Y2K Accounting Bug

Time Limit: 1000MS Memory Limit: 65536K

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


  • 题意就是公司有八次财政总结,每五个月总结一次(1-5,2-6,3-7,4-8,5-9,6-10,7-11,8-12),每次得出的总结都是亏损,每个月如果盈利只能盈利s,如果亏损只能亏损d,问这一年类十二个月盈利和亏损怎么分布才能让这一年的盈利最大,输出最大盈利,如果不能盈利或者不能符合要求输出“Deficit”。

  • 这个题就是欺负你英语不好读不懂题意,其实还是很简单的只要每次猜中总结亏损都亏损在连续五个月中的后面几个月就好,这样可以让亏损在12个月中分布均匀,符合每五个月都亏损的情况,具体情况如下:

    • ssssd,sssdd,ssddd,sdddd,ddddd

丑代码:

#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
int Max,s,d;
bool flag; void check_times(int k)
{
int y = 5-k;
if(k*d - y*s <= 0)
return ;
flag = true;
if(k == 1)
k = 2,y = 10;
else if(k == 2)
k = 4,y = 8;
else if(k == 3)
k = 6,y = 6;
else if(k == 4)
k = 9, y = 3;
else if(k == 5)
k = 12,y = 0;
int ans = y*s - k*d;
Max = max(ans,Max);
} int main()
{
while(scanf("%d%d",&s,&d) != EOF)
{
Max = -10000000;
flag = false;
for(int i=1;i<=5;i++)
check_times(i);
if(!flag || Max < 0)
printf("Deficit\n");
else
printf("%d\n",Max);
}
return 0;
}

POJ:2586-Y2K Accounting Bug的更多相关文章

  1. 贪心 POJ 2586 Y2K Accounting Bug

    题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...

  2. Poj 2586 / OpenJudge 2586 Y2K Accounting Bug

    1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS   Memory Lim ...

  3. poj 2586 Y2K Accounting Bug

    http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...

  4. poj 2586 Y2K Accounting Bug (贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8678   Accepted: 428 ...

  5. POJ 2586 Y2K Accounting Bug(枚举洪水问题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

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

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  7. POJ 2586 Y2K Accounting Bug 贪心 难度:2

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10537   Accepted: 52 ...

  8. [POJ 2586] Y2K Accounting Bug (贪心)

    题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...

  9. POJ 2586 Y2K Accounting Bug(贪心)

    题目连接:http://poj.org/problem?id=2586 题意:次(1-5.2-6.3-7.4-8.5-9.6-10.7-11.8-12),次统计的结果全部是亏空(盈利-亏空<0) ...

  10. POJ - 2586 Y2K Accounting Bug (找规律)

    Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...

随机推荐

  1. Linux关闭/开启防火墙命令

    Linux还是比较常用的,于是我研究了一下Linux关闭防火墙命令,在这里拿出来和大家分享一下,希望你能学会Linux关闭防火墙命令 . 1) 永久性生效,重启后不会复原 开启: chkconfig ...

  2. svn检出项目报错

    首先,我在浏览器访问svn检出项目地址是正常的,那么应该就是svn缓存的问题 1.         右键点击本地副本,TortoiseSVN -> Settings -> Saved Da ...

  3. 【.Net MVC4 connectionString设置】获取SQL server数据库的连接字符串

    第一步:创建向导文件 在桌面创建一个txt文件,并将文件后缀改成“.udl”.    第二步:选择“提供程序”tab页 双击新创建的“.udl”文件,进入后选择“提供程序”tab页,选择“Micros ...

  4. C#入门笔记3 表达式及运算符2

    关系运算符,也称布尔比较运算符 注:var1为bool类型,var2与var3可以是其它类型.[数据类型看下一节] 运算符 类别 示例表达式 结果说明 == 二元 var1=var2==var3 如果 ...

  5. Android使用AchartEngine绘制曲线图

    1.在布局文件中加入LinearLayout布局,如下: <LinearLayout android:id="@+id/chart" android:orientation= ...

  6. Volley解析(一)--Volley的使用

    Volley解析(一)--Volley的使用 Volley 是一个HTTP协议的网络请求框架 Volley的优势: 自动安排网络请求 支持多个并发网络连接 具有标准HTTP缓存一致性的透明磁盘和内存响 ...

  7. SQL SEVER数据库重建索引的方法

    一.查询思路 1.想要判断数据库查询缓慢的问题,可以使用如下语句,可以列出查询语句的平均时间,总时间,所用的CPU时间等信息 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...

  8. jmeter参考网址

    http://blog.csdn.net/dongdong9223/article/details/49248979 http://blog.csdn.net/hjh00/article/detail ...

  9. SingletonLoginUser

    package cn.com.jgt.view{ import flash.errors.IllegalOperationError; /** * actionscript类的构造方法不能是priva ...

  10. 批量格式化json

    单个文件格式化工具: vscode和sublime都有格式化json的插件. 但是笔者遇到的情况是有几百个文件需要格式化,不可能每个文件都打开,进行分别格式化. 于是写了一个python脚本,非常强大 ...