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 ------ ...
随机推荐
- 将TP引擎改为smarty引擎
在common/config文件里设置'TMPL_ENGINE_TYPE'=>'Smarty'即可,但要注意,在模板文件里的css样式{}要用一对{literal}{/literal}标签包裹, ...
- ASP.NET MVC3 Model验证总结(转)
推荐: ASP.NET MVC的Model元数据与Model模板:预定义模板 http://www.cnblogs.com/artech/archive/2012/05/02/model-meta ...
- SpringMVC Controller介绍(转)
SpringMVC Controller 介绍 一.简介 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理 ...
- OpenCV人脸检测demo--facedetect
&1 问题来源 在运行官网的facedetect这个demo的时候,总是不会出来result的图形,电脑右下角提示的错误是“显示器驱动程序已停止响应,而且已恢复 windows 8(R)”. ...
- Java中sleep()和wait()的区别
1. 这两个方法来自不同的类,sleep方法属于Thread,wait方法属于Object. 2. 最主要是sleep方法没有释放锁,而wait方法释放了锁,使得其他线程可以使用同步控制块或者方法. ...
- 20145204&20145212信息安全系统实验四报告
20145204信息安全设计基础实验四报告 博客链接:信息安全设计基础实验
- html5新增选择器
分享点html5的学习笔记,比较基础,突然发现通过写博客来记笔记有很多优点呢,平常记得笔记比较简单,复习起来比较吃力,看自己的博客理解起来还比较轻松,而且只有真正理解了才能表达清楚让别人看懂,还锻炼语 ...
- servlet请求转发、包含以及重定向
请求转发: 方式一: ServletContext对象.getRequestDispatcher(目标资源的URI).forward(request,response); 目标资源的URI " ...
- [bzoj 1026]windy数(数位DP)
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1026 分析: 简单的数位DP啦 f[i][j]表示数字有i位,最高位的数值为j的windy数总 ...
- 7、面向对象以及winform的简单运用(委托)
委托 1.概念: 委托可以看成是一个函数的“容器”,将某一具体的函数“装入”后,就可以把它当成函数一样使用.委托变量可看成是一种类型安全的函数指针,它只能接收符合其要求的函数地址. 2.定义方法:de ...