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. java基础-浅复制与深复制的理解

    浅复制与深复制在很多编程语言中都有出现,那么什么是浅复制,什么是深复制呢? 要区分浅复制与深复制,首先我们要明确什么是复制,怎样才算是复制.复制的例子在生活中也随处可见,如复印一份文档,复制一段文字等 ...

  2. jquery 从页面获取li数组,删除不在数组中的key

    应用场景: 获取页面 li 下面 key的值,添加到 arr数组 删除车型不在arr 数组中的value值. 示例代码: var getSaleModels = function(brand_id){ ...

  3. jQuery对input中radio的一些操作

    通过jQuery获取页面中的所有radio对象,遍历页面中的radio,取消选中的标签,因为使用到jQuery时间,因此引用到了网上公共的js,这只是本人的一些总结,大神勿喷. <html> ...

  4. Android 多国语言

    参考android 开发文档,  ISO 639-1  ISO 3166-1-alpha-2 关于中国的: 中国其他地区: https://en.wikipedia.org/wiki/ISO_3166 ...

  5. hadoop数据流转过程分析

    hadoop:数据流转图(基于hadoop 0.18.3):通过一个最简单的例子来说明hadoop中的数据流转. hadoop:数据流转图(基于hadoop 0.18.3): 这里使用一个例子说明ha ...

  6. SOAP 介绍

    简介 SOAP(Simple Object Access Protoco)简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于 XML 的协议.此协议规范由 IBM.Microso ...

  7. 关于不同进制数之间转换的数学推导【Written By KillerLegend】

    关于不同进制数之间转换的数学推导 涉及范围:正整数范围内二进制(Binary),八进制(Octonary),十进制(Decimal),十六进制(hexadecimal)之间的转换 数的进制有多种,比如 ...

  8. 百度云demo2

  9. Ztack学习笔记(1)-初识Ztack

    一.Zigbee协议 Zigbee是IEEE 802.15.4协议的代名词,是一种短距离.低功耗的无线通信技术.这一名称来源于蜜蜂的八字舞,因为蜜蜂(bee)是靠飞翔和“嗡嗡”(zig)地抖动翅膀的“ ...

  10. Thinkphp模板中使用自定义函数的方法

    注意:自定义函数要放在项目应用目录/common/common.php中. 这里是关键. 模板变量的函数调用格式:{$varname|function1|function2=arg1,arg2,### ...