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. Duilib 实现开关按钮

    转载:http://blog.csdn.net/wuan584974722/article/details/25045737 我们在做MFC程序时候经常会一个切换式的按钮,之前我的做法是利用butti ...

  2. JS 获取浏览器的宽和高

    网页可见区域宽:document.body.clientWidth 网页可见区域高:document.body.clientHeight 网页可见区域宽:document.body.offsetWid ...

  3. kubernetes 命令记录

    操作基本命令:   通过yaml文件创建: kubectl create -f xxx.yaml (不建议使用,无法更新,必须先delete) kubectl apply -f xxx.yaml (创 ...

  4. 明码|2018年蓝桥杯B组题解析第二题-fishers

    标题:明码 汉字的字形存在于字库中,即便在今天,16点阵的字库也仍然使用广泛. 16点阵的字库把每个汉字看成是16x16个像素信息.并把这些信息记录在字节中. 一个字节可以存储8位信息,用32个字节就 ...

  5. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer 最大生成树 lca

    大概就是要每两个点 只能有一条路径,并且约束,最短的边用来砌墙,那么反之的意思就是最大的边用来穿过 故最大生成树 生成以后 再用lca计算树上两点间的距离 (当然防止生成树是一条链,可以用树的重心作为 ...

  6. triggerHandler不执行事件默认值

    <input type="text" /> $('input').triggerHandler('focus');

  7. js中拼接HTML方式方法及注意事项

    博主原创:未经博主允许,不得转载 在前端应用中,经常需要在js中动态拼接HTML页面,比如应用ajax进行局部刷新的时候,就需要在js中拼接HTML页面. 主要规则是将HTML页面的标签拼接为标签字符 ...

  8. 微信小程序获取用户手机号

    获取微信用户绑定的手机号,需先调用wx.login接口. 小程序获取code. 后台得到session_key,openid. 组件触发getPhoneNumber 因为需要用户主动触发才能发起获取手 ...

  9. angular 模板语法(官方文档摘录)

    https://angular.cn/guide/template-syntax {{}} 和"" 如果嵌套,{{}}里面求完值,""就是原意 <h3&g ...

  10. 算法笔记--st表

    概述:用倍增法求区间最值的离线算法,O(nlogn)预处理,O(1)访问. 预处理: 状态:st[i][j]:[i,i+2^j)之间的最值 状态转移:如果j等于0,st[i][j]=a[i] 如果j大 ...