Moving Tables

骑猪看日落 2022-08-07 15:57 177阅读 0赞

Moving Tables

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 22410 Accepted Submission(s): 7560

Problem Description

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

1050-1.gif

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.

1050-2.gif

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

  1. 3
  2. 4
  3. 10 20
  4. 30 40
  5. 50 60
  6. 70 80
  7. 2
  8. 1 3
  9. 2 200
  10. 3
  11. 10 100
  12. 20 80
  13. 30 50

Sample Output

  1. 10
  2. 20
  3. 30

这一题被归宿为贪心算法,但是仔细一看,就是感觉他是一个求

重复的最大次数!

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. using namespace std;
  5. int main()
  6. {
  7. int t,n,a[405],i,Min,b,c;
  8. cin>>t;
  9. while(t--)
  10. {
  11. Min=1;
  12. for(i=0;i<405;i++)
  13. {
  14. a[i]=0;
  15. }
  16. cin>>n;
  17. while(n--)
  18. {
  19. cin>>b>>c;
  20. if(b>c)
  21. {
  22. b=b+c;
  23. c=b-c;
  24. b=b-c;
  25. }
  26. if(b%2==1&&c%2==0)
  27. {
  28. for(i=b;i<=c;i++)
  29. {
  30. a[i]+=1;
  31. }
  32. }
  33. else if(b%2==0&&c%2==0)
  34. {
  35. for(i=b-1;i<=c;i++)
  36. {
  37. a[i]+=1;
  38. }
  39. }
  40. else if(b%2==1&&c%2==1)
  41. {
  42. for(i=b;i<=c+1;i++)
  43. {
  44. a[i]+=1;
  45. }
  46. }
  47. else
  48. {
  49. for(i=b-1;i<=c+1;i++)
  50. {
  51. a[i]+=1;
  52. }
  53. }
  54. }
  55. for(i=0;i<405;i++)
  56. {
  57. if(a[i]>Min)
  58. {
  59. Min=a[i];
  60. }
  61. }
  62. cout<<Min*10<<endl;
  63. }
  64. }

发表评论

表情:
评论列表 (有 0 条评论,177人围观)

还没有评论,来说两句吧...

相关阅读

    相关 POJ1083 Moving Tables

    题目大意:走廊中搬桌子,走廊的宽度只允许一张桌子通过,但允许路线不交叉的同时搬桌子,每次搬桌子都需要10分钟,问所需最短时间。 解题思路:统计搬桌子过程中经过每个房