poj1083 Moving Tables
Moving Tables
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 26782
Accepted: 8962
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 cZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcnJpZG9yIGJldHdlZW4gdGhlIGZyb250IG9mIHJvb20gaSBhbmQgdGhlIGZyb250IG9mIHJvb20gaiBpcyB1c2VkLiBTbywgZHVyaW5nIGVhY2ggMTAgbWludXRlcywgc2V2ZXJhbCBtb3ZpbmcgYmV0d2VlbiB0d28gcm9vbXMgbm90IHNoYXJpbmcgdGhlIHNhbWUgcGFydCBvZiB0aGUgY29ycmlkb3Igd2lsbCBiZSBkb25lIHNpbXVsdGFuZW91c2x5LiBUbyBtYWtlIGl0IGNsZWFyIHRoZSBtYW5hZ2VyIGlsbHVzdHJhdGVkIHRoZQogcG9zc2libGUgY2FzZXMgYW5kIGltcG9zc2libGUgY2FzZXMgb2Ygc2ltdWx0YW5lb3VzIG1vdmluZy4gPGJyPgo8Y2VudGVyPjxpbWcgc3JjPQ=="http://www.2cto.com/uploadfile/Collfiles/20150204/20150204092916433.gif" alt="\">
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.
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,完了最後對計數器快排,最大的次數X10就是答案;
參考代碼:
#include
#include
#include
#include
using namespace std;
int main(){
int t,n,a[401],x,y;
cin>>t;
while (t--){
cin>>n;
memset(a,0,sizeof(a));
for (int i=0;i>x>>y;
if (x>y){
int temp=x;
x=y;
y=temp;
}
if (x%2!=0)
x++;
if (y%2!=0)
y++;
for (int j=x;j<=y;j+=2)
a[j]++;
}
sort(a,a+401);
cout<