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 ...
随机推荐
- AJPFX: Java基础多线程(一)
多线程是Java学习的非常重要的方面,是每个Java程序员必须掌握的基本技能.本文只是多线程细节.本质的总结,并无代码例子入门,不适合初学者理解.初学者学习多线程,建议一边看书.看博文,以便写代码尝试 ...
- springmvc 的配置 annotation-config/annotation-drive/ component-scan 区别
1. <context:annotation-config /> 作用隐式的配置注解的加载类,默认的加载了AutowiredAnnotationBeanPostProcessor(auto ...
- 修改xampp的mysql默认密码和端口
修改MySQL默认密码 MySQL 的“root”用户默认状态是没有密码的,所以在 PHP 中您可以使用 mysql_connect("localhost","root& ...
- Node.js——防盗链
防盗链可以通过判断请求头中携带的referrer是否属于本域名
- SQL 索引自动维护计划脚本
脚本功能: 1,查询数据库中,碎片率在5%以上(官方推荐),有一定数据里的表的索引. 2.如果碎片率在5%<碎片率<=30% 执行重新组织索引.如果在30%以上,执行重建索引 建议在执行 ...
- android 设置跳转
android.provider.Settings. 1. ACTION_ACCESSIBILITY_SETTINGS : // 跳转系统的辅助功能界面 Intent ...
- 【Gambit】Gambit使用教程
第一章 Gambit使用 Gambit介绍 网格的划分使用Gambit软件,首先要启动Gambit,在Dos下输入Gambit <filemane>,文件名如果已经存在,要加上参数-old ...
- CREATE VIEW - 定义一个视图
SYNOPSIS CREATE [ OR REPLACE ] VIEW name [ ( column_name [, ...] ) ] AS query DESCRIPTION 描述 CREATE ...
- CAD参数绘制批注(com接口)
C#中实现代码说明: private void DrawComment() { MxDrawComment com = new MxDrawComment(); MxDrawPoint pt = ne ...
- CAD设置背景图片(com接口)
把图片作为背景图片可见但是不能编辑操作. 主要用到函数说明: _DMxDrawX::DrawImageToBackground 绘光栅图到背景.详细说明如下: 参数 说明 BSTR sFileName ...