POJ2586Y2K Accounting Bug(贪心 + 不好想)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 12251 | Accepted: 6202 |
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
题意:12个月每个月要么盈利s,要么亏损d,连续五个月都是亏损的,即1-5,2-6,3-7,4-8,5-9,6-10,7-11,8-12;求一年最大盈利
分析:想了半天确实没想出怎么解,看了题解,却又感觉那么的合情合理,贪心考虑边界http://blog.csdn.net/lyy289065406/article/details/6642603
x=2: sssdd,sssdd,ss 2d>3s 赢利8个月 8s-4d
x=3: ssddd,ssddd,ss 3d>2s 赢利6个月 6s-6d
x=4: sdddd,sdddd,sd 4d>s 赢利3个月 3s-9d
x=5: ddddd,ddddd,dd 4d<s 无赢利
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long s,d;
char str[] = "Deficit"; int main()
{
while(scanf("%I64d%I64d", &s, &d) != EOF)
{
if(d > * s)
{
if( * s - * d > )
{
printf("%I64d\n", * s - * d);
}
else
{
printf("%s\n", str);
}
}
else if( * s < * d )
{
if( * s - * d > )
{
printf("%I64d\n", * s - * d);
}
else
{
printf("%s\n", str);
}
}
else if( * s < * d)
{
if( * s - * d > )
{
printf("%I64d\n", * s - * d);
}
else
{
printf("%s\n", str);
}
}
else if(s < * d)
{
if( * s - * d > )
{
printf("%I64d\n", * s - * d);
}
else
{
printf("%s\n", str);
}
}
else
{
printf("%s\n", str);
}
} return ;
}
POJ2586Y2K 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 ...
- Y2K Accounting Bug(贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10945 Accepted: 54 ...
- POJ2586Y2K Accounting Bug
http://poj.org/problem?id=2586 Description Accounting for Computer Machinists (ACM) has sufferred fr ...
- POJ2586 Y2K Accounting Bug(贪心)
题目链接. 题目大意: 题目相当晦涩难懂啊. 一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能. 一个月s ...
- POJ-2586 Y2K Accounting Bug贪心,区间盈利
题目链接: https://vjudge.net/problem/POJ-2586 题目大意: MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失.比如财务报表.现在知道这个奇特的公司每个 ...
- 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. 公司每五个月进行一次统计,全年共统 ...
- poj2586 Y2K Accounting Bug(贪心)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...
随机推荐
- javascript边角知识
1.组织默认事件 阻止默认事件,h5默认的input type='date'在某些浏览器和android设备上没有效果,这时要调用h5+的时间选择器,但是要组织input默认的click事件,代码如下 ...
- javascript中的队列结构
1.概念 队列和栈结构不同,栈是一种后进先出的结构,而队列是一种先进先出的结构.队列也是一种表结构,不同的是队列只能在队尾插入元素,在队首删除元素,可以将队列想象成一个在超时等待排队付钱的队伍,或者在 ...
- usb驱动开发5之总线设备与接口
Linux设备模型中的总线落实在USB子系统里就是usb_bus_type,它在usb_init的函数bus_register(&usb_bus_type)里注册.usb_bus_type定义 ...
- 【C#】【Thread】Monitor和Lock
所谓锁,就是之锁定的区域只能单个线程进入进行操作,其他线程在锁的外围等待.Monitor锁通过Monitor.Enter(obj)和Monitor.Exit(obj)来锁定和解锁.Lock锁则直接Lo ...
- [转]2006 MySQL server has gone away错误,最大值溢出解决办法 mysql max_allowed_packet 查询和修改
From : http://www.cnblogs.com/huangcong/archive/2013/03/26/2981790.html 1.应用程序(比如PHP)长时间的执行批量的MYSQL语 ...
- Linux考试易忘命令
这是为了考试而做的笔记 mv命令可以移动可以改名 mv a /test //移动a到test文件夹下 mv a b //把a改名为b 软链接和硬链接的创建 ln -s profile a //prof ...
- SgmlReader使用方法
HtmlAgilityPack是一个开源的html解析器,底层是通过将html格式转成标准的xml格式文件来实现的(使用dot net里的XPathDocument等xml相关类),可以从这里下载:h ...
- scrapy 登录
说明: 本文参考了官网文档,以及stackoverflow的几个问题 注意: 下面这个爬虫不能实际运行!我只是用它来展示登录,以及之后如何处理. 方式一:FormRequest import scra ...
- Android 长按Listview显示CheckBox,实现批量删除。
ListView实现的列表,如果是可编辑,可删除的,一般都要提供批量删除功能,否则的话,一项一项的删除体验很不好,也给用户带来了很大的麻烦. 实现效果图 具体实现代码 select.xml 主布局文件 ...
- 《信息安全系统设计基础》第一次实验报告--Linux 基础入门
北京电子科技学院(BESTI) 实 验 报 告 课程:信息安全设计基础 班级:1352 姓名:何伟钦 学号:20135223 成绩: 指导教师:娄嘉鹏 ...