poj 2586 Y2K Accounting Bug(贪心)
来源:互联网 发布:抓取网页数据工具 编辑:程序博客网 时间:2024/05/16 19:31
Y2K Accounting Bug
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 15926 Accepted: 7984
Description
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc.
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
Input is a sequence of lines, each containing two positive integers s and d.
Output
For each line of input, output one line containing either a single integer giving the amount of surplus for the entire year, or output Deficit if it is impossible.
Sample Input
59 237
375 743
200000 849694
2500000 8000000
Sample Output
116
28
300612
Deficit
题意:盈利s,赤字d,要求每五个月总额是亏损的,求12个月的盈利最大值,没有盈利输出“Deficit”。
贪心,使得每五个月之中的亏损尽可能小。
#include <iostream>#include <cstdio>using namespace std;int a[6];int main(){ //freopen( "in.txt", "r", stdin ); int s, d, sum, flg; while( scanf( "%d%d", &s, &d ) != EOF ){///surplus deficit for( int i = 1 ; i <= 5 ; i ++ ){ a[i] = s; } while( 1 ){ sum = flg = 0; for( int i = 5 ; i >= 1 ; i -- ){ if( !flg && a[i] > 0 ){/// flg = 1; a[i] = 0-d; } sum += a[i]; } if( a[1] < 0 || sum <= 0 ) break; } sum = sum * 2 + a[1] + a[2];///是a[1],a[2],不是2*s if( sum > 0 ) cout<<sum<<endl; else cout<<"Deficit"<<endl; } return 0;}
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ 2586:Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug (贪心)
- poj 2586 Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug贪心
- POJ 2586 Y2K Accounting Bug 贪心
- poj 2586 Y2K Accounting Bug 贪心
- poj 2586 Y2K Accounting Bug (贪心)
- POJ 2586 Y2K Accounting Bug 贪心策略
- POJ 2586 Y2K Accounting Bug 贪心
- POJ 2586:Y2K Accounting Bug:贪心法
- poj 2586 Y2K Accounting Bug (贪心)
- POJ--2586:Y2K Accounting Bug (贪心)
- 【贪心】POJ-2586 Y2K Accounting Bug
- poj 2586 Y2K Accounting Bug 【贪心】
- POJ 2586-Y2K Accounting Bug(贪心)
- Linux平台 Oracle 12cR2 RAC安装Part1:准备工作
- 关于在VS2012新建Web项目报错:当前已将Web应用程序项目配置为使用IIS Express。若要切换回......的解决方法
- nodeJs启动的时候:Error: Cannot find module '../build/Release/bson'的解决办法
- python 多线程串行和并行
- C++中extern关键字的作用
- poj 2586 Y2K Accounting Bug(贪心)
- PAT (Basic Level) Practise (中文) 1045. 快速排序(25)
- leetcode
- Django登录验证
- 单例模式的Java编程简单实现
- Linux 信号机制
- 数据库视频(一)
- python中的map函数
- HTTP 500 Internal Server Error