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 解题报告的更多相关文章

  1. [POJ2586]Y2K Accounting Bug

    [POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...

  2. POJ2586——Y2K Accounting Bug

    Y2K Accounting Bug   Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...

  3. poj2586 Y2K Accounting Bug(贪心)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...

  4. POJ-2586 Y2K Accounting Bug贪心,区间盈利

    题目链接: https://vjudge.net/problem/POJ-2586 题目大意: MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失.比如财务报表.现在知道这个奇特的公司每个 ...

  5. POJ2586 Y2K Accounting Bug(贪心)

    题目链接. 题目大意: 题目相当晦涩难懂啊. 一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能. 一个月s ...

  6. poj2586 Y2K Accounting Bug —— 枚举

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

  7. Y2K Accounting Bug(贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10945   Accepted: 54 ...

  8. 贪心 POJ 2586 Y2K Accounting Bug

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

  9. 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 ...

随机推荐

  1. HTML5 File API的应用

    HTML5 File API简介 HTML5File API协议族 Directories and System   文件系统和目录读取 FileWriter   写入文件 FileReader   ...

  2. 2017广东工业大学程序设计竞赛决赛 H tmk买礼物

    题意: Description 今天是校赛的日子,为了庆祝这么喜庆的日子,TMK打算买些礼物给女票LSH庆祝一下. TMK进入了雪梨超市,然后刚踏入的一瞬间,店主就对TMK说:“恭喜你成为了本店第21 ...

  3. .NET 微信开发之 获取用户数据

    通过微信接口获取用户信息主要分为以下几个步骤: a.获取公众号的access_token b.通过查询所有用户OPenid接口获取所有用户. string url = "https://ap ...

  4. 如何参与一个GitHub开源项目?

    如何参与一个GitHub开源项目? 摘要:本文是Github官如何参与一个GitHub开源项目方给出的参与Github上开源项目的一些指导,对希望加入开源社区的开发者是一个不错的参考. 最近一年开源项 ...

  5. 【PostgreSQL-9.6.3】表空间

    在PostgreSQL中,表空间实际上是为表指定一个存储目录,这样方便我们把不同的表放在不同的存储介质或者文件系统中.在创建数据库.表.索引时都可以指定表空间. 1. 创建表空间 --表空间目录必须是 ...

  6. laravel学习:容器绑定与解析

    1.在服务容器中注册类(bind) $this->app->bind('sender','MailSender');//$this->app成为服务容器.   2.从服务容器生成类( ...

  7. proposal_layer.py层解读

    proposal_layer层是利用训练好的rpn网络来生成region proposal供fast rcnn使用. proposal_layer整个处理过程:1.生成所有的anchor,对ancho ...

  8. 安装Subversion1.82(SVN)

    安装Subversion1.82(SVN)插件 简介    :SVN是团队开发的代码管理工具,它使我们得以进行多人在同一平台之下的团队开发. 解决问题:Eclipse下的的SVN插件安装. 学到    ...

  9. https://blog.csdn.net/blmoistawinde/article/details/84329103

    背景    很多场景需要考虑数据分布的相似度/距离:比如确定一个正态分布是否能够很好的描述一个群体的身高(正态分布生成的样本分布应当与实际的抽样分布接近),或者一个分类算法是否能够很好地区分样本的特征 ...

  10. java中mkdir()和mkdirs()区别

    mkdirs()可以建立多级文件夹 mkdir()只会建立一级的文件夹 例如: new File("/file/one/two").mkdirs(); 可建立/file/one/t ...