HDU 4572 Bottles Arrangement找规律 简单题

10 篇文章 0 订阅

Bottles Arrangement

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 295    Accepted Submission(s): 230


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 这是一道很简单的题,可以练一下自己找规律的能力,和细心能力, 另外也告诉我如果自己真的不知道正确答案可以试着 提交修改
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int m,n,sum,i,j;
	while(scanf("%d%d",&m,&n)!=EOF)
	{
		sum=0;
		/*	if(m<n)//一开始感觉自己找不到规律,其实这道题找几个数就行了,
		我忽略了一个条件就是n<2m,所以在m>n上面浪费了很多时间这份代码里的两个条件都是不必要的
		自己本来找到了m==n的情况,可是m<n的没有找到就是因为忽略了n<2m,找规律的题一定要看清条件

                  m,m,m-1,m-1,m-2,m-2,m-3,m-3

{
		{
			for(i=1;i<=n/m;i++)
				for(j=1;j<=m;j++)
					sum=sum+j;
				for(i=m;i>m-n%m;i--)
					sum=sum+i;
				printf("%d\n",sum);
		}
	else if(m==n)
		{
			for(i=1;i<=n/2;i++)
				for(j=m;j>m-2;j--)
					sum=sum+j;
				for(j=m;j>m-m%2;j--)
					sum+=j;
				printf("%d\n",sum);
		}	*/		
	//else 
		
		
				for(j=m;j>=m-n/2;j--)
					sum=sum+j;
				for(j=m;j>m-(n/2);j--)
					sum+=j;
				printf("%d\n",sum);
		}
	
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值