设为首页 加入收藏

TOP

hdu4572 Bottles Arrangement(找规律)
2014-11-23 18:58:14 来源: 作者: 【 】 浏览:2
Tags:hdu4572 Bottles Arrangement 规律

Bottles Arrangement
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 224 Accepted Submission(s): 176


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
3 3
3 5

Sample Output
8
11
Hint
For the first case the solution is:
1 2 3
2 1 1
3 3 2

Source
2013 ACM-ICPC长沙赛区全国邀请赛——题目重现


这题写起来很简单,可是推理起来不简单,比赛时只觉得不简单就没做它,谁知道这么短的代码就能过了,只能说自己能力不够

这个算是找规律的,当时就直接跳过了。把m,m,m-1,m-1,m-2,m-2,m-3,m-3..........前n项求出来输出即可

关于这个题的证明,网上可以找到,有人看了,证明这个写了两页,反正比这个代码要长很多的

#include   
int main()  
{  
    int n,m,i,sum,j;  
    while(scanf("%d%d",&m,&n)!=EOF)  
    {  
        sum=0;  
        for(i=0;i<=n/2;i++)  
        {  
            sum+=(m-i)*2;  
        }  
        sum-=m-i+1;  
        printf("%d\n",sum);  
    }  
    return 0;  
}  

#include
int main()
{
	int n,m,i,sum,j;
	while(scanf("%d%d",&m,&n)!=EOF)
	{
		sum=0;
		for(i=0;i<=n/2;i++)
		{
			sum+=(m-i)*2;
		}
		sum-=m-i+1;
		printf("%d\n",sum);
	}
	return 0;
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 4629 计算几何 扫描线 下一篇dp hdu-4570-Multi-bit Trie

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python 教程 - W3Sch (2025-12-26 12:00:51)
·Python基础教程,Pyt (2025-12-26 12:00:48)
·神仙级python入门教 (2025-12-26 12:00:46)
·“我用Java 8”已成 (2025-12-26 11:19:54)
·下载 IntelliJ IDEA (2025-12-26 11:19:52)