杭电1050-Moving Tables
来源:互联网 发布:幼儿园美工室活动记录 编辑:程序博客网 时间:2024/06/04 01:32
Moving Tables
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11406 Accepted Submission(s): 3898
Problem Description
The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.
The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to anotherroom can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.
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.
The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to anotherroom can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.
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
解题思路其实很简单:
当初自己的思路有点问题,提交好多次WA后参考了他人的思想,哎,实现并没有太复杂。究其原因一是自己练得少,二是题目中的提示没有抓住(比如说那个走廊)
我实现的时候是将对门的房间看成一个组合,即是否有路线从这对房间中间的走廊经过,经过的话就加1,而这样的房间组合有200组,最后统计200组中经过最多的次数,就是需要等待的时间了。代码如下:
struct table{int start;int end;};void movetable(){int i,j,m,n,T,N,sum,c[50]={0};while(scanf("%d",&T)!=EOF){for (i=0;i<T;i++){scanf("%d",&N);table a[200]={0,0};int b[200] = {0};for (j=0;j<N;j++){int temp =0;scanf("%d %d",&a[j].start,&a[j].end);if(a[j].start>a[j].end){temp=a[j].start;a[j].start=a[j].end;a[j].end=temp;}for(sum=0;sum<200;sum++){if (sum>=((a[j].start-1)/2)&&sum<=((a[j].end-1)/2))b[sum]++;}}int max = 0;for(n=0;n<200;n++) {b[n]>max?max=b[n]:max=max;}c[i]=max*10;}for (i=0;i<T;i++) printf("%d\n",c[i]);break; }}
0 0
- 【杭电1050】Moving Tables
- 杭电1050-Moving Tables
- 杭电 Moving Tables
- 杭电 1150 moving tables
- 贪心算法—杭电1050 Moving Tables
- 杭电oj 1050 Moving Tables的解法
- 杭电OJ Moving Tables 解题报告
- Moving Tables(杭电1050)(贪心---区间不重叠问题)
- 杭电 acm step 1.3.1 Moving Tables
- 1050 Moving Tables
- HDU 1050 Moving Tables
- hdu 1050 moving tables
- HDU-1050 Moving Tables
- hdu-1050-Moving Tables
- HDU 1050 Moving Tables
- HDU 1050 Moving Tables
- hdu 1050 moving tables
- hdu 1050 Moving Tables
- jdk7之java.lang.invoke.MethodHandle
- 小兔崽子
- 牛市的回复牛市的回复
- 小瘪三小瘪三小瘪三小瘪三
- 对STM32系统时钟和分频的一点理解
- 杭电1050-Moving Tables
- 计算机专业该怎么要求自己
- 【J2SE视频】-JDK安装
- Android百分比布局支持库介绍——com.android.support:percent
- MySQL查看日志
- CodeForces 161B - Discounts
- 验证码验证模块
- 图 (中)
- HashSet 详解