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 ------ ...
随机推荐
- Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...
- C语言 百炼成钢18
//题目52:用递归打印以下图形 //* //*.*. //*..*..*.. //*...*...*...*... //*....*....*....*....*.... #include<s ...
- 0.1 hint crack
http://files.cnblogs.com/files/crac/27.rar
- Redmine 项目管理工具----完全攻略
摘要: 此篇博客涉及 安装,插件修改,插件安装,代码显示,中文乱码,SVN配置等内容,几乎覆盖所有redmine基本功能. 本机环境: Redmine 版本: 3.2.0 本机环境: win7 64位 ...
- 数据库SQL优化大总结之 百万级数据库优化方案(转)
1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...
- 关于sql 的convert 格式设置
CONVERT(data_type,expression[,style]) convert(varchar(10),字段名,转换格式) 说明:此样式一般在时间类型(datetime,smalldate ...
- 如何用Android Studio打多包名APK
问题:项目中不同的分发渠道可能需要打包多种APK(同样的代码),包名可能是不一样的,如果一个一个修改包名重新编apk是很麻烦,可以参考下列步骤在Android Studio上操纵Gradle来打包不同 ...
- 实施项目--.NET实现仓库看板的一些感想
从一名技术开发人员到实施人员的蜕变,从不同的角度看待同一个问题,或许会有不一样的结果.这里记录一下最近一个项目实施的案例,非常有感触! 一. 项目情况简介 本次项目是给一个国外生产型企业做仓库方面的系 ...
- ModelProxy 前端接口配置建模框架
ModelProxy 轻量级的接口配置建模框架(1) 先看一下这个博客说明为什么需要用ModelProxy的前端轻量级的框架吧: http://developer.51cto.com/art/ ...
- [AHOI2013]立方体(三维bit)
[Ahoi2013]立方体 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 130 Solved: 55[Submit][Status] Descrip ...