poj 2586 Y2K Accounting Bug
http://poj.org/problem?id=2586
大意是一个公司在12个月中,或固定盈余s,或固定亏损d.
但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为亏损),而一年中只有8个连续的5个月,分别为1~5,2~6,…,8~12
问全年是否可能盈利?若可能,输出可能最大盈利金额,否则输出“Deficit".
贪心,符合最优子结构性质。5个月统计一次都亏空,那么有5种情况:
1、若SSSSD亏空,那么全年可能最大盈利情况为: SSSSDSSSSDSS
2、若SSSDD亏空,那么全年可能最大盈利情况为:SSSDDSSSDDSS
3、若SSDDD亏空,那么全年可能最大盈利情况为: SSDDDSSDDDSS
4、若SDDDD亏空,那么全年可能最大盈利情况为: SDDDDSDDDDSD
5、若DDDDD亏空,那么全年可能最大盈利情况为: DDDDDDDDDDDD
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 10761 | Accepted: 5391 |
Description
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
#include<iostream>
#include<cstring>
#include<cstdio>
int main()
{
int s,d;
while(~scanf("%d%d",&s,&d))
{
int flag=;
int ans=;
if(*s-d<)
{
ans=*s-*d;
if(ans<=)
flag=;
}
else if(*s-*d<)
{
ans=*s-*d;
if(ans<=)
flag=;
}
else if(*s-*d<)
{
ans=*s-*d;
if(ans<=)
flag=; }
else if(s-*d<)
{
ans=*s-*d;
if(ans<=)
flag=; }
else
{
printf("Deficit\n");
continue;
}
if(flag)
printf("Deficit\n");
else
printf("%d\n",ans); }
return ;
}
poj 2586 Y2K Accounting Bug的更多相关文章
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- 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 贪心 难度:2
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10537 Accepted: 52 ...
- POJ 2586 Y2K Accounting Bug(枚举大水题)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10674 Accepted: 53 ...
- POJ - 2586 Y2K Accounting Bug (找规律)
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...
- [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(贪心算法,水题一枚)
#include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...
随机推荐
- UIImageView的图片拉伸
iOS 8:UIView Stretching设置 使用小图片当变长输入框或类似QQ聊天文字背景效果时,需要拉伸图片.UIImage提供了三个可完成此任务的方法: resizableImageWith ...
- ibatis+spring+cxf+mysql搭建webservice
首先需必备:mysql.myeclipse6.5.apache-cxf-2.6.2 一.建数据库,库名:cxf_demo:表名:book CREATE DATABASE `cxf_demo` --数 ...
- scrapy抓取到中文,保存到json文件为unicode,如何解决.
http://scrapy-chs.readthedocs.org/zh_CN/latest/intro/overview.html 以上链接是很好的scrapy学些资料.感谢marchtea的翻译. ...
- UDP协议疑难杂症全景解析
转载:http://blog.csdn.net/dog250/article/details/6896949 UDP协议疑难杂症全景解析 2011-10-22 19:26 2989人阅读 评论(4) ...
- python 在调用时计算默认值
大家都知道python的默认值是在函数定义时计算出来的, 也就是说默认值只会计算一次, 之后函数调用时, 如果参数没有给出,同一个值会赋值给变量, 这会导致, 如果我们想要一个list默认值, 新手通 ...
- Graphviz使用简介(中文乱码的问题)
Graphviz使用简介 graphviz是基于dot语言的绘图工具,可以画有向图.无向图.关系图.目录图.流程图等.具体作用可见它的官方网站 一些参考的网址: http://www.open-ope ...
- 深入了解overflow
1.如果overflow-x与overflow-y值不同 其中一个赋值为visiable,另一个赋值scroll/auto/hidden,那么visiable会重置为auto 2.overflow ...
- 构建 struts2 spring3 mybatis 的maven项目 构建 pom.xml
学习maven项目时 搭建个ssm项目 算是给自己留个备份吧 环境说明: MyEclipse10 Maven 3.2.3 框架: struts2 2.3.24.1 spring3 3. ...
- CSS伪类对象before和after的用法
一直感觉这两个伪类对象不是很重要,并且IE对它两兄弟并不支持,所以也没有怎么静下心来研究,只有在清楚浮动clearfix的时候会用到哈,其他都很 少用!不过最近在研究css3的时候觉得它两个的搭配不仅 ...
- SQL 添加字段和默认值脚本
--插入字段和默认值alter table Acc_WayBill add DeclaredValue nvarchar(50)goEXEC sys.sp_addextendedproperty @n ...