题目链接

题目大意:

题目相当晦涩难懂啊。

一年的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. Redis配置文件分析

    #Redis演示示例配置文件 # 注意单位问题:当须要设置内存大小的时候,能够使用类似1k.5GB.4M这种常见格式: # # 1k=> 1000 bytes #1kb => 1024 b ...

  2. Android中的Apk的加固(加壳)原理解析和实现

    一.前言 今天又到周末了,憋了好久又要出博客了,今天来介绍一下Android中的如何对Apk进行加固的原理.现阶段.我们知道Android中的反编译工作越来越让人操作熟练,我们辛苦的开发出一个apk, ...

  3. MYSQL 体系结构图 log commit

  4. 使用EPEL和REMI第三方yum源

    http://dl.fedoraproject.org/pub/epel/ epel-release-latest-.noarch.rpm redhat5 epel-release-latest-.n ...

  5. iOS平台基于ffmpeg的视频直播技术揭秘

    现在非常流行直播,相信很多人都跟我一样十分好奇这个技术是如何实现的,正好最近在做一个ffmpeg的项目,发现这个工具很容易就可以做直播,下面来给大家分享下技术要点: 首先你得编译出ffmpeg运行所需 ...

  6. python与数值计算环境搭建

    数值计算的编程的软件很多种,也见过一些编程绘图软件的对比. 利用Python进行数值计算,需要用到numpy(矩阵) ,scipy(公式符号), matplotlib(绘图)这些工具包. 1.Linu ...

  7. RxJava 教程-1 简介 原理 线程控制 变换

    简介 RxJava 是什么? RxJava 在 GitHub 主页上的自我介绍是 RxJava is a Java VM implementation of ReactiveX: a library ...

  8. Linux编程之定制带级别的log

    我的开发组长曾经说过这么一段话"一个优秀的程序员不在于他写代码有多快,也不在于他能不能实现这个模块的功能,要实现业务实现功能谁不会啊,重要的是他的解决能力,也就说当程序出现错误时你能不能够快 ...

  9. codevs4203山区建小学

    /* 状态:f[i][j] 前i个村庄已经建了j个学校 转移:f[i][j]=min(f[i][j],f[ii][j-1]+s[ii+1][i]) 1<=ii<=i-1 */ #inclu ...

  10. SQL In的替换

    前2天在搞SQL的的时候,发现其中有很多in的操作,诸如:id in(1,2,3)或id in(select id from table……),这个对SQL来说并不是最好的选择,执行效率是偏低的[它执 ...