Problem DescriptionThe Famous ACM (Advanced computer Maker) company have rented a floor of a building whose shape was in the Following figure. The floor has a rooms each of the 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 was big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out of the following plan:moving a table from a hostel to another the can is done within minutes. When moving a table from the class I to the Class J, the part of the corridor between the front of the class I and the front of the class J is Used. So, during each minutes, several moving between and rooms not sharing the same part of the corridor would be done Simult aneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving. For each of the either, at the most one table would be a 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. Inputthe 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, which represents the number of tables to move . Each of the following N lines contains-positive integers s and t, representing that a table was to move from the hostel numbe R S to the guest number T (each of the number appears at a once in the N lines). From the N+3-rd line, the remaining test cases is listed in the same manner as above. Outputthe output should contain the minimum time in minutes to complete the moving, one per line. Sample INPUT3 4-2 1 3 2 3-ten-sample Output10 20 30-
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespacestd;structnode{intx, y;} data[205];intins[205];BOOLcmpConstNode &a,ConstNode &b) { if(a.x<b.x)return true; Else if(a.x==b.x) {if(A.Y<B.Y)return true; Else return false; } Else return false;}intMain () {intC,n,ans; CIN>>C; while(c--) {memset (INS,0,sizeof(INS)); Ans=0; CIN>>N; for(intI=0; i<n;i++) {cin>>data[i].x>>data[i].y; if(data[i].x>data[i].y) { intT; T=data[i].y; Data[i].y=data[i].x; data[i].x=T; } if(data[i].y%2!=0) Data[i].y++; if(data[i].x%2==0) data[i].x--; } sort (Data,data+n,cmp); for(intI=0; i<n;i++) { if(ins[i]==0) {Ins[i]=1; Ans++; intm=data[i].y; for(intj=i+1; j<n;j++) { if(data[j].x>m&&ins[j]==0) {m=data[j].y; INS[J]=1; } }}} cout<<ans*Ten<<Endl; } return 0;}
HDU 1050 Moving Tables