POJ:2586-Y2K Accounting Bug
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的更多相关文章
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- 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 ...
- POJ 2586 Y2K Accounting Bug(枚举洪水问题)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10674 Accepted: 53 ...
- POJ 2586 Y2K Accounting Bug(枚举大水题)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10674 Accepted: 53 ...
- POJ 2586 Y2K Accounting Bug 贪心 难度:2
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10537 Accepted: 52 ...
- [POJ 2586] Y2K Accounting Bug (贪心)
题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...
- 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) ...
- POJ - 2586 Y2K Accounting Bug (找规律)
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...
随机推荐
- DevExpress PivotGrid 使用记录
1.自定total值: 调试的时候,如果要定位,给一个index,然后,把e.CustomVale=index++;定位后,监视ds的值,每个ds的值不一样!
- Git操作(及操作github)
一.git操作: 1.创建一个项目: 2.打开项目,在项目目录下右键单击--打开 git bash: 3.初始化项目仓库 创建项目仓库 命令: git init ; git status 查看文 ...
- str中的join方法,fromkeys(),set集合,深浅拷贝(重点)
一丶对之前的知识点进行补充 1.str中的join方法.把列表转换成字符串 # 将列表转换成字符串,每个元素之间用_拼接 s = "_".join(["天",& ...
- 关于原生javascript的this,this真是个强大的东东
最近一直坐在东钿微信服务平台,上上级领导提出一个要求,就是微信分享. 因为首页是一个tab切换页,领导想在分享的时候区分上产调还是评估.我研究了很久很久,一直都是失败,今天领导又问了.于是我就向我们老 ...
- js基础的自定义属性练习
js基础的自定义属性练习: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type ...
- Java集合框架—Set
集合框架 Set的特点:无序,不可以重复元素. (1)HashSet:数据结构是哈希表.线程是非同步的. 保证元素唯一性的原理:判断元素的hashCode值是否相同. ...
- Android 设置资源字体,屏幕截图
字体设置 将下载的资源字体放在assets中, 引用设置 edit..setTypeface(Typeface.createFromAsset(getAssets(), "字体名.ttf&q ...
- iOS 应用架构 (一)
摘要:iOS 客户端应用架构看似简单,但实际上要考虑的事情不少.本文作者将以系列文章的形式来回答 iOS 应用架构中的种种问题,本文是其中的第一篇,主要讲架构设计的通识和方法论等,同时还讨论了大家关心 ...
- SQL Server 2012安装配置(Part4 )
SQL Server 2012安装配置(Part1) SQL Server 2012安装配置(Part2) SQL Server 2012安装配置(Part3 ) SQL Server 2012安装配 ...
- 【TensorFlow入门完全指南】模型篇·最近邻模型
最近邻模型,更为常见的是k-最近邻模型,是一种常见的机器学习模型,原理如下: KNN算法的前提是存在一个样本的数据集,每一个样本都有自己的标签,表明自己的类型.现在有一个新的未知的数据,需要判断它的类 ...