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 ------ ...
随机推荐
- 八、Foundation -常用结构体
一.NSRange 在foundation/NSRange.h中对NSRange的定义 typedef struct _NSRange{ NSUInteger location; NSUInteger ...
- 11SpringMvc_一个Action中,写多个类似的业务控制方法
我们要实现这么一个功能: 编写两个表单,提交到同一个Action中的不同的处理方法中.比如注册和登录,都提交到UserAction这个控制类中.但是这两个提交由userAction这个控制类不同的方法 ...
- Java连接Elasticsearch集群
package cn.test; import java.net.InetAddress; import java.net.UnknownHostException; import org.elast ...
- [py]编码 Unicode utf-8
什么是字符集 在介绍字符集之前,我们先了解下为什么要有字符集.我们在计算机屏幕上看到的是实体化的文字,而在计算机存储介质中存放的实际是二进制的比特流.那么在这两者之间的转换规则就需要一个统一的标准,否 ...
- iBatis.Net实现返回DataTable和DataSet对象
如题.要返回一个ADO.NET对象好像没有使用ORM的必要,而且从编程的角度看这样的实现一点也不OO,但是实际的开发场景中还是会碰到这种需求的.下面我就借鉴前人的经验,结合实际的示例,再总结一下.如果 ...
- 开始学习node.js了,第一节,fs文件系统 【fs.rename】重命名文件/文件夹
var fs=require('fs');fs.rename('c:\\a','c:\\a2',function(err){ if(err) console.log('error:'+err);}); ...
- Yii2-Redis使用小记 - Cache
前些天简单学习了下 Redis,现在准备在项目上使用它了.我们目前用的是 Yii2 框架,在官网搜索了下 Redis,就发现了yii2-redis这扩展. 安装后使用超简单,打开 common/con ...
- 从士兵到程序员再到SOHO程序员
2013年9月13日,我从就职了一年半的S公司正式离职,并开始了我梦寐以求的“SOHO程序员”之路. 这对于我来说,是一次人生道路上的重要选择,在这里,我想分享一下我是如何选择了这条道路的,同时也是对 ...
- ssh 返回错误 Too many authentic authentication failures for root 的时候检查 ssh 配置
路径 cd /etc/ssh ls -ltr sudo vi sshd_config 改为以下内容(yes): PermitRootLogin yes
- session放到mongo里边
为了session的共享和保存,常常把session放数据库里边,但是很多时候都放redis里边,今天看了一个放Mongo中的记录下,说不懂什么时候就用到了. app.use(session({ se ...