Problem Description
Accounting for
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.
Input
Input is a
sequence of lines, each containing two positive integers s and
d.
Output
For each line
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.
Sample Input
59
237
375
743
200000
849694
2500000
8000000
Sample Output
116
28
300612
Deficit
题意:(说实话没看懂题,看了别人的博客才看懂题意,但是代码思路是自己的)这个公司中病毒了,数据丢了不少,但是他们公司在杂志上定期发布财务数据,所以留下了仅有的数据,连续五个月一公布,一年公布八次,1-5,2-6,3-7,4-8,5-9,6-10,7-11,8-12;并且每次都是亏钱的,现在给出盈利的钱数s,亏的钱数d;让你求最大盈利数;
解题思路:可以这么想先求前5个月的在亏钱的前提下,盈利月数最多的情况,这样6-10月结果可以和1-5月一样,11,12月的,要是5个月中盈利月数大约等于2,那么11,12月全盈利就行了,如果不是的话,就先把盈利的月数加上;
感悟:是不是得训练看题了......这个比英语阅读理解还烦.....
代码(G++ 0
MS)
#include

   #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的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. 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 ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [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 ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  10. PHP curl报错“Problem (2) in the Chunked-Encoded data”解决方案

    $s = curl_init(); curl_setopt($s, CURLOPT_POST, true); curl_setopt($s, CURLOPT_POSTFIELDS, $queryStr ...

随机推荐

  1. Java编程 “提高性能” 应尽力做到

    除了新增机器内存外,还应该好好review一下我们的代码,有很多代码编写过于随意化,这些不好的习惯或对程序语言的不了解是应该好好打压打压了. 下面是参考网络资源总结的一些在Java编程中尽可能要做到的 ...

  2. oss滤网图片音视频过滤(1)内容检测

    图片音视频过滤有好多方法,我这里就不一一介绍了,这篇文章只是简单介绍一下我在项目中使用阿里云oss滤网过滤的步骤 1.所遇问题: 1.图片视频鉴别时要设置textScanRequest.setUriP ...

  3. (一) .net core 2.0 初体验

    1..net core 2.0环境 .net core 下载地址:https://www.microsoft.com/net/core#windowscmd 问题一:提示[Failed to load ...

  4. Day4 闭包、装饰器decorator、迭代器与生成器、面向过程编程、三元表达式、列表解析与生成器表达式、序列化与反序列化

    一.装饰器 一.装饰器的知识储备 1.可变长参数  :*args和**kwargs def index(name,age): print(name,age) def wrapper(*args,**k ...

  5. 使用jsonp完美解决跨域问题

    调用web接口,get请求,发现提示:No 'Access-Control-Allow-Origin' header is present on the requested resource. 这个和 ...

  6. EXISTS/NOT EXISTS CASE WHEN等使用方法

    --简单判断用法 WHERE EXISTS (SELECT * FROM cpay..System_Setting) --可以替换count ) FROM cpay..System_Setting U ...

  7. Hadoop就是一个别人造好的轮子

    这个想法源自于我看了<Hadoop: The Definitive Guide>的Part I Ch 2中MapReduce的引入和介绍,书中先说了怎么通过原始的办法处理数据,然后引入到如 ...

  8. HDU1300 Pearls

    +)*= +)*= .总共需要的花费是150+=++)*= .在两组数据看来.珍珠都买了高品质的了,而且花费也少了!问题是怎么样能花费最少买珍珠! Add:合并肯定是相邻的合并.比如啊a<b&l ...

  9. 学习笔记之09小练习题(js:从小到大输出三个任意数,查成绩,相亲题,查体重,一元二次方程求根)

    <script type="text/javascript"> /*第一题.输入三个整数,x,y,z,最终以从小到大的方式输出. 注意小点:1 字符串的拼接是用+,数学 ...

  10. thinking in java 随笔

    初始化顺序 在一个类里,初始化的顺序是由变量在类内的定义顺序决定的.即使变量定义大量遍布于方法定义的中间,那些变量仍会在调用任何方法之前得到初始化--甚至在构建器调用之前.例如: class Tag ...