acm 1000 Moving Tables(贪心算法)

1.1000

2.沿着走廊的北面和南面分别有200个房间(共计400间),公司搬桌子,从一个房间到另一个房间在10分钟内,当搬动一张桌子从房间i到房间J,房间i和房间j前面的部分走廊就被占用了.因此,在每个10分钟内,两个房间之间的搬动就不会同时用到走廊相同的部分.每个房间,只有一张桌子可以搬进或搬出.

输入格式 第一行例子数,第二行需搬桌子的个数,第二行从房间i到房间j,每个示例格式相同

输出格式 最短时间

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



3.设置从0开始足够大的数组,先放置房间间隔,运用循环统计每个事例的时间,输入房间号的同时注意房间单双数间隔分布,求出走廊间隔,桌子从房间小号到大号移动,否则相互交换,每个间隔10分钟,相对门的两个房间占用同一处走廊,所以例如有1——3和4——6移动方式时,它们是共享了同一段走廊. 将时间累加起来,直到全部搬完. 使用数组标记搬运桌子的路径的开始到结尾经过路径,循环结束后每次循环得到的局部最优值相加得到最优时间.

4.感想:这是我运用贪心法的起步道练习题,用时漫长,过程确实十分艰难,一开始毫无思路,还有很多使用不熟悉,通过翻书查找资料慢慢理清了头绪,但在具体写代码中先后修改了十多遍,终于提交通过,*v*

这次练习暴露了我很多问题

(1)英文题目看不熟,需多加练习

(2)c++中的许多stl应用不熟悉,还要加大学习力度

(3)分析问题上思路混乱,代码自我查错难

困难虽大,但一分辛苦一分才,不断地克服困难才能更上一层楼,希望自己能在接下来的acm训练中进步

5.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int arr[201];
int main()
{   int e,n;
int f,t,g;
int i,j,b;
    cin>>e;
    while(e--)
    {   
        memset (arr,0,sizeof (arr));
        cin>>n;
        g=0;
        for(b=0;b         {   cin>>f>>t;
            f=(f-1)/2;
            t=(t-1)/2;
            if (f>t)
            swap (f,t);
            for (i=f;i<=t;i++)
            {arr[i]+=1;}
        }
        for (j=0;j<200;j++)
        {   if (arr[j]>g)
            g=arr[j];
        }
        cout<     }
    return 0;
}

                                  

你可能感兴趣的:(贪心)