POJ2586 Y2K Accounting Bug 解题报告
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
分析:
已知一年中,所有的连续的5个月是亏损的(如1-5月,2-6月。。。8-12月共8个),每个月要么收益s,要么亏损d,
求一年中最大收益。这数据量什么都不想了直接暴力搜索加个树状数组优化下算是用了点心了
#include <iostream>
#include <cstring>
using namespace std;
int f[13],ans,s,d;
void update(int x,int k){
for(;x<=12;x+=(-x)&x) f[x]+=k;
}
int sum(int x){
int s=0;
for(;x>0;x-=(-x)&x) s+=f[x];
return s;
}
void make(int k){
if(k==13) {
ans=max(sum(12),ans);
return;
}
update(k,s+d);
int i;
for(i=5;i<=12;i++){
if(sum(i)-sum(i-5)>0) break;
}
if(i<13) {
update(k,-s-d);
make(k+1);
}
else{
make(k+1);
update(k,-s-d);
make(k+1);
}
}
int main(){
while(cin>>s>>d) {
ans=-1e8;
memset(f,0,sizeof f);
for(int i=1;i<=12;i++) update(i,-d);
make(1);
if(ans<0) cout<<"Deficit"<<endl;
else
cout<<ans<<endl;
}
return 0;
}
http://www.cnblogs.com/keam37/ keam所有 转载请注明出处
POJ2586 Y2K Accounting Bug 解题报告的更多相关文章
- [POJ2586]Y2K Accounting Bug
[POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
- POJ2586——Y2K Accounting Bug
Y2K Accounting Bug Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
- poj2586 Y2K Accounting Bug(贪心)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...
- POJ-2586 Y2K Accounting Bug贪心,区间盈利
题目链接: https://vjudge.net/problem/POJ-2586 题目大意: MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失.比如财务报表.现在知道这个奇特的公司每个 ...
- POJ2586 Y2K Accounting Bug(贪心)
题目链接. 题目大意: 题目相当晦涩难懂啊. 一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能. 一个月s ...
- poj2586 Y2K Accounting Bug —— 枚举
链接:http://poj.org/problem?id=2586 题意:大意是一个公司在12个月中,或固定盈余s,或固定亏损d.但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(和 ...
- Y2K Accounting Bug(贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10945 Accepted: 54 ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- Y2K Accounting Bug 分类: POJ 2015-06-16 16:55 14人阅读 评论(0) 收藏
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11222 Accepted: 56 ...
随机推荐
- JDK集合框架--LinkedList
上一篇讲了ArrayList,它有一个"孪生兄弟"--LinkedList,这两个集合类总是经常会被拿来比较,今天就分析一下LinkedList,然后总结一下这俩集合类的不同 首先 ...
- AJPFX解析成员变量和局部变量
成员变量和局部变量 3.1.成员变量和局部变量 A:在类中的位置不同 * 成员变量:在类中方法外 * 局部变量:在方法定义中或者方法声明上 B:在内存中的位置不同 ...
- Oracle Mysql的jdbc连接
Oracle和MySql的jdbc或连接池中的连接,写下来以便随时参考 Oracle: driverClassName=oracle.jdbc.driver.OracleDriver url=jdbc ...
- Spring---AOP注解开发&jdbc模板&Spring事务管理
一.AOP注解开发 此处需要回忆一遍AOP的概念.简单的来说,AOP就是利用动态代理技术,做到不触动源代码但却扩展了功能.那么就需要一个被扩展的对象和一个“新的功能”,例如说给某类的saveUser方 ...
- es6核心特性-数组扩展
1. Array.from() : 将伪数组对象或可遍历对象转换为真数组 如果一个对象的所有键名都是正整数或零,并且有length属性,那么这个对象就很像数组,称为伪数组.典型的伪数组有函数的argu ...
- Python __str__(self)和__unicode__(self)
object.__str__(self) Called by the str() built-in function and by the print statement to compute the ...
- VM virtualBox设置无缝全屏
设置之前:
- js面向对象之构造函数
最简单的面向对象程序<script type="text/javascript"> var obj = new Object(); obj.qq = '10791611 ...
- Oracle反向字符截取逗號分隔字符串
DECLARE M ); BEGIN FOR I IN ( WITH T AS (SELECT REVERSE('i,am,a,test,hahahhah') AS STR FROM DUAL) SE ...
- VC++检测硬件设备状态
首先捕捉WM_DEVICECHANGE消息,该消息在usb插拔时均有触发. MFC下 添加消息处理函数afx_msg BOOL OnDeviceChange( UINT nEventType, DWO ...