Ultraviolet (*) live 2326-moving tables

Source: Internet
Author: User

Map the room numbers to a coordinate, sort the numbers, find a feasible plan from left to right, and find a feasible plan from left to right, find a feasible plan from left to right, and find a feasible plan from left to right,

............

Number of times * 10 is the answer


#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;struct node{    int s,e;};istream & operator >>(istream &is,node &a){    is>>a.s>>a.e;    return is;}bool cmp(node a,node b){    return a.s!=b.s?a.s<b.s:a.e<b.e;}int cg(int x){    return x&1?(x+1)>>1:x>>1;}int main(){   // freopen("in","r",stdin);    bool vis[210];    int T,i,j,n,ans;    node box[210];    node p;    cin>>T;    while(T--)    {        cin>>n;        for(i=0;i<n;i++)        {            cin>>box[i];            box[i].s=cg(box[i].s);            box[i].e=cg(box[i].e);            if(box[i].s>box[i].e)                swap(box[i].s,box[i].e);        }        ans=0;        memset(vis,0,sizeof(vis));        sort(box,box+n,cmp);        for(i=0;i<n;i++)        {            if(vis[i])                continue;            ans+=10;            p=box[i];            for(j=i+1;j<n;j++)            {                if(vis[j])                    continue;                if(box[j].s>p.e||box[j].e<p.s)                {                    vis[j]=1;                    p=box[j];                }            }        }        cout<<ans<<endl;    }    return 0;}

MOUs ACM (advanced computer maker) company has rented a floor ofa building whose shape is inthe following figure.

The floor has 200 rooms each on the North Side and south side along thecorridor. recently the companymade a plan to reform its system. the reform provided des moving a lot oftables between rooms. because thecorridor is narrow and all the tables are big, only one table can passthrough the corridor. some plan is neededto make the moving efficient. the manager figured out the followingplan: moving a table from a room toanother room can be done within 10 minutes. when moving a table fromroom ITo room J, The part of thecorridor between the front of room IAnd the front of room JIs used. so, during each 10 minutes, severalmoving between two rooms not sharing the same part of the corridor willbe done simultaneously. to make itclear the manager was strated the possible cases and impossible casesof simultaneous moving.

  Table moving Reason
Possible (Room 30 to room 50) and (room60 to room 90) No part of corridor is shared
(Room 11 to room 12) and (room14 to room 13) No part of corridor is shared
Impossible (Room 20 to room 40) and (room31 to room 80) Corridorin front of Room 31 toroom 40 is shared
(Room 1 to Room 4) and (room 3to Room 6) Corridorin front of room 3 isshared
(Room 2 to Room 8) and (room 7to room 10) Corridorin front of room 7 isshared

For each room, at most one table will be either moved in or moved out. now, the manager seeks out a methodto minimize the time to move all the tables. your job is to write aprogram to solve the manager's problem.

Input the input consists TTest cases. The number 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 thenumber of tables to move. Each of the following NLines contains two positive integers SAnd T,Representing that a table is to move fromroom number STo room number T(Each room numberappears at most once in NLines). From N+ 3-rdline, the remaining test cases are listed in the same manner as abve. output the output shoshould contain the minimum time in minutes to complete themoving, one per line. sample input
3410 2030 4050 6070 8021 32 200310 10020 8030 50
Sample output
102030

Ultraviolet (*) live 2326-moving tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.