poj 2586 Y2K Accounting Bug 【贪心】
来源:互联网 发布:linux安装挂载点 编辑:程序博客网 时间:2024/05/21 09:39
Y2K Accounting Bug
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 11993 Accepted: 6067
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.
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 237375 743200000 8496942500000 8000000
Sample Output
11628300612Deficit
Source
Waterloo local 2000.01.29
题意读了半天没读懂,T—T,大意是说每连续五个月都亏损,1-5,2-6,,,,9-12,但是他们不知道到底哪几个月亏损或盈余,求年底的盈余,else output Deficit if it is impossible
贪心的思想:为了使每五个月都亏损,应使亏损在最后面,才能保证多次使用;于是排列情况有
x=1 ssssd ssssd ss
x=2 sssdd sssdd ss
x=3 ssddd ssddd ss
x=4 sdddd sdddd sd
代码如下
#include<stdio.h>int main(){ int s,d; while(~scanf("%d%d",&s,&d)) { if(4*s-d<0&&10*s-2*d>0) printf("%d\n",10*s-2*d); else if(3*s-2*d<0&&8*s-4*d>0) printf("%d\n",8*s-4*d); else if(2*s-3*d<0&&6*s-6*d>0) printf("%d\n",6*s-6*d); else if(s-4*d<0&&3*s-9*d>0) printf("%d\n",3*s-9*d); else printf("Deficit\n"); }}
0 0
- POJ 2586 Y2K Accounting Bug贪心
- POJ 2586 Y2K Accounting Bug 贪心
- poj 2586 Y2K Accounting Bug 贪心
- poj 2586 Y2K Accounting Bug (贪心)
- POJ 2586 Y2K Accounting Bug 贪心策略
- POJ 2586 Y2K Accounting Bug 贪心
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ 2586:Y2K Accounting Bug:贪心法
- poj 2586 Y2K Accounting Bug (贪心)
- POJ 2586:Y2K Accounting Bug(贪心)
- POJ--2586:Y2K Accounting Bug (贪心)
- 【贪心】POJ-2586 Y2K Accounting Bug
- POJ 2586 Y2K Accounting Bug(贪心)
- poj 2586 Y2K Accounting Bug 【贪心】
- POJ 2586-Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug 简单贪心
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug (贪心)
- EventBus的源码分析:SubscriberMethodFinder和订阅流程
- 第十四周 项目一-线性表的折半查找
- jquery .index()一直返回-1的问题
- linux 64位编译32位protobuf
- T-SQL查询进阶--深入理解子查询
- poj 2586 Y2K Accounting Bug 【贪心】
- 1002 写出这个数 PAT
- 第14周项目5迷宫问题之图深度优先遍历解法
- windows下绑定线程(进程)到指定的CPU核心
- [c++]螺旋数递归实现
- 蓝牙BR/EDR和Bluetooth Smart的十大重要区别
- 高德地图
- 关于ViewPager中Fragment的延时加载问题
- 第十六周——【项目4 - 英文单词的基数排序】