题目链接

题目大意:

题目相当晦涩难懂啊。

一年的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. 3DS MAX 导出FBX到Unity3D设置

  2. 缓冲运动-1-[解决1].html

    <!DOCTYPE html> <html> <head lang="en">     <meta charset="UTF-8 ...

  3. 多版本号并发控制(MVCC)在分布式系统中的应用

    QQ群:289150599 问题 近期项目中遇到了一个分布式系统的并发控制问题.该问题能够抽象为:某分布式系统由一个数据中心D和若干业务处理中心L1,L2 ... Ln组成:D本质上是一个key-va ...

  4. UVA 10668 - Expanding Rods(数学+二分)

    UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图能够非常easy推出 ...

  5. MYSQL 体系结构图-LRU FREELIST FLUSH LIST

  6. php模拟HTTP协议发送post请求方法

    今天用到php模拟http发送post请求记录 代码如下: <?php $url = 'xxxx.com'; $data = 'a=one&b=two'; $data = urlenco ...

  7. python练习程序_员工信息表_基本实例

    python实现增删改查操作员工信息文件,可进行模糊查询: http://edu.51cto.com/lesson/id-13276.html http://edu.51cto.com/lesson/ ...

  8. access的时间相关的查询

    string sql = "select * from CONCURRENCY WHERE CONCURRENCY.DATE_FLAG BETWEEN  cdate('2013-11-1', ...

  9. webpack 配置 (支持 React SCSS ES6 编译打包 和 模块热更新 / 生成SourceMap)

    1.首先是目录结构 |-node_modules/ #包文件 |-build/ #静态资源生成目录 |-src/ #开发目录 |-js/ |-index.js #入口文件 |-app.js #Reac ...

  10. KMP算法总结

    kmp算法的T子字符串的下标的变化规律 大话数据结构这边书中的KMP算法的讲解跟最终的算法代码还是有很大的差别 java语言只会if判断语句,循环语句,但是这些语句以及可以包罗万象了,可以适用很多情况 ...