POJ2586Y2K Accounting Bug
http://poj.org/problem?id=2586
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
#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
POJ2586Y2K Accounting Bug的更多相关文章
- POJ2586Y2K Accounting Bug(贪心 + 不好想)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12251 Accepted: 62 ...
- [POJ2586]Y2K Accounting Bug
[POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
- Y2K Accounting Bug(贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10945 Accepted: 54 ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- 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 ...
- 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 ...
- POJ2586——Y2K Accounting Bug
Y2K Accounting Bug Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...
- poj 2586 Y2K Accounting Bug
http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...
- poj2586 Y2K Accounting Bug(贪心)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...
随机推荐
- PCB参数计算神器-Saturn PCB Design Toolkit下载及安装指南
进行PCB设计,特别是高频高速设计时,难免会涉及到PCB相关参数的计算及设置,如:VIA的过流能力,VIA的寄生电容.阻抗等,导线的载流能力,两相互耦合信号线间的串扰,波长等参数. 这里向大家介绍一款 ...
- ARM公布“物联网”嵌入式mbed OS系统软件平台
继ARM公司发布了为嵌入式微控制器设计的Cortex-M7架构处理器,ARM又公布了专为廉价低功耗“物联网”设计的新版软件及系统平台,以加速物联网设备的发展及部署.该软件为基于ARM现有Cortex- ...
- SecureCRT远程控制ubuntu
如果你拥有两台电脑一台是ubuntu,另一台是笔记本电脑,而你又想在远程控制你的ubuntu,那么SecureCRT就可以用了. 1:首先在你的ubuntu电脑上安装SSH服务 :apt-get i ...
- ubuntu下安装phpstudy环境记录
下载一键安装包 下载地址:http://www.phpstudy.net/a.php/208.html 安装过程 开启终端 更改文件权限 chmod +x phpstudy 进行安装 ./phpstu ...
- 例题6-3 Matrix Chain Multiplication ,Uva 442
这个题思路没有任何问题,但还是做了近三个小时,其中2个多小时调试 得到的经验有以下几点: 一定学会调试,掌握输出中间量的技巧,加强gdb调试的学习 有时候代码不对,得到的结果却是对的(之后总结以下常见 ...
- Python-Day2 Python基础进阶之数据类型
一.数据类型 Python3 中有六个标准的数据类型: Number(数字) String(字符串) List(列表) Tuple(元组) Sets(集合) Dictionary(字典) Python ...
- Spark 大数据平台
Apache Spark is an open source cluster computing system that aims to make data analytics fast - both ...
- NGUI3.5系列教程之 一些小功能的实现
(一)可拖动窗体的实现: 1:添加一个Sprite为鼠标点击区域,改名为:DragSprite 2:给DragSprite添加Collider 3:给DragSprite添加Drag Object , ...
- C#调用Python 脚本语言
1. 安装IronPython http://pan.baidu.com/s/1qW4jNJ2 下载IronPython 2.7 安装下载下来的安装包 2. 创建项目 创建一个C#的Windows窗 ...
- 无法将 flash.display::Sprite@156b7b1 转换为 mx.core.IUIComponent
无法将 flash.display::Sprite@156b7b1 转换为 mx.core.IUIComponent 在Flex Application里,是不能直接用addChild添加Sprite ...