POJ 2586-Y2K Accounting Bug(贪心)
来源:互联网 发布:彩八仙时时彩软件 编辑:程序博客网 时间:2024/05/21 12:37
Y2K Accounting Bug
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 12742 Accepted: 6461
Description
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc.
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.
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
Input is a sequence of lines, each containing two positive integers s and d.
Output
For each line of input, output one line containing either a single integer giving the amount of surplus for the entire year, or output Deficit if it is impossible.
Sample Input
59 237375 743200000 8496942500000 8000000
Sample Output
11628300612Deficit
Source
Waterloo local 2000.01.29
题目意思:
有一家公司,盈为s,亏为d。而且一年中每个月的或盈或亏的数额都是一样的。
这家公司每五个月查一次账,一年12个月,所以是1-5、2-6、3-7、4-8、5-9、6-10、7-11、8-12这五次。
每行给出这家公司一个月的盈s亏d,求这家公司一年中是否能盈利,不能就输出Deficit。
解题思路:
题目真是看得我狂吐血。。勉强翻译出来了但就是没明白什么意思,后来翻了翻大神的博客。。恍然大悟
因为每5个月统计一次都亏空,那么有5种情况:
1、若SSSSD亏空,那么全年可能最大盈利情况为: SSSSDSSSSDSS
2、若SSSDD亏空,那么全年可能最大盈利情况为:SSSDDSSSDDSS
3、若SSDDD亏空,那么全年可能最大盈利情况为: SSDDDSSDDDSS
4、若SDDDD亏空,那么全年可能最大盈利情况为: SDDDDSDDDDSD
5、若DDDDD亏空,那么全年可能最大盈利情况为: DDDDDDDDDDDD
1、若SSSSD亏空,那么全年可能最大盈利情况为: SSSSDSSSSDSS
2、若SSSDD亏空,那么全年可能最大盈利情况为:SSSDDSSSDDSS
3、若SSDDD亏空,那么全年可能最大盈利情况为: SSDDDSSDDDSS
4、若SDDDD亏空,那么全年可能最大盈利情况为: SDDDDSDDDDSD
5、若DDDDD亏空,那么全年可能最大盈利情况为: DDDDDDDDDDDD
分别根据输入的sd判断,请注意前提是5个月统计一次都亏空,所以这五个月内d之和一定大于s之和。
/* * Copyright (c) 2016, 烟台大学计算机与控制工程学院 * All rights reserved. * 文件名称:sd.cpp * 作 者:单昕昕 * 完成日期:2016年4月28日 * 版 本 号:v1.0 */ #include <iostream>#include <malloc.h>#include <cstdio>#include <cmath>using namespace std; int main() { int s,d; int ans; while(cin>>s && cin>>d) { if(d>4*s)ans=10*s-2*d; else if(2*d>3*s)ans=8*s-4*d; else if(3*d>2*s)ans=6*(s-d); else if(4*d>s)ans=3*(s-3*d); else ans=-1; if(ans<0)cout<<"Deficit"<<endl; else cout<<ans<<endl; } return 0; }
0 0
- POJ 2586 Y2K Accounting Bug贪心
- POJ 2586 Y2K Accounting Bug 贪心
- poj 2586 Y2K Accounting Bug 贪心
- poj 2586 Y2K Accounting Bug (贪心)
- POJ 2586 Y2K Accounting Bug 贪心策略
- POJ 2586 Y2K Accounting Bug 贪心
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ 2586:Y2K Accounting Bug:贪心法
- poj 2586 Y2K Accounting Bug (贪心)
- POJ 2586:Y2K Accounting Bug(贪心)
- POJ--2586:Y2K Accounting Bug (贪心)
- 【贪心】POJ-2586 Y2K Accounting Bug
- POJ 2586 Y2K Accounting Bug(贪心)
- poj 2586 Y2K Accounting Bug 【贪心】
- POJ 2586-Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug 简单贪心
- POJ 2586 Y2K Accounting Bug(贪心)
- POJ 2586 Y2K Accounting Bug (贪心)
- 4月面试总结
- Ecplise打开xml文件时报Failed to create the part's controls错误
- 时间复杂度一定的算法1s内能处理的问题规模上限
- 【Unity3d开发记录】Unity动态画曲线、弧线(GL画线)在UI上的显示
- 【GDOI模拟】两场总结
- POJ 2586-Y2K Accounting Bug(贪心)
- pku 2769 - Reduced ID Numbers
- Android-AlertDialog各种对话框的用法
- Win7+Ubuntu双系统安装完成后时间不一致相差大概8小时
- 第九周项目1-深度复制体验(3)
- tomcat7.0 特性
- 【codevs3052&&1022】多米诺&覆盖,二分图
- Win7下SQL2012安装教程图文版
- tomcat 8.0特性