http://poj.org/problem?id=2586

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
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
using namespace std ;
int main()
{
int m,n;
while(scanf("%d %d",&m,&n)!=EOF)
{
int flag = ,surplus;
if(*m < n)
{
surplus = *m-*n ;
if(surplus < )
flag = ;
}
else if(*m < *n)
{
surplus = *m-*n;
if(surplus < )
flag = ;
}
else if(*m < *n)
{
surplus=*m-*n;
if(surplus < )
flag = ;
}
else if(m < *n)
{
surplus=*m-*n;
if(surplus < )//一开始加了分号在这里导致WA我竟然没发现。
flag = ;
}
else
flag = ;
if(flag == )
cout<<"Deficit"<<endl ;
else cout<<surplus<<endl ;
}
return ;
}

这个时间的话是0MS;挺快的

看着分类在贪心里边,后来发现其实就五种情况,枚举一下也行

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
using namespace std ;
int main()
{
int m,n;
while(scanf("%d %d",&m,&n)!=EOF)
{
int flag = ,surplus;
if(*m < n)
{
surplus = *m-*n ;
}
else if(*m < *n)
{
surplus = *m-*n;
}
else if(*m < *n)
{
surplus=*m-*n;
}
else if(m < *n)
{
surplus=*m-*n;
}
else
surplus = -;
if(surplus < )
cout<<"Deficit"<<endl ;
else cout<<surplus<<endl ;
}
return ;
}

这个是AIHONGHONG帮我改的一开始我因为不仔细WA了,挺好的这个,时间是30MS

 #include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
int k=,i;
if(n==&&m==)//不加这个就是16MS
{
printf("Deficit");
continue;
}
else if(n==||m==)
{
printf("Deficit");
continue;
}
for(i=;i<=;i++)
{
if(m*(-i)-n*i>)
{
k=i;
}
else break;
}
if(k==)
{
if(*k*n-((-k)*+)*m<)
printf("Deficit");
else printf("%d",*k*n-((-k)*+)*m);
}
else if(k>)
{
if(*k*n+*n-((-k)*)*m<)
printf("Deficit");
else printf("%d",*k*n+*n-((-k)*)*m);
}
else printf("Deficit");
printf("\n");
}
return ;
}

还有这个是会神代码

大神的博客http://www.cnblogs.com/justforgl/archive/2012/07/14/2591110.html

http://blog.csdn.net/lyy289065406/article/details/6642603

POJ2586Y2K Accounting Bug的更多相关文章

  1. POJ2586Y2K Accounting Bug(贪心 + 不好想)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12251   Accepted: 62 ...

  2. [POJ2586]Y2K Accounting Bug

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

  3. Y2K Accounting Bug(贪心)

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

  4. 贪心 POJ 2586 Y2K Accounting Bug

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

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

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

  7. POJ2586——Y2K Accounting Bug

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

  8. poj 2586 Y2K Accounting Bug

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

  9. poj2586 Y2K Accounting Bug(贪心)

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

随机推荐

  1. php下载文件,添加响应头

    //下载,添加响应头信息 header('Content-type:application/octet-stream'); header('Content-Disposition:attachment ...

  2. Nginx +keepalived

    Nginx +keepalived   配置高可用的Nginx 准备环境: 节点node17,node18   lftp 172.16.0.1:/pub/Sources/6.x86_64/nginx ...

  3. javascript里面技巧整理

    web develop tools secrets: http://jinlong.github.io/blog/2013/08/29/devtoolsecrets/ 1.Date new Date( ...

  4. CentOS 6.4 升级 Mysq5.5l方法 和 用户远程登录数据库

    一:.在这里我们都知道 系统的yum源Mysql版本一般都是5.1 5.2的比较多 但是有些程序 必须要5.5以上的版本才能支持 这时候我们应该怎么办呢  编译安装也太慢 太费时间  那么我们就必要要 ...

  5. 安装node和grunt

    由于我用的恶事win8的系统,所以在安装nodeJS的时候出现了2503和2502的错误.解决方案: 进入cmd,然后输入msiexec /package [路径:为你将要安装的node所在的位置] ...

  6. UnitTest

    using Bll; using Model; using Dal; using NUnit.Framework; using NUnit.Mocks; using System.ServiceMod ...

  7. WPF-控件-将ListBox条目水平排列

    <Grid Margin="6"> <ListBox> <!--ItemsPanel--> <ListBox.ItemsPanel> ...

  8. 【iOS】屏幕旋转,屏幕自适应方向变化

    1. iOS有四个方向的旋转,为了保证自己的代码能够支持旋转,我们必须首先处理一个函数: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInter ...

  9. 关于php框架

    最近学习yii2.0 强哥原班人马开发,不得不看 同时也需要关注一下drupal8和symfony2

  10. 实现iOS长时间后台的两种方法:Audiosession和VOIP(转)

    分类: Iphone2013-01-24 14:03 986人阅读 评论(0) 收藏 举报 我们知道iOS开启后台任务后可以获得最多600秒的执行时间,而一些需要在后台下载或者与服务器保持连接的App ...