POJ 2586:Y2K Accounting Bug(贪心)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10024 | Accepted: 4990 |
Description
All what they remember is that MS Inc. posted a surplus or a deficit each month of 1999 and each month when MS Inc. posted surplus, the amount of surplus was s and each month when MS Inc. posted deficit, the deficit was d. They do not remember which or how
many months posted surplus or deficit. MS Inc., unlike other companies, posts their earnings for each consecutive 5 months during a year. ACM knows that each of these 8 postings reported a deficit but they do not know how much. The chief accountant is almost
sure that MS Inc. was about to post surplus for the entire year of 1999. Almost but not quite.
Write a program, which decides whether MS Inc. suffered a deficit during 1999, or if a surplus for 1999 was possible, what is the maximum amount of surplus that they can post.
Input
Output
Sample Input
59 237
375 743
200000 849694
2500000 8000000
Sample Output
116
28
300612
Deficit
题意是:
对于每个月来说,不是盈利,就是亏损,假设是盈利则盈利S,假设亏空则亏d。
每五个月进行一次统计,共统计八次(1-5月一次,2-6月一次.......8-12月一次)
统计的结果是这八次都是亏空。
问题:推断全年能否盈利,假设能则求出最大的盈利。
假设不能盈利则输出Deficit
贪心思想:
每五个连续的月一定亏损,也就是不能出现连续5个月盈利,我们能够设每五个月亏损月数最少为x,这样的情况下,
假设x能保证让这五个月为亏损,这是满足题意的盈利最大值!
(比x大的,盈利也少了,题意是让求最大利润),x仅仅能为1,2,3,4,5.
当然x=5时, 则一定亏空。。
除了则之后,也就仅仅有四种情况ssssd ssssd ss
sssdd sssdd ss
ssddd ssddd ss
sdddd sdddd sd
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath> using namespace std; #define M 100500 int main()
{
int s, d;
while(~scanf("%d%d", &s, &d))
{
if(s>4*d)
{
printf("Deficit\n");
continue;
}
int t = 1;
while(s*(5-t)>d*t)
t++;
int k;
if(t==4)
k = 2*t+1;
else
k = 2*t;
int ans = s * (12-k) - d*k;
if(ans>0)
printf("%d\n", ans);
else
printf("Deficit\n");
}
return 0;
}
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 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...
- 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 ...
随机推荐
- POJ 2418 Hardwood Species( AVL-Tree )
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> ...
- 如果在线显示php源代码
原文:如果在线显示php源代码 通过php提供的函数highlight_file和highlight_string实现
- 快速学会搭建SVN服务器
原文:快速学会搭建SVN服务器 SVN是一个版本控制工具,常用于我们软件开发项目中,用来管理我们团队共同使用的代码,文档等历史版本的管理,保持代码的更新,避免混乱. 需要工具: svn安装程序:免费下 ...
- Twenty Newsgroups Classification任务之二seq2sparse(5)
接上篇blog,继续分析.接下来要调用代码如下: // Should document frequency features be processed if (shouldPrune || proce ...
- linux zombie process相关学习
1. zombie process是什么? zombie process是那些在系统中已经死掉的process, 通过ps -A | grep defunct可以查看系统中有多少zombie proc ...
- RSD和wlwmanifest是什么
今天小博发现header.php文件里<?php wp_head(); ?>显示有以下的两句代码,因为小博的网站打开速度实在太慢了,换空间怕麻烦,那就只有优化代码了. <link r ...
- linux的tr命令
tr(translate缩写)主要用于删除文件中的控制字符,或进行字符转换. 语法 tr [ -c | -cds | -cs | -C | -Cds | -Cs | -ds | -s] [ -A] S ...
- Cordova CLI源码分析(一)——简介
本系列文章分析基于node.js的命令行工具Cordova CLI,所以如果对node.js基础不是很了解,建议参考http://nodejs.gamesys.net/node-js提供的基础教程 文 ...
- jps查看java进程中哪个线程在消耗系统资源
jps或ps -ef|grep java可以看到有哪些java进程,这个不用说了.但值得一提的是jps命令是依赖于/tmp下的某些文件 的. 而某些操作系统,定期会清理掉/tmp下的文件,导致jps无 ...
- 一个css和js结合的下拉菜单,支持主流浏览器
首先声明: 本人尽管在web前端岗位干了好多年,但无奈岗位对技术要求不高.html,css用的比較多,JavaScript自己原创的非常少,基本都是copy改动,所以自己真正动手写时,发现基础非常不坚 ...