Y2K Accounting Bug POJ2586
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
Source
Waterloo local 2000.01.29
解题思路:连续5个月之中。必定有亏损的月,有多少个月不确定,要使得盈利最大,可以将所有情况列出来,s代表盈利,d代表亏损:(样例可以看出判断条件是<还是>)
1.ssssd ssssd ss sum=10s-2d 判断条件:4s<d
2.sssdd sssdd ss sum=8s-4d, 判断条件:3s<2d
3.ssddd ssddd ss sum=6s-6d 判断条件:2s<3d
4.sdddd sdddd sd sum=3s-9d 判断条件:s<4d
5.ddddd ddddd dd sum=Deficit(必定亏损) 判断条件:s>=4d
AC代码:
#include <iostream>
using namespace std;
int main()
{
int s,d;
while(cin>>s>>d)
{
int res=;
if(*s<d)
res=*s-*d;
else if(*s<*d)
res=*s-*d;
else if(*s<*d)
res=*s-*d;
else if(s<*d)
res=*s-*d;
else
res=-;
if(res>)
cout<<res<<endl;
else
cout<<"Deficit"<<endl;
}
return ;
}
Y2K Accounting Bug POJ2586的更多相关文章
- [POJ2586]Y2K Accounting Bug
[POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
- POJ2586——Y2K Accounting Bug
Y2K Accounting Bug Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
- poj2586 Y2K Accounting Bug(贪心)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...
- Y2K Accounting Bug(贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10945 Accepted: 54 ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- Y2K Accounting Bug 分类: POJ 2015-06-16 16:55 14人阅读 评论(0) 收藏
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11222 Accepted: 56 ...
- 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 ...
- poj 2586 Y2K Accounting Bug
http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...
- poj 2586 Y2K Accounting Bug (贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8678 Accepted: 428 ...
随机推荐
- 大数据结构设计V1.0
- 在Chrome浏览器中点击链接,打开IE浏览器,跳转到指定页面并传递参数
需求: 在Chrome浏览器中点击链接,打开IE浏览器,跳转到指定页面并传递参数 过程: 一些应用软件可以通过点击URL链接启动并执行操作(例如迅雷),这是如何做到的呢? 主要是通过修改注册表,注册U ...
- [Python自学] day-19 (1) (FBV和CBV、路由系统)
一.获取表单提交的数据 在 [Python自学] day-18 (2) (MTV架构.Django框架)中,我们使用过以下方式来获取表单数据: user = request.POST.get('use ...
- Ubuntu 蓝牙鼠标一段时间失效的问题
问题: 我有一个小巧的蓝牙鼠标,但有一个问题. 当它不使用一段时间时,它会关闭. 好的我得按按钮把它打开. 但是我发现,在我在蓝牙小程序下单击"连接"之前,它不会再被Ubuntu识 ...
- STL中的BITSET运用
胡小兔的OI博客C++ bitset 常用函数及运算符 对于一个叫做foo的bitset: foo.size() 返回大小(位数) foo.count() 返回1的个数 foo.any() 返回是否有 ...
- Nim积的一种???的写法
Nim积总不能一直打四次暴力吧! 用SG定理等东西,可以证明 \((N, \oplus, \otimes)\) 构成一个域.(证明很难,我不会) 其中 \(\oplus\) 为异或, \(x \oti ...
- 数学函数(C/C++)
C中包含头文件<math.h> C++包含头文件<cmath> 函数 double cos(double) 该函数返回弧度角(double型)的余弦 double tan(do ...
- vue 监听键盘回车事件 @keyup.enter || @keyup.enter.native
vue运行为v-on在监听键盘事件时,添加了特殊的键盘修饰符:\ <input v-on:keyup.13="submit"> vue还非常贴心地给出了常用按键的别名, ...
- Redis 4.x RCE 复现学习
攻击场景: 能够访问远程redis的端口(直接访问或者SSRF) 对redis服务器可以访问到的另一台服务器有控制权 实际上就是通过主从特性来 同步传输数据,同时利用模块加载来加载恶意的用来进行命令执 ...
- Vue入门下
使用npm创建项目,系统会自动生成一些列文件. 以慕课网上的Travel项目来说,在生成的项目文件中存在src文件夹,这个文件夹也是平时在做项目的时候用的比较多的,其他的一些配置信息更改的频率较低. ...