Problem M
Computer Machinists (ACM) has sufferred from the Y2K bug and lost
some vital data for preparing annual report for MS Inc.
All what they remember is that MS Inc. posted a surplus or a
deficit each month of 1999 and each month when MS Inc. posted
surplus, the amount of surplus was s and each month when MS Inc.
posted deficit, the deficit was d. They do not remember which or
how many months posted surplus or deficit. MS Inc., unlike other
companies, posts their earnings for each consecutive 5 months
during a year. ACM knows that each of these 8 postings reported a
deficit but they do not know how much. The chief accountant is
almost sure that MS Inc. was about to post surplus for the entire
year of 1999. Almost but not quite.
Write a program, which decides whether MS Inc. suffered a deficit
during 1999, or if a surplus for 1999 was possible, what is the
maximum amount of surplus that they can post.
sequence of lines, each containing two positive integers s and
d.
of input, output one line containing either a single integer giving
the amount of surplus for the entire year, or output Deficit if it
is impossible.
237
743
849694
8000000
MS)
#include
using namespace std;
int main()
{
//freopen("in.txt", "r", stdin);
int
s=0,d=0,money=0,month=0;
while(~scanf("%d%d",&s,&d))
{
money=month=0;
for(int i=1;i<=6;i++)
if(s*i>=d*(5-i))
{
month=i-1;
break;
}//算出来五个月亏钱时最少亏钱月数
//printf("month=%d\n",month);
switch(month)
{
case 0:money=-12*d;break;
case 1:money=3*s-9*d;break;
case 2:money=6*s-6*d;break;
case 3:money=8*s-4*d;break;
case 4:money=10*s-2*d;break;
}
if(money<0)
printf("Deficit\n");
else
printf("%d\n",money);
}
return
0;
}
Problem M的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案
$s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...
随机推荐
- Java 使用Axis实现WebService实例
在上一篇WebService实例中,基于jdk1.6以上的javax.jws 发布webservice接口.这篇博文则主要用eclipse/myeclipse 使用axis插件进行发布和调用WebSe ...
- [js高手之路] html5 canvas系列教程 - arc绘制曲线图形(曲线,弧线,圆形)
绘制曲线,经常会用到路径的知识,如果你对路径有疑问,可以参考我的这篇文章[js高手之路] html5 canvas系列教程 - 开始路径beginPath与关闭路径closePath详解. arc:画 ...
- 【JavaScript】设计模式-module模式及其改进
写在前面 编写易于维护的代码,其中最重要的方面就是能够找到代码中重复出现的主题并优化他们,这也是设计模式最有价值的地方 说到这里...... <head first设计模式>里有一篇文章, ...
- [mysql] ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).
用mysql -u root -p显示ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YE ...
- Life Forms (poj3294 后缀数组求 不小于k个字符串中的最长子串)
(累了,这题做了很久!) Life Forms Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8683 Accepted ...
- 宝藏(树形DP)
这道题目是十分考验思维的,n^2应该还是比较好想的,主要是如何转移根的问题.转移根,在我看来应该是树形dp最难的一部分了, 一般学会如何转移根,也就差不多考验通吃树形dp了. 下面转一转大佬链接: ...
- Java中的类型擦除与桥方法
类型擦除 Java在语法中虽然存在泛型的概念,但是在虚拟机中却没有泛型的概念,虚拟机中所有的类型都是普通类.无论何时定义一个泛型类型,编译后类型会被都被自动转换成一个相应的原始类型. 比如这个类 pu ...
- php基础运算符语句
/* 多行注释 *///常用数据类型//int string double/float bool//变量的定义$a = 123;$b = "123";$c = '456';//$d ...
- Vue实现勾选后向数组都添加
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- python3.6如何安装pymssql
使用pip install pymssql安装时,总是会出现UnicodeDecodeError.于是下载了适用的pymssql.whl进行安装,详细可参考 https://docs.microsof ...