hdoj-4572-Rescue
2016-04-27 23:17
441 查看
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
m行n列,每行相邻的数,相差最大不超过1,每一列不能有重复的数,提供给你n个1,n个2,…,n个m让你填,对于每一行单独求一个和,每一种填法有个最大行和,作为这种填法的值。问所有填法的值的最小值是多少?
这个算是找规律的
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
m行n列,每行相邻的数,相差最大不超过1,每一列不能有重复的数,提供给你n个1,n个2,…,n个m让你填,对于每一行单独求一个和,每一种填法有个最大行和,作为这种填法的值。问所有填法的值的最小值是多少?
这个算是找规律的
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> int m, n; int main() { while (scanf("%d%d", &m, &n)!=EOF) { n = (n + 1) / 2; printf("%d\n", (m + (m - n) + 1) * n - ((m - n) + 1)); } return 0; }
相关文章推荐
- 【Map】Double Queue
- hdu1005Number Sequence
- EasyUI datagrid groupview 分组勾选问题的解决
- Android在非UI线程中显示Toast
- ajax异步处理时,如何在JS中获取从Servlet或者Action中session,request
- Android系统Surface机制的SurfaceFlinger服务渲染应用程序UI的过程分析
- Hue简介
- hdu 5667 Sequence(BC——矩阵快速幂)
- 如何在UITableView里动态添加 cell
- 几种常用容器的分析与比较
- IOS开发-UIView之动画效果的实现方法(
- 共同学习Java源代码--常用工具类--AbstractStringBuilder(七)
- 开发测试时给 Kafka 发消息的 UI 发送器――Mikasa
- 详解 $_SERVER 函数中QUERY_STRING和REQUEST_URI区别
- leetcode-303. Range Sum Query - Immutable
- Android 图文混排spannableStringBuilder简单使用
- IDEA 主题、字体、编辑区主题、文件编码修改
- 设置UITabBarController的用法
- js/jquer获取web页面上传文件的大小
- sdut 2605 Mountain Subsequences(树状数组)