[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 ...
随机推荐
- html之table标签
简单的html表格,由table元素以及一个或多个tr,th,td元素组成. tr:定义表格行 th:定义表格头 td:定义表格单元 更复杂的 HTML 表格也可能包括 caption.col.col ...
- eclipse提交subversion+apache的中文路径问题解决过程
原文链接:http://cavenfeng.iteye.com/blog/1921400 .download & patch: # wget http://webdav.todo.gr.jp/ ...
- Asp.Net MVC 路由 - Asp.Net 编程 - 张子阳
http://cache.baiducontent.com/c?m=9d78d513d98316fa03acd2294d01d6165909c7256b96c4523f8a9c12d522195646 ...
- Angular学习(4)- 数组双向梆定
示例: <!DOCTYPE html> <html ng-app="MyApp"> <head> <title>Study 4< ...
- bootstrap中datetimepicker只选择月份显示1899问题
直接修改bootstrap-datetimepicker.js中 update: function () { var date, fromArgs = false; if (arguments &am ...
- CSS媒体查询(@media)
@media only screen and (max-width: 500px) { .gridmenu { width:100%; } .gridmain { width:100%; } .gri ...
- find_in_set mysql
有个文章表里面有个type字段,他存储的是文章类型,有 1头条,2推荐,3热点,4图文 .....11,12,13等等 现在有篇文章他既是 头条,又是热点,还是图文, type中以 1,3,4的格式存 ...
- sublime_text3 用户配置
{ "auto_complete_triggers": [ { "characters": "", "selector" ...
- xorm使用pgsql的例子
测试表 /* Navicat Premium Data Transfer Source Server : localhost Source Server Type : PostgreSQL Sourc ...
- 【maven】之使用jetty发布web项目
<plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin ...