poj1083

来源:互联网 发布:手机怎样看淘宝的积分 编辑:程序博客网 时间:2024/05/01 15:05

http://poj.org/problem?id=1083

Moving Tables
Time Limit: 1000MSMemory Limit: 10000KTotal Submissions: 20134Accepted: 6580

Description

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

The floor has 200 rooms each on the north side and south side alongthe corridor. Recently the Company made a plan to reform itssystem. The reform includes moving a lot of tables between rooms.Because the corridor is narrow and all the tables are big, only onetable can pass through the corridor. Some plan is needed to makethe moving efficient. The manager figured out the following plan:Moving a table from a room to another room can be done within 10minutes. When moving a table from room i to room j, the part of thecorridor between the front of room i and the front of room j isused. So, during each 10 minutes, several moving between two roomsnot sharing the same part of the corridor will be donesimultaneously. To make it clear the manager illustrated thepossible cases and impossible cases of simultaneous moving.
poj1083

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

Input

The input consistsof T test cases. The number of test cases ) (T is given in thefirst line of the input file. Each test case begins with a linecontaining 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 andt, representing that a table is to move from room number s to roomnumber 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 asabove.

Output

The output shouldcontain the minimum time in minutes to complete the moving, one perline.

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

102030

Source

Taejon 2001
这题最大的收获或者感悟是题目的意思一定要理解正确,没理解题目就敲代码是非常愚蠢的。。我的acm师傅。。呵呵曾经说过不在于你做多少而在于你收获了多少。这题我就读了两天。。真是。。弱爆了。。不过有收获就是好的。题目的每一字可以说都是有用的,千万别心急。。
说说这题。题目中的表格要理解是什么意思,它告诉我们什么情况下移动是不能同时进行的。
比如3—5和4—6这里有重复要使用的4这个有什么用呢?接着看possible10—20和30—40,这里没有重复的区间,可以同时进行移动。。想来想去他为什么要这么说,其实就是要告诉你去求覆盖区间最大的区域,把最终的结果再*10就行了。。看看代码自己理解下。题目意思!还有这题网上分类是弄到dp里面去。。做的时候感觉是贪心。
 
#include<stdio.h>#include<string.h>int r[410];int main(){        int a,b,t;        while(scanf("%d",&t)!=EOF)        {                int i,j,n;                while(t--)                {                        memset(r,0,sizeof(r));                        int max=0;                        scanf("%d",&n);                        for(i=0;i<n;i++)                        {                                scanf("%d %d",&a,&b);                                {                                        if(a>b)//把输入的对应的每一组数据按小到大排序(仅仅是一组数据内排好序)
                                    {                                                int temp=a;                                                a=b;                                                b=temp;                                        }                                        for(j=(a+1)/2;j<=(b+1)/2;j++)//这边牵涉到数的奇偶性                                        {                                                r[j]++;                                                if(r[j]>max)                                                        max=r[j];                                        }                                }                        }                        printf("%d\n",max*10);                }        }        return 0;}
原创粉丝点击