Y2K Accounting Bug
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 12251   Accepted: 6202

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.

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 237
375 743
200000 849694
2500000 8000000

Sample Output

116
28
300612
Deficit
题意:12个月每个月要么盈利s,要么亏损d,连续五个月都是亏损的,即1-5,2-6,3-7,4-8,5-9,6-10,7-11,8-12;求一年最大盈利
分析:想了半天确实没想出怎么解,看了题解,却又感觉那么的合情合理,贪心考虑边界http://blog.csdn.net/lyy289065406/article/details/6642603
在保证连续5个月都亏损的前提下,使得每5个月中亏损的月数最少。
              x=1:  ssssd,ssssd,ss    d>4s     赢利10个月  10s-2d
              x=2:  sssdd,sssdd,ss    2d>3s    赢利8个月     8s-4d
              x=3:  ssddd,ssddd,ss    3d>2s    赢利6个月     6s-6d 
              x=4:  sdddd,sdddd,sd    4d>s     赢利3个月     3s-9d
              x=5:  ddddd,ddddd,dd    4d<s     无赢利
 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long s,d;
char str[] = "Deficit"; int main()
{
while(scanf("%I64d%I64d", &s, &d) != EOF)
{
if(d > * s)
{
if( * s - * d > )
{
printf("%I64d\n", * s - * d);
}
else
{
printf("%s\n", str);
}
}
else if( * s < * d )
{
if( * s - * d > )
{
printf("%I64d\n", * s - * d);
}
else
{
printf("%s\n", str);
}
}
else if( * s < * d)
{
if( * s - * d > )
{
printf("%I64d\n", * s - * d);
}
else
{
printf("%s\n", str);
}
}
else if(s < * d)
{
if( * s - * d > )
{
printf("%I64d\n", * s - * d);
}
else
{
printf("%s\n", str);
}
}
else
{
printf("%s\n", str);
}
} return ;
}

POJ2586Y2K 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. Y2K Accounting Bug(贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10945   Accepted: 54 ...

  4. POJ2586Y2K Accounting Bug

    http://poj.org/problem?id=2586 Description Accounting for Computer Machinists (ACM) has sufferred fr ...

  5. POJ2586 Y2K Accounting Bug(贪心)

    题目链接. 题目大意: 题目相当晦涩难懂啊. 一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能. 一个月s ...

  6. POJ-2586 Y2K Accounting Bug贪心,区间盈利

    题目链接: https://vjudge.net/problem/POJ-2586 题目大意: MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失.比如财务报表.现在知道这个奇特的公司每个 ...

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

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

  8. 贪心 POJ 2586 Y2K Accounting Bug

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

  9. poj2586 Y2K Accounting Bug(贪心)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=2586 ------ ...

随机推荐

  1. Masonry

    Autolayout就像一个知情达理,善解人意的好姑娘,可惜长相有点不堪入目,所以追求者寥寥无几.所幸遇到了化妆大师cloudkite,给她来了一个完美的化妆,从此丑小鸭Autolayout变成了美天 ...

  2. 014医疗项目-模块一:删除用户的功能l

    删除用户的功能我们还是按照:Dao->Service->Action->页面调试这种顺序来写. Dao: 我们使用逆向工程生成的方法就好: SysuserMapper sysuser ...

  3. [5]Telerik Extensions for ASP.NET MVC 开发问题

    1.Controller获取不到checkedNodes的问题 HTML @(Html.Telerik().TreeView()        .Name("TreeView")  ...

  4. 【原创】有关Silverlight中“DataGrid中级联动态绑定父/子ComboBox ”的示例。

    尝试了很多种方案,由于Datagrid动态生成的每行父子comboBox的Name的不确定性,给父ComboBox绑定事件中获取 子ComboBox很难根据Name获取到. 花了不少时间和公司同事商讨 ...

  5. CUDA安装及配置:Windows 7 64位环境

    最近又有新的项目要做了,这次是关于CUDA---多核高性能计算的问题,所以最近一直在学习CUDA的编程问题,昨天安装软件完毕,运行第一个程序的时候还是遇到很多问题.所以这里给大家一起分享一下, 有和我 ...

  6. Android 获取手机Mac地址,手机名称

    /** * 获取手机mac地址<br/> * 错误返回12个0 */ public static String getMacAddress(Context context) { // 获取 ...

  7. count(*) vs count(1)--social.msdn.microsoft.com

    Clever response Dave, but insufficient. I'll admit I've suggested this myself for certain questions ...

  8. 解决方法:未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序

    win7或win8 64位调试程序,出现这样的错误提示:未在本地计算机上注册 Microsoft.Jet.OLEDB.4.0 提供程序 解决方法如下: 方法一:“设置应用程序池默认属性”/“常规”/” ...

  9. HoloLens开发手记 - Unity之Gestures手势识别

    手势识别是HoloLens交互的重要输入方法之一.HoloLens提供了底层API和高层API,可以满足不同的手势定制需求.底层API能够获取手的位置和速度信息,高层API则借助手势识别器来识别预设的 ...

  10. Android中的Intent Filter匹配规则介绍

    本文主要介绍了隐式Intent匹配目标组件的规则,若有叙述不清晰或是不准确的地方希望大家指出,谢谢大家: ) 1. Intent简介 Intent用于在一个组件(Component,如Activity ...