POJ 2586--Y2K Accounting Bug
来源:互联网 发布:政务数据开放流程 编辑:程序博客网 时间:2024/06/16 19:30
2017-10-03
原题链接
题目大意:
某公司每个月要么赚s元,要么亏d元,但是它每5个月才报一次帐(一年共报帐8次),每次报账结果都是亏钱。给出若干组s,d,求这一年中该公司最多可能的盈利值,如果不可能盈利,输出”Deficit”。
样例输入:
59 237375 743200000 8496942500000 8000000
样例输出:
11628300612Deficit
思路:
每5个月中都必须有至少1个、最多4个月亏损才可能实现5个月总体亏损但全年盈利,且亏损月应该尽可能少。而且每5个月中的亏损月应该尽可能靠后,这样接下来的5个月里亏损月才能尽可能的少。
在参考题解中,作者直接对最少亏损月数为1,2,3,4,5的情况进行了讨论。
参考题解
代码:
#include <iostream>#include <stdio.h>using namespace std;int main() { int s,d; while(scanf("%d%d",&s,&d) == 2) { int min_def; //每5个月中最少亏损月数 for(min_def = 1; min_def < 5; min_def++) { int tp = (5-min_def)*s - min_def*d; if(tp < 0) break; } int def = 0; //总计最少亏损月数 for(int a = 6-min_def; a <= 12; a += 5) def += 13-a > min_def?min_def:13-a; int result = (12-def)*s - def*d; if(result > 0) printf("%d\n",result); else printf("Deficit\n"); } return 0;}
阅读全文
0 0
- POJ 2586 Y2K Accounting Bug
- poj-2586-Y2K Accounting Bug
- poj 2586 Y2K Accounting Bug
- POJ 2586 Y2K Accounting Bug
- POJ 2586 Y2K Accounting Bug
- poj - 2586 - Y2K Accounting Bug
- POJ 2586 Y2K Accounting Bug
- poj 2586 Y2K Accounting Bug
- poj 2586 Y2K Accounting Bug
- poj 2586 Y2K Accounting Bug
- POJ 2586 Y2K Accounting Bug
- POJ 2586 Y2K Accounting Bug
- poj 2586 Y2K Accounting Bug
- poj 2586 Y2K Accounting Bug
- poj 2586 Y2K Accounting Bug
- POJ 2586 Y2K Accounting Bug
- ** poj Y2K Accounting Bug 2586
- poj 2586 Y2K Accounting Bug
- 用户登录流程详解 +volley(StringRequest)
- 关系型数据库原理
- 让我们来写数位DP吧~
- 嵌入式多路温湿度监控系统(十51单片机温湿度采集模块)
- response与request以及编码,路径的介绍
- POJ 2586--Y2K Accounting Bug
- 编写高质量代码改善Java程序的151个建议--总结摘抄
- JAVA多线程实现的三种方式
- ssm框架数据库取数据在前台分页显示
- Xcode添加main函数输入参数
- java中创建线程的方法
- ABP简单页面
- 关系型数据库工作原理简述
- C++ list用法