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. 内核中读取UTC时间

        记录这个知识点的原因是因为项目中需要保存充电日志,因此,趁着这个机会,深入了解一下Linux的时间系统. UTC:(Universal Time Coordinated) 协调世界时的缩写   ...

  2. 【风马一族_Android】Android 前端内容1

    Android 前端内容 4.1 View 类概述 4.1.1 关于 View //类型说明 view(视图)指的是用户界面组件的基本构建基块.一个视图占据屏幕上的矩形区域,负责绘图和事件处理.视图是 ...

  3. CF 148A Insomnia cure

    题目链接:传送门 题目大意:就是给四个数,和一个d,问1-d中有多少个数字不是那四个数的倍数; 这道题的d数据很小直接暴力可以过: 暴力代码:时间复杂度O(1): #include<stdio. ...

  4. iOS 点击return或者点击屏幕键盘消失

    //定义两个文本框 UITextField *textName; UITextField *textSummary; //点击return 按钮 去掉 -(BOOL)textFieldShouldRe ...

  5. AIX性能监控topas命令的详细解析

    执行topas命令后如图所示: #topas 区域1:反映CPU使用率和工作状况  Kernel:操作系统的内核占用的CPU时间比率. 操作系统作为基础软件,为应用程序支持和服务的同时,本身的运行也需 ...

  6. vs2010中安装ASP.NET AJAX Control Toolkit

    方法一: 第一步 下载Ajax Control Toolkit 进入网址http://ajaxcontroltoolkit.codeplex.com/ 即可下载 第二步 解压下载下来的Ajax Con ...

  7. ActiveMQ之MessageListener

    消息的消费者接收消息可以采用两种方式: 1.consumer.receive()或 consumer.receive(int timeout); 2.注册一个MessageListener. 采用第一 ...

  8. 源码编译安装MySQL 5.7.9

    安装CentOS 6.3 配置yum:[root@hank-yoon ~]# cd /etc/yum.repos.d/ [root@hank-yoon yum.repos.d]# mkdir a [r ...

  9. 定位表的数据块并且dump出来

    SQL> select * from city;         ID NAME ---------- ----------          7 Chicago          6 Jers ...

  10. class_create(),device_create()使用

    开始写Linux设备驱动程序的时候,很多时候都是利用mknod命令手动创建设备节点(包括ldd3中不少例子也是这样),实际上现在Linux内核为我们提供了一组函数,可以用来在模块加载的时候自动在/de ...