HDU 4572 Bottles Arrangement(数学推公式)——2013 ACM-ICPC长沙赛区全国邀请赛

传送门

Bottles Arrangement

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


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


题目大意:
有一个 mn 的矩阵,其中保证的 n 是一个奇数,在矩阵中需要满足如下两个条件:
1):每一列是 1m 的组合
2):每一行保证相邻列之间数字差值为 1
显然,这样的矩阵有很多。
求:每个矩阵一行中所有数的和的最大值m,这众多的矩阵中,m最小的那个值。
即:min(max(nj=1a[i][j]))

解题思路:
因为 n 是一个奇数,那么我们不妨设 n=2l+1
根据题目描述的范围 3n<2m ,可以求得 l 的范围 1l<m
因为每一列是 1m 的组合,那么假设行数一定为第 i 行, 第 l+1 列的值为 m ,即 ai,l+1=m
那么有如下两种情况:
1): 就是第 l 和 第l+2 列有一个值为 m
不妨设 l 列为 m ,那么可以列出如下不等式:
ai,l1m1 , ai,l2m2, ... ,ai,1ml+1
ai,l+2m1 , ai,l+3m2, ... ,ai,2l+1ml
将所有数字相加得到一个不等式(等差数列求和可得): 2l+1j=1ai,j(2l+1)ml2
即为: 2l+1j=1ai,jnm(n12)2

2):第 l 和 第l+2 列值都不为 m

设存在第i1 列有 ai1,l=m ,因为 ai,lm 所以一定存在一行 i1 有第 l 列为 m,因为相邻列之间差值 1
所以一定有 ai1,l+1=m1 ,因为 ai,l+1 已经有 m 了。
还有 ai1,l+2=m,又可以得出以下结论:
ai1,l1m1 , ai1,l2m2, ... ,ai1,1ml+1
ai1,l+3m1 , ai1,l+4m2, ... ,ai1,2l+1ml+1
将所有数字相加得到一个不等式(等差数列求和可得): 2l+1j=1ai1,j(2l+1)ml2
即为: 2l+1j=1ai1,jnm(n12)2
综上:
可得 ans=nm(n12)2

代码:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const double eps=1e-10;
int main()
{
    int n, m;
    while(~scanf("%d%d",&m,&n)){
        printf("%d\n",m*n-(n*n-2*n+1)/4);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值