Y2K Accounting Bug
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10537   Accepted: 5264

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 题目意思:MS公司在1999年每个月有盈余有亏损,现在只知道盈余一定为s,亏损一定为d,并且该公司每连续五个月的总利润都是亏损(0-4,1-5,...7-11)(编号0-11),问如何取值(s,-d)在该条件下使得总利润最大,并且询问总利润是否可能为正数(盈利)
思路:贪心,如果统计需要次数最多的那个点容易造成断层,(比如第二组数据375 473,5 6 7 8都是被需要次数相同的,这个算法就不知道该先选择哪个,可能会先选择5,6,而4是一定要选的,选了4就不用选6了)
改变贪心思路,初始化全部选s,从头往尾扫,每个sum都必须变成-的为止,那么选择最右边的大于0,因为左边的要不就已经变成-的,或者使用次数没有右边多,直到sum变成负数为止
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int s,d;
int a[];
long long sum[];
int main()
{
while(scanf("%d%d",&s,&d)==){
for(int i=;i<;i++)a[i]=s;
for(int i=;i<;i++)sum[i]=*s;
for(int i=;i<;i++){
int t=;
while(sum[i]>=){
a[i+t]=-d;
for(int j=max(i+t-,);j<&&j<=i+t;j++){
sum[j]-=d+s;
}
t--;
}
}
long long ans=sum[]+sum[]+a[]+a[];
if(ans>=)printf("%I64d\n",ans);
else printf("Deficit\n");
}
return ;
}

POJ 2586 Y2K Accounting Bug 贪心 难度:2的更多相关文章

  1. poj 2586 Y2K Accounting Bug (贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8678   Accepted: 428 ...

  2. poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)

    #include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...

  3. 贪心 POJ 2586 Y2K Accounting Bug

    题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...

  4. poj 2586 Y2K Accounting Bug

    http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...

  5. POJ 2586 Y2K Accounting Bug(枚举洪水问题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  6. POJ 2586 Y2K Accounting Bug(枚举大水题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  7. [POJ 2586] Y2K Accounting Bug (贪心)

    题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...

  8. POJ 2586 Y2K Accounting Bug(贪心)

    题目连接:http://poj.org/problem?id=2586 题意:次(1-5.2-6.3-7.4-8.5-9.6-10.7-11.8-12),次统计的结果全部是亏空(盈利-亏空<0) ...

  9. POJ - 2586 Y2K Accounting Bug (找规律)

    Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...

随机推荐

  1. JS引擎深入分析

    转载自阮一峰:http://javascript.ruanyifeng.com/bom/engine.html 目录 JavaScript代码嵌入网页的方法 script标签:代码嵌入网页 scrip ...

  2. 洛谷 P2056 采花 - 莫队算法

    萧芸斓是 Z国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了 n 朵花,花有 c 种颜色(用整数 1-c 表示) ,且花是排成一排的,以 ...

  3. HDU1043 Eight(八数码:逆向BFS打表+康托展开)题解

    Eight Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  4. U盘中病毒了怎么办

    声明: 该方案仅是我处理自己U盘的心得,如果您看到这篇文件,并使用此方法,有任何数据丢失或者损失,我概不负责 问题: U盘里面显示占用了空间,就是看不到文件,或者仅有一两个自己不认识的文件 处理方案: ...

  5. Codeforces Round #406 (Div. 2) D. Legacy 线段树建模+最短路

    D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  6. bnu 51636 Squared Permutation 线段树

    Squared Permutation Time Limit: 6000ms Memory Limit: 262144KB 64-bit integer IO format: %lld      Ja ...

  7. C++ 利用栈解决运算问题

    2017-06-27 19:19:18 第一步需要将中缀表达式转为后缀表达式.这步的转化可以说是本题的核心. 主要的转化手段是利用栈,有如下几个规则: 数字直接输出 "("直接进栈 ...

  8. LeetCode--205--同构字符串

    问题描述: 给定两个字符串 s 和 t,判断它们是否是同构的. 如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的. 所有出现的字符都必须用另一个字符替换,同时保留字符的顺序.两个字符不 ...

  9. Ubuntu中vi命令的编辑模式异常

    今天更改Ubuntu软件源的时候,进入源文件的编辑模式时,发现删除键和编辑都不能正常使用,百度之后,知道是由于Ubuntu预装的是vim-tiny,而我们需要使用vim-full.在此记录下该问题以便 ...

  10. array_unshift

    <!DOCTYPE html> <html> <body> <?php $a=array(0=>"red",1=>" ...