首页 > 代码库 > poj1083
poj1083
Moving Tables
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 25176 | Accepted: 8373 |
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 another room 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 another room 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 file. 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 3 + N -rd
line, the remaining test cases are listed in the same manner as above.
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 3 + N -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
Source
Taejon 2001
虽然说这题是水题,可是很容易出问题,应该属于贪心吧,不过贪心的策略得好好考虑一下,这题扫描点,因为不管有冲突和没冲突,自己的动作都得完成,有冲突的就在冲突的地方走两边甚至多遍,没冲突的就只走一遍,于是就是一个根据输入的每组搬动的i,j,我们定义一个数组num,从i循环到j,中间经历过的点都加一,到最后遍历数组,找出最大值*10就是最后要求的值。
1 #include <iostream> 2 #include<cstring> 3 #include<cstdlib> 4 using namespace std; 5 6 int main() 7 { 8 int n; 9 while(cin>>n) 10 { 11 int a,b; 12 int num[401]={0}; 13 for(int i =0;i< n ;i++) 14 { 15 int m; 16 cin>>m; 17 for(int k=0;k<m;k++) 18 { 19 cin>>a>>b; 20 if(a>b) 21 swap(a,b); 22 if(a%2==0) 23 a--; 24 if(b%2==1) 25 b++; 26 for(int j=a;j<=b;j++) 27 num[j]++; 28 } 29 int maxnum=0; 30 for(int i=0;i<401;i++) 31 { 32 if(maxnum<num[i]) 33 maxnum = num[i]; 34 } 35 cout<<maxnum*10<<endl; 36 memset(num,0,sizeof(num)); 37 } 38 } 39 return 0; 40 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。