程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> hdu4572 Bottles Arrangement(找規律)

hdu4572 Bottles Arrangement(找規律)

編輯:C++入門知識

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<stdio.h>   
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<stdio.h>
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;
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved