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
思路:
五个月内必有一次以上亏损,那么为了尽可能盈利如果五个月内4*s>d的话可以变成:oooox,oooox,oo 十二个月,盈利最大,类推一下,
实现代码;
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <bitset>
using namespace std; #define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
#define pb push_back
#define mp make_pair
const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define ms0(X) memset((X), 0, sizeof(X)))
#define SelfType int
SelfType Gcd(SelfType p,SelfType q){return q==?p:Gcd(q,p%q);}
SelfType Pow(SelfType p,SelfType q){SelfType ans=;while(q){if(q&)ans=ans*p;p=p*p;q>>=;}return ans;}
#define Sd(X) scanf("%d", &X)
#define Sdd(X, Y) scanf("%d%d", &X, &Y)
#define Sddd(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define all(a) a.begin(), a.end()
#define mem(x,v) memset(x,v,sizeof(x))
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
inline int read(){int ra,fh;char rx;rx=getchar(),ra=,fh=;while((rx<''||rx>'')&&rx!='-')rx=getchar();if(rx=='-')fh=-,rx=getchar();while(rx>=''&&rx<='')ra*=,ra+=rx-,rx=getchar();return ra*fh;}
//struct node{int a,b;}a[MAX][MAX];
//bool cmp(const node &x, const node &y){return x.a>y.a;} int main()
{
int s,d,ans;
while(cin>>s>>d){
if(*s<d) ans = s*-d*;
else if(*s<*d) ans = *s-*d;
else if(*s<*d) ans = *s-*d;
else if(s<*d) ans = *s - *d;
else ans = -;
if(ans <= ) cout<<"Deficit"<<endl;
else cout<<ans<<endl;
}
return ;
}

poj2586 【贪心】的更多相关文章

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

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

  2. poj2586 Y2K Accounting Bug(贪心)

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

  3. POJ2586 Y2K Accounting Bug(贪心)

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

  4. POJ3069 POJ2586 解题报告(异曲同工的贪心算法)

    [POJ 3069](2586见下) 原题在此:http://poj.org/problem?id=3069 题目大意: 一个直线上有N个点.点i的距离是Xi.从这些点中选取若干个加上标记.要求:对于 ...

  5. [POJ2586]Y2K Accounting Bug

    [POJ2586]Y2K Accounting Bug 试题描述 Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...

  6. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  7. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  8. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

随机推荐

  1. SkylineGlobe 如何实现工程进度管理或者说是对象生命周期管理

    SkylineGlobe 的 TerraExplorer Pro里面,给我们提供了一个Timespan Tags工具,通过这个工具,我们可以设置ProjectTree任务组对象的生命周期: 然后通过调 ...

  2. OSGeo.OGR.Geometry

    #region 程序集 ogr_csharp.dll, v2.0.50727 // D:\KM行业需求\C++\gdal17_cSharp\ogr_csharp.dll #endregion usin ...

  3. 一、java三大特性--封装

    封装字面意思即包装.专业点来说就是数据隐藏,是指利用抽象数据将数据和基于数据的操作封装起来,使其构成一个不可分割的独立实体,数据被保护在抽象数据类型的内部,尽可能的隐藏细节,只保留一些对外的接口和外部 ...

  4. 基于tensorflow的躲避障碍物的ai训练

    import pygameimport randomfrom pygame.locals import *import numpy as npfrom collections import deque ...

  5. 将WinForm程序(含多个非托管Dll)合并成一个exe的方法

    原文:将WinForm程序(含多个非托管Dll)合并成一个exe的方法 开发程序的时候经常会引用一些第三方的DLL,然后编译生成的exe文件就不能脱离这些DLL独立运行了. ILMerge能把托管dl ...

  6. Luogu T29912 fuck

    这是QZEZ的Luogu团队中的一道难得的水题,题面和数据都是CJJ dalao出的,然后我就没有太看懂题意. 也是一道经典的割点好题,但需要一定的思维. 首先对于题意,它只需要得到切断的作用就可以了 ...

  7. 事务,acid,cap,paxos随笔

    事务ACID四个特性: A:原子性(Atomicity)C:一致性(Consistency)I:隔离性(Isolation)D:持久性(Durability) 原子性:语句要么全执行,要么全不执行,是 ...

  8. item 2: 理解auto类型的推导

    本文翻译自modern effective C++,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 如果你已经读过item 1的模板类型推导,你已经知道大部分关于au ...

  9. css-preprocessors

    what ? 预处理器是css 能够使用 变量.操作符.函数.mixins.interpolations 等类似于js 功能的一种语言. 目前比较常用是三种:SASS.less .stylus . W ...

  10. Linux内核第二节

    作者:武西垚 深入理解函数调用堆栈 堆栈是C语言程序运行时必须的一个记录调用路径和参数的空间 堆栈的作用 函数调用框架 传递参数 保存返回地址 提供局部变量空间 堆栈相关的寄存器 esp,堆栈指针,指 ...