题目链接: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 (贪心)的更多相关文章

  1. poj 2586 Y2K Accounting Bug (贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8678   Accepted: 428 ...

  2. POJ 2586 Y2K Accounting Bug 贪心 难度:2

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10537   Accepted: 52 ...

  3. poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)

    #include <iostream> using namespace std; /*248K 32MS*/ int main() { int s,d; while(cin>> ...

  4. 贪心 POJ 2586 Y2K Accounting Bug

    题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...

  5. poj 2586 Y2K Accounting Bug

    http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...

  6. POJ 2586 Y2K Accounting Bug(枚举洪水问题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  7. POJ 2586 Y2K Accounting Bug(枚举大水题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  8. 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) ...

  9. POJ - 2586 Y2K Accounting Bug (找规律)

    Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...

随机推荐

  1. python爬虫之BeautifulSoup

    爬虫有时候写正则表达式会有假死现象 就是正则表达式一直在进行死循环查找 例如:https://social.msdn.microsoft.com/forums/azure/en-us/3f4390ac ...

  2. 通过改变计算机策略来解决“只能通过Chrome网上应用商店安装该程序”的方法及模版文件下载

    通过改变计算机策略来解决“只能通过Chrome网上应用商店安装该程序”的方法及模版文件下载 操作步骤 1.开始 -> 运行 -> 输入gpedit.msc -> 回车确定打开计算机本 ...

  3. Jfinal中log4j的配置

    基本不用配置: 1.web.xml不用配置: 2.添加文件log4j.properties到src下面: 3.lib中复制log4j的jar包进去: 4.可以使用了; package demo; im ...

  4. [jquery] jQuery jsTree V3.2.1 基础Demo

    引入对应的文件: <link rel="stylesheet" href="../dist/themes/default/style.min.css" / ...

  5. Hibernate3回顾-3-Session管理

    3.Session管理 仅为个人理解.请指正 3.1背景 由于Configuration的创建耗费系统的资源.所以有必要只将Configuration实例化一次,之后通过SessionFactory获 ...

  6. C#.NET ,微信退款证书

    微信退款时遇到:基础连接已经关闭 连接被意外关闭. 服务器环境:WIN SERVER 2008 R2.  WINDOWS服务承载的WCF服务,基于.NET FRAMEWORK 3.5. 第一笔交易的退 ...

  7. Android开发——通过扫描二维码,打开或者下载Android应用

    Android开发——通过扫描二维码,打开或者下载Android应用   在实现这个功能的时候,被不同的浏览器折磨的胃疼,最后实现了勉强能用,也查考了一下其他人的博客 android实现通过浏览器点击 ...

  8. 源码安装extundelete以及对遇到问题的解决

    软件下载:http://sourceforge.net/projects/extundelete/ 1.在安装extundelete包./configure时遇到configure: error: C ...

  9. 启动Memcache,出现memcached: error while loading shared libraries: libevent-1.4.so.1: cannot open shared

      1.有可能是装了多个 libevent而导致memcache无法识别哪一个,解决方法就是卸载掉一个libevent 2.只安装了一个libevent,但是也报这个错,解决方法 32位系统下:ln ...

  10. C#委托和事件讲解

    委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去的人每 ...