[贪心]HDU1085 Moving Tables
2015-07-24 13:44
274 查看
D - Moving Tables
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.
For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.
Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.
Output
The output should contain the minimum time in minutes to complete the moving, one per line.
Sample Input
3
4
10 20
30 40
50 60
70 80
2
1 3
2 200
3
10 100
20 80
30 50
Sample Output
10
20
30
相对门的两个房间占用同一处走廊,所以例如有1——3和4——6移动方式时,它们是共享了同一段走廊的,即3号房间门前的走廊。
分析过程有如下图所示
所以当左端起点为偶数时,要将其中左端的起点再向左移动一位,
当右端终点为奇数时,要将右端的终点在向右移动一位。
计算每一个位置上最大走过的次数。
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.
For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager’s problem.
Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<=N<=200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.
Output
The output should contain the minimum time in minutes to complete the moving, one per line.
Sample Input
3
4
10 20
30 40
50 60
70 80
2
1 3
2 200
3
10 100
20 80
30 50
Sample Output
10
20
30
相对门的两个房间占用同一处走廊,所以例如有1——3和4——6移动方式时,它们是共享了同一段走廊的,即3号房间门前的走廊。
分析过程有如下图所示
所以当左端起点为偶数时,要将其中左端的起点再向左移动一位,
当右端终点为奇数时,要将右端的终点在向右移动一位。
计算每一个位置上最大走过的次数。
#include <cstdio> #include <cstring> #include<algorithm> #define MAXN 505 using namespace std; int main() { int Count[MAXN]; int i, j, testNum, n, L, R; scanf("%d", &testNum); while (testNum-- != 0) { scanf("%d", &n); memset(Count, 0, sizeof(Count)); for (i = 0; i < n; i++) { scanf("%d %d", &L, &R); if (L > R) swap(L,R); if (L % 2 == 0) Count[L-1]++; if (R % 2 == 1) Count[R+1]++; for (j = L; j <= R; j++) Count[j]++; } printf("%d\n", *max_element(Count,Count+MAXN)*10); } return 0; }
相关文章推荐
- yii2利用mpdf创建pdf 中文乱码
- PAT (Basic Level) Practise (中文)1015. 德才论 (25) C语言
- uva348Optimal Array Multiplication Sequence (最优矩阵链乘+路径输出)
- 线索二叉树的两种方法
- arc下的block使用注意事项
- dfs序 + RMQ = LCA
- hdu3397 线段树 成段更新
- SCWS分词扩展在WINDOWS下的安装方法
- 一个简单的多线程题目
- Lowest Common Ancestor of a Binary Tree
- xcode6.4升级以后Alcatraz不能使用的解决办法
- Samba3.0服务器实战调试
- Python正则表达式指南
- hdu 2824 The Euler function
- put和post
- iphone手机屏幕大小
- GIT简单用法
- XAMPP 安装
- 揭秘百度核心技术:53位专家纯干货分享
- mysql union和union all 的区别以及使用