hdu 1050 Moving Tables 类似活动安排问题

Moving Tables

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

Problem 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.
 

 

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
  
  
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
 
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
    int ci;scanf("%d",&ci);
    while(ci--)
    {
        int n;scanf("%d",&n);
        int a[210];
        memset(a,0,sizeof(a));
        int ans=0;
        for(int i=0;i<n;i++)
        {
            int begin,end;
            scanf("%d%d",&begin,&end);
            if(begin>end){begin^=end;end^=begin;begin^=end;}
            for(int i=(begin+1)/2;i<=(end+1)/2;i++)//转换成区间段
            {
                a[i]++;
                if(a[i]>ans) ans=a[i];
            }
        }
        printf("%d/n",ans*10);
    }
    return 0;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct node
{
    int x,y;
};
node a[500];
int vis[500];
bool cmp(node h,node k)
{
    return h.x<k.x;//求多少天要按照开始时间排序,但是一般活动安排问题是一天最多能做多少活动,则需要按照结束时间排序
}
int main()
{
   // freopen("in.txt","r",stdin);
    //freopen("out_correct.txt","w",stdout);
    int ci,n;scanf("%d",&ci);
    while(ci--&&scanf("%d",&n)==1)
    {
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++)
        {
            int begin,end;
            scanf("%d%d",&begin,&end);
            if(begin>end) swap(begin,end);
            a[i].x=(begin+1)>>1,a[i].y=(end+1)>>1;
        }
        sort(a,a+n,cmp);
        int cnt=0;
        for(;;)
        {
            /*cout<<"cnt="<<cnt<<endl;
            cout<<"....................................."<<endl;
            for(int i=0;i<n;i++) if(vis[i]==0) cout<<"i="<<i<<"..."<<a[i].x<<"   "<<a[i].y<<endl;
            cout<<"....................................."<<endl<<endl;*/
            int j=-1;
            for(int i=0;i<n;i++)
            {
                if(vis[i]==0)
                {
                    j=i;break;
                }
            }
            vis[j]=1;
            if(j==-1) break;
            for(int i=j+1;i<n;i++)
            {
                if(vis[i]) continue;
                if(a[i].x>a[j].y)
                {
                    vis[i]=1;
                    j=i;
                }
            }
            cnt++;
        }
        printf("%d/n",cnt*10);
    }
    return 0;
}
/*
1
8
15 79
55 20
68 77
122 54
76 9
51 43
110 12
168 104
*/
//50
/*
1
17
101 45
173 49
61 68
1 186
148 151
191 81
145 42
177 100
169 94
171 112
26 15
76 149
74 5
157 133
48 24
82 43
170 143
*/
//100
/*
1
24
98 123
198 55
23 68
72 184
22 95
31 127
116 55
91 34
150 17
0 197
3 103
15 56
176 162
178 41
12 123
8 19
86 164
5 111
35 186
78 33
165 133
188 143
136 20
191 126
*/
//160
/*
1
153
45 91
150 159
175 58
126 62
38 83
73 131
8 28
37 57
12 70
183 188
46 145
13 46
160 83
189 145
124 107
53 21
104 82
189 5
152 85
186 85
18 12
76 95
150 142
65 54
13 65
27 178
116 44
168 174
185 144
66 38
21 63
150 21
154 3
184 21
166 10
127 177
72 24
124 184
35 77
129 114
98 121
192 120
179 150
177 167
15 5
0 165
96 11
86 143
67 149
71 58
64 177
5 17
112 175
171 63
159 65
12 101
170 14
108 53
139 45
143 128
74 153
121 102
182 175
150 20
148 176
3 115
39 11
180 94
105 50
151 83
161 184
169 78
158 17
16 107
139 27
9 27
43 36
35 8
55 60
92 52
85 172
114 79
187 143
108 160
12 64
18 182
18 196
154 151
150 129
45 128
196 31
49 70
194 166
72 133
162 9
65 175
93 18
21 191
179 85
45 142
49 89
171 118
50 132
182 54
121 111
1 181
101 146
166 34
22 48
39 43
191 15
53 196
45 153
93 11
191 30
112 2
23 198
25 68
80 177
5 196
71 153
110 122
119 99
64 31
112 18
24 59
8 180
41 125
5 49
9 51
145 145
27 2
166 85
46 96
44 154
103 57
162 105
42 55
57 130
47 13
7 34
34 189
114 154
107 40
123 171
32 79
198 175
80 79
199 81
113 186
47 199
59 116
39 46
*/
//790

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值