poj_2586_Y2K Accounting Bug_201407211318
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10210 | Accepted: 5083 |
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
Source
说下题目大意,比较难理解。
某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D。
公司每五个月进行一次统计,全年共统计8次(1-5、2-6、3-7、4-8、5-9、6-10、7-11、8-12),已知这8次统计的结果全部是亏空(盈利-亏空<0)。
题目给出S和D,判断全年是否能盈利,如果能则求出盈利的最大值,如果不能盈利则输出Deficit。
恩,符合最优子结构性质,可以使用贪心算法。5个月统计一次都亏空,那么有5种情况:
1、若SSSSD亏空,那么全年最优情况为SSSSDSSSSDSS
2、若SSSDD亏空,那么全年最优情况为SSSDDSSSDDSS
3、若SSDDD亏空,那么全年最优情况为SSDDDSSDDDSS
4、若SDDDD亏空,那么全年最优情况为SDDDDSDDDDSD
5、若DDDDD亏空,全年必亏空...
因此只要讨论这5种情况即可...
#include <stdio.h>
int main()
{
int s,d;
while(scanf("%d%d",&s,&d)!=EOF)
{
int t,max;
max = -*d;
if(*s<d)
{
t = *s-*d;
if(t>max)
max = t;
}
else if(*s<*d)
{
t = *s-*d;
if(t>max)
max = t;
}
else if(*s<*d)
{
t = *s-*d;
if(t>max)
max = t;
}
else if(s<*d)
{
t = *s-*d;
if(t>max)
max = t;
}
if(max>)
printf("%d\n",max);
else
printf("Deficit\n");
}
return ;
}
贪心
poj_2586_Y2K Accounting Bug_201407211318的更多相关文章
- [POJ2586]Y2K Accounting Bug
[POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
- POJ2586Y2K Accounting Bug(贪心 + 不好想)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12251 Accepted: 62 ...
- Y2K Accounting Bug(贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10945 Accepted: 54 ...
- Codeforces Gym 100513G G. FacePalm Accounting
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- Y2K Accounting Bug 分类: POJ 2015-06-16 16:55 14人阅读 评论(0) 收藏
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11222 Accepted: 56 ...
- How to setup and process Intercompany accounting [AX2012]
In this post, I will take you through a very simple functionality called the intercompany accountin ...
- POJ2586Y2K Accounting Bug
http://poj.org/problem?id=2586 Description Accounting for Computer Machinists (ACM) has sufferred fr ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
随机推荐
- hihocoder1703 第K小先序遍历
思路: 给定n个节点二叉树的中序遍历,不同形态的二叉树的种类数有卡特兰数个.为了在中序序列[l, r]表示的子树上找先序序列第k小的树,首先需要从小到大枚举每个节点作根所能构成的二叉树的数目来确定树根 ...
- 移动端rem
手机有很多尺寸的型号.使用rem来做为大小单位可以达到兼容的目的. 方法一:js测量手机尺寸,设置font-size:为手机屏幕width /10 + ‘px’.即10rem 为手机屏幕width. ...
- iOS Programming Dynamic Type 2
iOS Programming Dynamic Type 2 You will need to update two parts of this view controller for ...
- WordPress更改固定链接出现404
新浪SAE的前端采用的是nginx,nginx是不识别.htaccess的. 最后学习了新浪SAE官方教程——应用配置模块 – AppConfig终于把问题解决! 1.修改你SAE SDK站点目录下的 ...
- jQuery 的DOM操作
DOM创建节点及节点属性 创建元素:document.createElement设置属性:setAttribute添加文本:innerHTML加入文档:appendChild append()前面是被 ...
- 【译】x86程序员手册34-9.7错误代码
9.7 Error Code 错误代码 With exceptions that relate to a specific segment, the processor pushes an error ...
- 【译】x86程序员手册32-9.4 中断描述符表
9.4 Interrupt Descriptor Table 中断描述符表 The interrupt descriptor table (IDT) associates each interrupt ...
- mac webstrom 安装less
1.检验电脑是否安装less lessc -v 2.如果没有执行全局安装命令 npm install -g less 3.webstrom -> Preferencs-> File Wat ...
- java_StringBuffer、StringBuilder
StringBuffer和StringBuider是可变的字符串,使用方法 相同,StringBuffer是线程安全的,StringBuider是线程不安全的 public class StringT ...
- win7 命令行禁用开启usb存储
禁用: reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\usbstor" /v Start /t reg ...