[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 ...
随机推荐
- 关于ExpandableListView用法的一个简单小例子
喜欢显示好友QQ那样的列表,可以展开,可以收起,在android中,以往用的比较多的是listview,虽然可以实现列表的展示,但在某些情况下,我们还是希望用到可以分组并实现收缩的列表,那就要用到an ...
- 【dubbo】dubbo-admin在jdk 1.8上部署出错问题
今天在linux上部署dubbo-admin-2.5.4,一直报错: ERROR context.ContextLoader - Context initialization failedorg.sp ...
- VBA 打开一个string指定的文件
Open csvFileName For Input As #1 Dim lineChanger as String lineChanger = Chr(13) fileData = Split(St ...
- liveusb-creator
liveusb-creator The liveusb-creator is a cross-platform tool for easily installing live operating sy ...
- svn 同步脚本
REPOS="$1"REV="$2"export LANG=en_US.UTF-8/usr/bin/svn update /home/wwwroot/yswif ...
- 从官方下载 Bootstrap 版本 并写 第一个页面
从官方下载 Bootstrap 版本 页面内容参考自 http://www.cnblogs.com/sanjuantianshu/p/3935120.html bootstrap-3.2.0.zip ...
- C#学习笔记二: C#类型详解
前言 这次分享的主要内容有五个, 分别是值类型和引用类型, 装箱与拆箱,常量与变量,运算符重载,static字段和static构造函数. 后期的分享会针对于C#2.0 3.0 4.0 等新特性进行. ...
- DBA_Oracle日志文件 - altert / trace /audit / redo / archive log(概念)
2014-07-26 Created By BaoXinjian
- BEvent_客制化BusinessEvent通过PLSQL Procedurer接受消息传递(案例)
2014-06-27 Created By BaoXinjian
- 51nod 1120 机器人走方格 V3 卡特兰数 lucas定理
N * N的方格,从左上到右下画一条线.一个机器人从左上走到右下,只能向右或向下走.并要求只能在这条线的上面或下面走,不能穿越这条线,有多少种不同的走法?由于方法数量可能很大,只需要输出Mod 100 ...