Y2K Accounting Bug - 2586
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 11271 | Accepted: 5672 |
Description
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
Output
Sample Input
59 237
375 743
200000 849694
2500000 8000000
Sample Output
116
28
300612
Deficit
这里翻译一下题目,原先没看懂题:
1. SSSSD -> SSSSDSSSSDSS
2. SSSDD -> SSSDDSSSDDSS
3. SSDDD -> SSDDDSSDDDSS
4. SDDDD -> SDDDDSDDDDSD
只有这几种情况,依次试一下即可
下面是我写的AC
#include <iostream>
using namespace std; int main() {
int s,d;
int res[];
int sum[];
while(cin>>s>>d){
int tmp=;
for(int i=;i<;i++){
if(i*s-(-i)*d<=&&(i+)*s-(-i-)*d>){
tmp=i;
break;
}
}
//cout<<tmp<<endl;
if(tmp==){
cout<<"Deficit"<<endl;
continue;
}
for(int i=;i<tmp;i++){
res[i]=s;
}
for(int i=tmp;i<;i++){
res[i]=-d;
}
sum[]=res[];
//cout<<sum[0]<<endl;
for(int i=;i<;i++){
sum[i]=sum[i-]+res[i];
// cout<<sum[i]<<endl;
}
for(int i=;i<;i++){
int tsum=;
tsum=sum[i-]-sum[i-];
if(tsum+s<=){
sum[i]=sum[i-]+s;
}else{
sum[i]=sum[i-]-d;
}
//cout<<sum[i]<<endl;
}
if(sum[]<=){
cout<<"Deficit"<<endl;
}else{
cout<<sum[]<<endl;
}
}
return ;
}
Y2K Accounting Bug - 2586的更多相关文章
- ** poj Y2K Accounting Bug 2586
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10117 Accepted: 50 ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- Poj 2586 / OpenJudge 2586 Y2K Accounting Bug
1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS Memory Lim ...
- poj 2586 Y2K Accounting Bug
http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...
- poj 2586 Y2K Accounting Bug (贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8678 Accepted: 428 ...
- POJ 2586:Y2K Accounting Bug(贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10024 Accepted: 4990 D ...
- POJ 2586 Y2K Accounting Bug(枚举洪水问题)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10674 Accepted: 53 ...
- POJ 2586 Y2K Accounting Bug 贪心 难度:2
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10537 Accepted: 52 ...
- POJ 2586 Y2K Accounting Bug(枚举大水题)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10674 Accepted: 53 ...
随机推荐
- [COCI2015]ZMIJA
题目大意: 一个$n\times m(n,m\leq1000)$的格子中有若干金币,从左下角出发,每一步可以进行如下操作: 1.向当前方向前进一格: 2.向上移动一步,并调转当前方向. 一开始的方向是 ...
- cocurrent包 原子性数据类型
22. 原子性布尔 AtomicBoolean AtomicBoolean 类为我们提供了一个可以用原子方式进行读和写的布尔值,它还拥有一些先进的原子性操作,比如 compareAndSet().At ...
- linux 远程同步数据工具rsync (2)
在远程主机上建立一个rsync的服务器,在服务器上配置好rsync的各种应用,然后本机作为rsync的一个客 户端去连接远程的rsync服务器.如何去配置一台rsync服务器. 首先配置/etc/rs ...
- 直方图均衡(HE)与局部色调映射(LTM) .
直方图均衡(Histogram Equalization)是图像处理中一个十分基础的概念,具有调整图像灰度,增强对比度的作用. 限制对比度自适应直方图均衡(Contrast Limited Ad ...
- Java里日期转换及日期比较大小
1.比较日期的大小: DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//创建日期转换对象hh:mm:ss为 ...
- 15 Basic ‘ls’ Command Examples in Linux
FROM: http://www.tecmint.com/15-basic-ls-command-examples-in-linux/ ls command is one of the most fr ...
- 谷歌安卓UI自动化测试策略
中文翻译版: 为了使大家确信"应做单元测试,就一定能做单元测试",谷歌测试工程师Mona El Mahdy专门写了一篇博客,提出了几种执行安卓应用用户界面单元测试的方法.Mahdy ...
- 用Jmeter对数据库执行压力测试
转载:http://www.cnblogs.com/chengtch/p/6198900.html 在我看来压力测试的压测对象可以分为UI,接口及数据库三个部分吧,对界面及接口进行压测还算熟悉, 定位 ...
- oc 之中的 汉字字符串转化成为拼音 汉字字符串的排序
在oc 之中的字符串为汉字的时候,我们经常要进行字符串比較,可是汉字不能比較,所以就要将汉字转化成为拼音,详细步骤例如以下: //可变字符串 必须是可变字符串. NSMutableString ...
- 倍福TwinCAT(贝福Beckhoff)基础教程 松下驱动器如何执行绝对值清零
点击参数-参数一览,然后修改015为0(设置为绝对编码器方式),点击设定值变更,然后传送,EEP,将参数写入驱动器(保持USB线连接,重启驱动器并确认参数确是改成0了) 监视器-清除多圈数,清除之 ...