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 ...
随机推荐
- IO流的原理和概念
在程序中如何读写文件?不同的编程语言有不同的方式,而 JAVA 则提出了“流”的概念,通过“流”来读写文件 什么是流: 流(Stream)是指一连串的数据(字符或字节),是以先进先出的方式发送信息的通 ...
- AJPFX实践 java实现快速排序算法
快速排序算法使用的分治法策略来把一个序列分为两个子序列来实现排序的思路: 1.从数列中挑出一个元素,称为“基准“2.重新排序数列,所有元素比基准值小的摆放在基准前面,所有元素比基准值大的摆在基准的后面 ...
- ES之事件绑定,解除绑定以及事件冒泡、事件捕获
绑定事件的处理方法任何元素都有事件属性,而绑定事件就是将这个事件与一个函数相连接. ①句柄事件dom.onXXX = function () {代码块} 以on开头的事件属于句柄事件兼容性非常好,但是 ...
- 迅为7寸工业触摸屏嵌入式平台可用于ARM嵌入式一体机
7寸触摸屏介绍产品名称:7寸IPS高清屏幕分辨率:1280*800触摸屏类型:电容屏(五点触摸)接线方式: FPC 可应用于嵌入式一体机.自动售货机.广告机.智能自动终端.零售终端等 ARM平台处理器 ...
- Shorthand Argument Names $0 : 只用于指代Closer声明中的形参
Shorthand Argument Names Swift automatically provides shorthand argument names to inline closures, w ...
- 最后一个非零数字(POJ 1604、POJ 1150、POJ 3406)
POJ中有些问题给出了一个长数字序列(即序列中的数字非常多),这个长数字序列的生成有一定的规律,要求求出这个长数字序列中某个位上的数字是多少.这种问题通过分析,找出规律就容易解决. 例如,N!是一个非 ...
- com口操作excel
_Application app; //Excel应用程序接口 Workbooks books; //工作薄集合 _Workbook book; //工作薄 Work ...
- CS2QS
inline QString MotorCS2QS(CString cs) { return QString::fromWCharArray((LPCTSTR)cs, cs.GetLength()); ...
- SQL Server错误: 0 解决方案
1.已设置两种登录模式. 2.SQL Server配置管理器已配置好. 按Windows徽标键+R组合键,然后输入cmd. 再然后输入netsh winsock reset.接下来重启电脑,应该就可以 ...
- vue hash模式和404页面的配置
1.设置我们的路由配置文件(/src/router/index.js): { path:'*', component:Error } 这里的path:’*’就是找不到页面时的配置,component是 ...