找规律的简单题。太简单了!把规律告诉你们
如果输入的是:3 3 那答案就是 3 2 3+2+3=8
3
3 5 3 2 1 3+2+1+3+2=11
3 2
4 7 4 3 2 1 4+3+2+1+4+3+2=19
4 3 2
看懂了吧!题目自己就百度一下吧!
代码在最后面;
Problem Description
Hunan cuisine is really wonderful! But if you don’t like spicy food, you will feel terrible since it can be hard for you to find any food without hot pepper here. Big Fan is a student from the north who was not fit to the spicy food in Changsha. He became
thinner and thinner because eating little food and maintained his life mostly by drinking water. One day, he found that the wine in Hunan is pretty good, such as Jiugui, Liuyang River, Shaoyang Daqu and so on. He got addicted to it and became an alcoholic,
leading a depressed life.
Now N days have passed and he is sobered. He is surprised to find that there are exactly N×M bottles around him. Another amazing fact is that there are N bottles with height 1 and N bottles with height 2 … N bottles with height M.
Now he is interested in playing with these bottles. He wants to arrange all these bottles in a rectangle with M rows and N columns which satisfied:
(1)In any column, there are no bottles with same height;
(2)In any row, the height difference between any two adjacent bottles is no more than 1.
He defined a strange function Y which equals the maximum value of the total height of any single row. He is addicted in arranging these rubbish bottles to find the minimal Y. You know that he cannot solve it with his pour IQ. You are his friend and can’t
endure his decadence any more. So you decide to help him solve this problem and then bring him back to study.
Input
There are several test cases. For each case, the input contains one line with two integers M and N (1< M <= 10000, 3 <= N < 2×M, It is guaranteed that N is always odd).
The input will finish with the end of file.
Output
For each test case, print the minimal Y in single line.
Sample Input
Sample Output
代码:
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int M,N,sum=0;
while(scanf("%d%d",&M,&N)!=EOF)
{
for(int i=0;i
{
sum=sum+M;
M--;
}
sum=(sum)*2-(M+1);
cout<<sum<<endl;
sum=0;
}
return 0;
}
分享到:
相关推荐
一个十分简单的程序,能够ac杭电hdu的第2050题,无注释,简单明了
hdu 1005.比较简单的一道题,有兴趣的可以看看。
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
HDU的一题........HDU DP动态规
杭电ACMhdu1163
HDU1059的代码
hdu1001解题报告
hdu 1574 passed sorce
ACM HDU题目分类,我自己总结的大概只有十来个吧
hdu2101AC代码
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu ACM 各种排序
搜索 dfs 解题代码 hdu1241
我写的hdu上的一些题AC的题的代码 也许你会有用
HDU 的ACM 题目,只做了一些简单的,都是用JAVA语言写的
100道 acm C语言 hdu 解题报告
离线OJ题库(HDU ZJU等,部分有答案),需联网。
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
HDU 动态规划(46道题目