POJ 2586:Y2K Accounting Bug(贪心)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10024 | Accepted: 4990 |
Description
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
Output
Sample Input
59 237
375 743
200000 849694
2500000 8000000
Sample Output
116
28
300612
Deficit
题意是:
对于每个月来说,不是盈利,就是亏损,假设是盈利则盈利S,假设亏空则亏d。
每五个月进行一次统计,共统计八次(1-5月一次,2-6月一次.......8-12月一次)
统计的结果是这八次都是亏空。
问题:推断全年能否盈利,假设能则求出最大的盈利。
假设不能盈利则输出Deficit
贪心思想:
每五个连续的月一定亏损,也就是不能出现连续5个月盈利,我们能够设每五个月亏损月数最少为x,这样的情况下,
假设x能保证让这五个月为亏损,这是满足题意的盈利最大值!
(比x大的,盈利也少了,题意是让求最大利润),x仅仅能为1,2,3,4,5.
当然x=5时, 则一定亏空。。
除了则之后,也就仅仅有四种情况ssssd ssssd ss
sssdd sssdd ss
ssddd ssddd ss
sdddd sdddd sd
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath> using namespace std; #define M 100500 int main()
{
int s, d;
while(~scanf("%d%d", &s, &d))
{
if(s>4*d)
{
printf("Deficit\n");
continue;
}
int t = 1;
while(s*(5-t)>d*t)
t++;
int k;
if(t==4)
k = 2*t+1;
else
k = 2*t;
int ans = s * (12-k) - d*k;
if(ans>0)
printf("%d\n", ans);
else
printf("Deficit\n");
}
return 0;
}
POJ 2586:Y2K Accounting Bug(贪心)的更多相关文章
- poj 2586 Y2K Accounting Bug (贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8678 Accepted: 428 ...
- 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(贪心算法,水题一枚)
#include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- 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: 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 (贪心)
题目链接: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 ...
随机推荐
- 用TinyXml2读取XML文件的一个简单Demo
废话少说直接上代码,需要的人自然一看便懂,对于第一次接触TinyXml2的人来说还是有帮助的. <?xml version="1.0"?> <Table name ...
- 微信公众平台PHP开发
p=932" style="color: rgb(255, 153, 0); text-decoration: none;">微信公众平台PHP开发 2013.05 ...
- 只能从脚本中调用在类定义上有[ScriptService]属性的Web服务问题的解决方案
ajax调用webservice中的接口时, 会出现[只能从脚本中调用在类定义上有[ScriptService]属性的...]的异常. 这是因为, 在.net3.5中, 访问web服务, 要对web服 ...
- 我的EJB学习历程
http://blog.csdn.net/sinapaper/archive/2004/06/28/28659.aspx http://blog.csdn.net/sinapaper/archive/ ...
- solr4.9r+ Eclipse 4.3+ tomcat 7.5 +winds7(二)
尊重原创,原文地址:http://blog.csdn.net/chunlei_zhang/article/details/38778945 这另外一种方法是将solr项目部署到tomcat上,执行to ...
- xcode project
An Xcode project is a repository for all the files, resources, and information required to build one ...
- ORA-00600: 内部错误代码, 参数: [kqlnrc_1]
如以下的错误: Mon Mar 31 18:45:59 2014 Errors in file /oracle/app/oracle/diag/rdbms/zscims/zscims2/trace/z ...
- 【DRP】删除递归树的操作
正如图呈现的树结构.本文从任意节点删除树形结构.提供解决方案 图中,不包括其他结点的是叶子结点.包括其他结点的是父结点,即不是叶子结点. 一 本文的知识点: (1)递归调用: 由于待删除的结点的层次是 ...
- PHP 文件操作类(创建文件并写入) 生成日志
<?php /** * 文件操作(生成日志)支持多条插入 * (假设插入多条语句并换行 用','逗号分开) * */ class log { public $path = './info.txt ...
- UVA 11235 Frequent values(RMQ)
Frequent values TimeLimit:3000Ms , ... , an in non-decreasing order. In addition to that, you are gi ...