[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 ...
随机推荐
- Java文件读写
import java.io.*; public class Study { public static void main(String[] args) { try { String strPath ...
- 【linux】/etc/fstab修复
/etc/fstab在修改后,如果配置错误直接重启的话会导致系统崩溃.建议大家重启前执行mount -a ,mount -a是自动挂载 /etc/fstab 里面的东西.若不慎重启了,会出现开机错误, ...
- phonegap 2.7 ios配置安装详细教程(2.9通用)
原地址:http://www.cnblogs.com/yansi/archive/2013/05/14/3078222.html 在移动开发日益激烈的情况下我也不得不硬着头皮尝试下新鲜的html5的a ...
- RDO部署openstack(1)
1. 安装系统CentOS 6.5 2. 网络配置 Eth0 设置 # cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 ON ...
- 【设计模式】装饰者模式(Decorator)
装饰者模式 动态的将责任附加到对象上,若要扩展功能,装饰者提供了比继承更有弹性的替代方案. Java I/O中的装饰类 示例:coffee装饰者模式类图 顶层超类 被装饰组件-被装饰者 装饰者抽象类 ...
- 【Java编程进阶-1】enum枚举的使用
枚举主要用于枚举常量,下面举个简单的应用. 比如一个公司有如下几个部门: 研发部: 销售部: 财务部: (其他部门暂时不列举) 部门的某些信息相对固定,此时可以考虑使用枚举来说明: 枚举类 Depts ...
- WEBrick/Rack Puppet Master
Puppet's Services: The WEBrick Puppet Master Puppet master is the application that compiles configur ...
- 【sql】之使用sql根据身份证查询过生日人数
根据当前日期查询有多少人过生日 ,) = DATE_FORMAT(NOW(),'%m'); 查询price一样的人数 select * from people where price in (sele ...
- [系统开发] Postfix 邮件管理系统
一.简介 开发时间:2012年 开发工具:Perl CGI 这是我开发的 Postfix 邮件管理系统,通过它可以安全.方便的对邮件域名.用户.权限.组.邮箱容量.安全等进行各种设置:界面样式借鉴了 ...
- Metro 应用无法打开解决办法
1.恢复默认UAC设置: 2.恢复自带防火墙服务启动类型为自动: 3.设置IE为默认浏览器(搜索和应用中): 4.如有可能使用Microsoft帐户,而不是本地帐户(仅使用有限的几个Metro应用): ...