• poj1083


                                                                                                         Moving Tables
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 25176   Accepted: 8373

    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 file. 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 3 + N -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

    Taejon 2001
     
    虽然说这题是水题,可是很容易出问题,应该属于贪心吧,不过贪心的策略得好好考虑一下,这题扫描点,因为不管有冲突和没冲突,自己的动作都得完成,有冲突的就在冲突的地方走两边甚至多遍,没冲突的就只走一遍,于是就是一个根据输入的每组搬动的i,j,我们定义一个数组num,从i循环到j,中间经历过的点都加一,到最后遍历数组,找出最大值*10就是最后要求的值。
     1 #include <iostream>
     2 #include<cstring>
     3 #include<cstdlib>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int n;
     9     while(cin>>n)
    10     {
    11         int a,b;
    12         int num[401]={0};
    13         for(int i =0;i< n ;i++)
    14         {
    15             int m;
    16             cin>>m;
    17             for(int k=0;k<m;k++)
    18             {
    19                 cin>>a>>b;
    20                 if(a>b)
    21                     swap(a,b);
    22                 if(a%2==0)
    23                     a--;
    24                 if(b%2==1)
    25                     b++;
    26                 for(int j=a;j<=b;j++)
    27                     num[j]++;
    28             }
    29             int maxnum=0;
    30             for(int i=0;i<401;i++)
    31             {
    32                 if(maxnum<num[i])
    33                     maxnum = num[i];
    34             }
    35             cout<<maxnum*10<<endl;
    36             memset(num,0,sizeof(num));
    37         }
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    django中itsdangerous的用法
    Django之跨域请求同源策略
    django中如何建立抽象型数据库作为父模块可继承其功能
    cookie,session 的概念以及在django中的用法,以及cbv装饰器用法
    django开发日志配置
    RESTful API概念解析
    django Rest Framework---缓存通过drf-extensions扩展来实现
    匿名内部类
    android app出现红叉
    Failed to resolve: com.android.support:appcompat-v7:27.+
  • 原文地址:https://www.cnblogs.com/jhldreams/p/3750608.html
Copyright © 2020-2023  润新知