[POJ 2586] Y2K Accounting Bug (贪心)
题目链接:http://poj.org/problem?id=2586
题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就是陪d元。现在告诉你只要是连续的5个月,就亏钱(亏多少不知道),问你MS公司全年能够赚多少钱,如果赚不了钱的话,就输出“Deficit”
贪心:我们说,输出的最终结果是f(x,y)=x*s-y*d,也就是说现在要求得x,y使得f(x,y)具有最大值。
当s,d,x+y给定时,x越大,则赚的钱越多。
连续的5个月一共有8个:
1 | 2 | 3 | 4 | 5 |
2 | 3 | 4 | 5 | 6 |
3 | 4 | 5 | 6 | 7 |
4 | 5 | 6 | 7 | 8 |
5 | 6 | 7 | 8 | 9 |
6 | 7 | 8 | 9 | 10 |
7 | 8 | 9 | 10 | 11 |
8 | 9 | 10 | 11 | 12 |
我们希望亏损的月份更加集中,也就是说一个月能够尽量的贯穿更多的连续5个月。
因此应该是从右上角往左下角走,贴着最右边。
这样就能够出现不多的几种情况了。。(切勿想当然的想着对称)
#include <stdio.h>
#include <string.h> char imp[] = "Deficit"; int main(){
int s,b; while(EOF!=scanf("%d%d",&s,&b)){
if( *s<b ){
if( *s-*b< ) puts(imp);
else printf("%d\n",*s-*b);
} else if( *s<*b ){
if( *s-*b< ) puts(imp);
else printf("%d\n",*s-*b);
} else if( *s<*b ){
if( *s-*b< ) puts(imp);
else printf("%d\n",*s-*b);
} else if( s<*b ){
if( *s-*b< ) puts(imp);
else printf("%d\n",*s-*b);
} else puts(imp);
} return ;
}
[POJ 2586] Y2K Accounting Bug (贪心)的更多相关文章
- poj 2586 Y2K Accounting Bug (贪心)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8678 Accepted: 428 ...
- 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(贪心算法,水题一枚)
#include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- 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: 10674 Accepted: 53 ...
- POJ 2586 Y2K Accounting Bug(枚举大水题)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10674 Accepted: 53 ...
- POJ 2586 Y2K Accounting Bug(贪心)
题目连接:http://poj.org/problem?id=2586 题意:次(1-5.2-6.3-7.4-8.5-9.6-10.7-11.8-12),次统计的结果全部是亏空(盈利-亏空<0) ...
- POJ - 2586 Y2K Accounting Bug (找规律)
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...
随机推荐
- eclipse 怎么新建工作空间workspace
打开eclipse 点击文件“File”菜单切换工作空间“Switch Workspace”>其它“Other” 点击“Browser”选择新的工作空间目录. 选择新的工作空间目录,点击确定. ...
- MySQL5.7.13源码编译安装指南(转)
系统 CenterOs 6.5 1.安装依赖包(cmake make gcc等,其实好多都有了,不需要更新,为了防止世界被破坏,就装下) yum install gcc gcc-c++ -yyum i ...
- Window下SVN命令的使用总结
1 地址:http://subversion.apache.org/packages.html#windows 找到windows下的svn客户端工具.选择Win32Svn 进行安装. 一般环境变量会 ...
- WCF学习心得----(四)服务承载
WCF学习心得----(四)服务承载 这一章节花费了好长的时间才整理个大概,主要原因是初次接触这个东西,在做练习实践的过程中,遇到了很多的问题,有些问题到目前还没有得以解决.所以在这一章节中,有一个承 ...
- iptables基础信息介绍
在linux系统下,网络安全,除了有SElinux,另外就是iptables防火墙了,这个是用的最多也是功能非常强大的一个工具,今天就对其简单的架构上技术进行概要描述.让自己后续能够逻辑清晰的处理云环 ...
- Winform用匿名方法新建线程的方法
作用:1.将耗时的操作放在单独的线程,加快UI的响应速度.Thread t = new Thread(delegate() { parse.ParseDay(StockCode, FileName); ...
- 黄聪:get_posts 函数 | wordpress
get_posts 函数,简单的来讲是 get_post 的复数新形势,但因为是文章多篇提取,所以使用方法上却略有不同,支持众多参数选择需要提取的文章,在 CMS 主题中经常被用到,当然如果你对 Wo ...
- 最简单的ioc容器代码(低仿Spring )
Spring 的一大核心就是IOC,控制反转(依赖注入). 对象交由容器去控制,降低耦合性. Spring 的ioc实现原理其实很简单,容器启动后读取并解析配置文件,根据配置文件中<bean&g ...
- SecureCRT自动记录日志【记录键入的所有命令和打印的结果信息】
- HtmlParser
HtmlParser 基本类库使用 HtmlParser 提供了强大的类库来处理 Internet 上的网页,可以实现对网页特定内容的提取和修改.下面通过几个例子来介绍 HtmlParser 的一些使 ...