poj1083 2010.7.31

来源:互联网 发布:什么听歌识曲软件好 编辑:程序博客网 时间:2024/06/03 23:38

poj1083 2010.7.31

模拟_poj1083_Moving Tables_7_312010-07-31 14:59Moving TablesTime Limit:1000MS  Memory Limit: 10000K

Total Submissions: 13148  Accepted: 4336

 

Description

 

The famous ACM (Advanced Computer Maker)Company has rented a floor of a building whose shape is in the followingfigure.

 

The floor has 200 rooms each on the northside and south side along the corridor. Recently the Company made a plan toreform 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 canpass 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 toanother room can be done within 10 minutes. When moving a table from room i toroom j, the part of the corridor between the front of room i and the front ofroom j is used. So, during each 10 minutes, several moving between two roomsnot sharing the same part of the corridor will be done simultaneously. To makeit clear the manager illustrated the possible cases and impossible cases ofsimultaneous moving.

 

For each room, at most one table will beeither moved in or moved out. Now, the manager seeks out a method to minimizethe time to move all the tables. Your job is to write a program to solve themanager's problem.

Input

 

The input consists of T test cases. Thenumber of test cases ) (T is given in the first line of the input file. Eachtest 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 twopositive integers s and t, representing that a table is to move from room numbers to room number t each room number appears at most once in the N lines). Fromthe 3 + N -rd

line, the remaining test cases are listedin the same manner as above.

Output

 

The output should contain the minimum timein 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

 

 

水题。。但是。。WA了好久。。。还RE了一次。。。。

 

对于读入的房间编号x 我们给它一个新的编号 (x+1)/2,酱紫,面对面的房间的编号就一样了;

 

对于读入的每个区间,先转换成新的编号a和b,sum[a..b]每个都+1,最后看sum[i]的最大值,就是ans,也就是看那个新的编号被通过的次数最多;

 

RE是忘记 (x+1)/2直接用了;

 

WA是算法完全错。。唉。。我就不说是怎么错的了。。。囧死。。。对题意没理解清楚。。。

 

水题居然。。唉。。。

 

 

Code 136K 0MS

 

#include <cstdio>#include <cstring>using namespace std;#define MAXN 250int n,ans;int sum[MAXN];int minn,maxx;void init(){for(int i=1;i<=n;i++){   int a,b;   scanf("%d %d",&a,&b);   if (a>b)   {    int temp=a;    a=b;    b=temp;   }   a=(a+1)/2;   b=(b+1)/2;   for(int j=a;j<=b;j++)    sum[j]++;   if (a<minn)minn=a;   if (b>maxx)maxx=b;}}void doit(){for(int i=minn;i<=maxx;i++)   if (sum[i]>ans)    ans=sum[i];}int main(){int p;scanf("%d",&p);while (p--){   ans=-1;   minn=MAXN+1;   maxx=-1;   memset(sum,0,sizeof(sum));   scanf("%d",&n);   init();   doit();   printf("%d\n",ans*10);}return 0;}


0 0