题目链接

题目大意:

题目相当晦涩难懂啊。

一年的12个月,每5个月统计一次,如从1~5,2~6,3~7,...,8~12共统计了8次,已知每次都deficit,问这一年有没有盈利的可能。

一个月surplus只能是s,deficit只能是d,不能是其它的值。

分析:

用贪心,先计算1~5,让每个月都盈利,然后从第5个月向前deficit,直到1~5的和为deficit。继续2~6,3~7.。。。,8~12.

最后统计全年是否盈利。

AC代码如下:

#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; int main(){
int s, d, a[]; while(scanf("%d%d", &s, &d) == ) {
memset(a, , sizeof(a)); for(int i=; i<; i++) a[i] = s; for(int i=; i<; i++) {
a[i+-] = s;
while(true) {
int ans = ;
for(int j=; j<; j++) {
ans += a[i+j];
} if(ans > ) {
int j;
for(j=i+; j>=i; j--) if(a[j] > ) {
a[j] = -d; break;
}
}
else break;
}
} int ans = ;
for(int i=; i<; i++) ans += a[i]; if(ans > ) printf("%d\n", ans);
else printf("Deficit\n");
} return ;
}

POJ2586 Y2K Accounting Bug(贪心)的更多相关文章

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

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

  2. [POJ2586]Y2K Accounting Bug

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

  3. poj2586 Y2K Accounting Bug(贪心)

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

  4. POJ2586——Y2K Accounting Bug

    Y2K Accounting Bug   Description Accounting for Computer Machinists (ACM) has sufferred from the Y2K ...

  5. poj 2586 Y2K Accounting Bug (贪心)

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8678   Accepted: 428 ...

  6. POJ 2586 Y2K Accounting Bug 贪心 难度:2

    Y2K Accounting Bug Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10537   Accepted: 52 ...

  7. Y2K Accounting Bug(贪心)

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

  8. POJ2586 Y2K Accounting Bug 解题报告

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

  9. poj2586 Y2K Accounting Bug —— 枚举

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

随机推荐

  1. "Storage Virtualization" VS "Software-Defined Storage"

    http://www.computerweekly.com/blogs/StorageBuzz/2013/07/storage-virtualisation-vs-soft.html 这篇blog的目 ...

  2. PreTranslateMessage作用和用法

    PreTranslateMessage作用和用法  PreTranslateMessage是消息在送给TranslateMessage函数之前被调用的,绝大多数本窗体的消息都要通过这里,比較经常使用, ...

  3. Android应用打包安装过程具体解释

    Android应用打包安装过程(Run as Android Application ): 1,过程:Android Project --> Compilation and Packaging ...

  4. cocos2dx 自己主动加入cpp文件到android.mk

    将 LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldSce ...

  5. [转] Linux下查看文件和文件夹大小

    当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择. df可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力.    du可以查看文件及文件夹的大小. ...

  6. Java基础知识强化18:抽象类、接口的区别 和 选择性实现接口方法

    1.抽象类和接口的区别 抽象类里面可以有非抽象的方法(可以没有抽象方法),接口里只能有抽象方法. 抽象类中的抽象方法声明时不能有大括号,而接口中的所有方法都没有大括号.  抽象类(abstract c ...

  7. 有向图的欧拉路径POJ2337

    每个单词可以看做一条边,每个字母就是顶点. 有向图欧拉回路的判定,首先判断入度和出度,其实这个题判定的是欧拉通路,不一定非得构成环,所以可以有一个点的顶点入度比出度大1,另外一个点的出度比入度大1,或 ...

  8. android背景平铺方式 tileMode

    创建重复的背景图片  在drawable目录下创建一个repeat_bg.xml:    然后在布局的xml文件中可以这样引用:    ================================ ...

  9. Centos7+Apache2.4+php5.6+mysql5.5搭建Lamp环境——为了wordPress

    最近想搭建个人博客玩玩,挑来挑去发现口碑不错的博客程序是wordpress,简称wp.虽然是学java路线的程序员,但因入行时间太短,至今没有发现较为称手开源的博客程序,如果各位大神有好的推荐,也希望 ...

  10. Java编程思想-泛型-泛型方法

    代码示例如下: package generics; //: generics/GenericMethods.java public class GenericMethods<A> { // ...