题目链接:

https://vjudge.net/problem/POJ-2586

题目大意:

MS公司(我猜是微软)遇到了千年虫的问题,导致数据大量数据丢失。比如财务报表。现在知道这个奇特的公司每个月不是盈利就是亏损(废话),而且无论是盈利和亏损都有一个定值(亏少了它还不干
)。经过ACM组织的分析,在一年中任意连续的5个月,它都是亏损的,但是全年就不一定亏损了。现在给你盈利和亏损的定值s和d,请求出它一年能得到的最大利润!如果亏了,就输出Deficit!

思路:

一开始暴力一发,枚举12个月的状态,TLE。应该贪心,

每五个连续的月一定亏损,我们可以设每五个月亏损月数最少为x,这种情况下,如果x能保证让这五个月为亏损,这是满足题意的盈利最大值!
x只能为1,2,3,4,5。 在保证连续5个月都亏损的前提下,使得每5个月中亏损的月数最少。根据d和s的不同五种情况
              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<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
int s, d; int main()
{
while(cin >> s >> d)
{
ll ans;
//如果四个月盈利小于一个月亏损 ssssdssssdss 答案是10s-2d
if( * s < d)ans = * s - * d;
//如果三个月盈利小于两个月亏损 sssddsssddss 答案是8s-4d
else if( * s < * d)ans = * s - * d;
//如果两个月盈利小于三个月亏损 ssdddssdddss 答案是6s-6d
else if( * s < * d)ans = * s - * d;
//如果一个月盈利小于四个月亏损 sddddsddddsd 答案是3s-9d
else if( * s < * d)ans = * s - * d;
//如果一个月盈利大于四个月亏损 dddddddddddd 答案是亏损
else ans = -;
if(ans < )cout<<"Deficit"<<endl;
else cout<<ans<<endl; }
return ;
}

POJ-2586 Y2K 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. poj 2586 Y2K Accounting Bug(贪心算法,水题一枚)

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

  4. 贪心 POJ 2586 Y2K Accounting Bug

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

  5. poj 2586 Y2K Accounting Bug

    http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...

  6. POJ 2586 Y2K Accounting Bug(枚举洪水问题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  7. POJ 2586 Y2K Accounting Bug(枚举大水题)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10674   Accepted: 53 ...

  8. [POJ 2586] Y2K Accounting Bug (贪心)

    题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...

  9. 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) ...

  10. POJ - 2586 Y2K Accounting Bug (找规律)

    Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...

随机推荐

  1. 很全的atom问题解决方案

    atom插件 http://blog.csdn.net/qq_30100043/article/details/53558381 atom社区 https://atom-china.org/

  2. 数据库 --> sqlite3总结

    Sqlite3总结 SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中. sqlite语句 #sqlite3 test.db //设置宽度为2sqlit ...

  3. C语言中数据类型的取值范围

    C语言中数据类型的取值范围如下:char -128 ~ +127 (1 Byte)short -32767 ~ + 32768 (2 Bytes)unsigned short 0 ~ 65536 (2 ...

  4. Android layout属性之gravity和layout_gravity

    1. gravity用来描述当前view的内容在view中的位置. gravity是控制其内容或者包含的views在该view(或view group)中的位置 2. layout_gravity是表 ...

  5. 解决Oracle登录时出现无法处理服务名问题

    1.首先找到客户端的tnsnames.ora文件,打开看看里面有没有配置相应的服务器名,服务器名就是你的数据库名: 2.如果有相应的服务器名,那就检查一下配置信息是否错误,如果没有就添加: 3.配置信 ...

  6. codeforce round#466(div.2)C. Phone Numbers

    C. Phone Numbers time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

  7. IDEA的快捷键的使用

    1.配置Intellij Idea的配置文件从默认c盘转移到其他盘符 找到Intellij idea的安装文件,在bin目录下找到idea.properties配置文件,如下把Idea的配置文件夹和I ...

  8. [W班]第二次结对作业成绩评价

    作业地址: https://edu.cnblogs.com/campus/fzu/FZUSoftwareEngineering1715W/homework/1016 作业要求: 1.代码具有规范性. ...

  9. 20145237 实验二 “Java面向对象程序设计”

    20145237 实验二 “Java面向对象程序设计” 实验内容 • 理解并掌握面向对象三要素:封装.继承.多态 • 初步掌握UML建模 • 熟悉S.O.L.I.D原则 • 使用TDD设计实现复数类 ...

  10. OpenGL中怎么把世界坐标系变成屏幕坐标系

    对这个3D坐标手动进行OpenGL的四个变换,得到的结果就是屏幕上的像素坐标.前三个变换(Model, View, Projection)都是4x4矩阵,操作对象是四维向量,所以需要把(100, 10 ...