POJ_2586_Y2K Accounting Bug_英语、贪心
来源:互联网 发布:mysql select 锁表 编辑:程序博客网 时间:2024/06/12 20:26
不知不觉回来训练都一周了,我一直这么逗比真的好吗?
题意:
我自认为英语还不错,然后这个题还是没读懂。。。
已知某公司这年每个月要么亏损d要么盈利s,并且已知每五个连续的月的总利润都是亏损的,求该公司这一年最多能盈利多少,如果不能盈利输出赤字的英语单词。
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.
可以根据s和t算一下每5个月最少有多少个月亏损,假设每个月都是盈利的,然后从第一个月开始的第一个五个月开始遍历,如果当前五个月中亏损月不足,就把最后几个月变成亏损月。因为从前往后遍历,把亏损月放在后面可以减少后面五月的亏损月。
代码如下:
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>using namespace std;int s,d;const int a[]={0,2,4,6,9,12};int main(){while(scanf("%d%d",&s,&d)!=EOF){int cnt=0;while(s*(5-cnt)-d*cnt>=0)++cnt;int ans=(12-a[cnt])*s-a[cnt]*d;if(ans<0)puts("Deficit");elseprintf("%d\n",ans);}return 0;}
0 0
- POJ_2586_Y2K Accounting Bug_英语、贪心
- Y2K Accounting Bug(贪心)
- 2586 Y2K Accounting Bug 贪心
- 【贪心】POJ2586 Y2K Accounting Bug
- poj2586 Y2K Accounting Bug 贪心
- POJ2586 Y2K Accounting Bug(贪心)
- POJ2586 Y2K Accounting Bug 贪心
- poj2586 Y2K Accounting Bug 贪心
- POJ_2586 Y2K Accounting Bug(贪心)
- poj2586 Y2K Accounting Bug 贪心
- POJ2586 Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug贪心
- POJ 2586 Y2K Accounting Bug 贪心
- poj 2586 Y2K Accounting Bug 贪心
- POJ2586《Y2K Accounting Bug》方法:贪心
- 2586 Y2K Accounting Bug 贪心 枚举
- poj 2586 Y2K Accounting Bug (贪心)
- POJ 2586 Y2K Accounting Bug 贪心策略
- java学习日记05——java中的浮点数剖析
- 学习历程之HTML第二篇
- 拓扑排序
- Sybase identity 字段
- HDu 4876(2014多校第二场 ZCC loves cards)
- POJ_2586_Y2K Accounting Bug_英语、贪心
- 集合框架(泛型类)
- UVA 488 Triangle Wave
- POJ 2531 Network Saboteur (搜索)
- OCP 1Z0 053 227
- 最小生成树-Prim算法和Kruskal算法
- JS感悟
- Vector的使用
- i.MX6高清双屏广告机