贪心算法6之1000

来源:互联网 发布:大数据挖掘软件 编辑:程序博客网 时间:2024/05/16 16:03

1 题目编号:1000 problemA

2 题目内容:

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
102030

3 解题思路形成过程:之前自己一直在考虑用递归的思路循环遍历,并记录次数,但是提交一直不通过,不得已只能考虑上课老师讲解的思路,即记录所有的走廊占用情况,每被占用一次就加1,最后取占用次数的最大值再乘以10即可。

4 感想:自己做时一直没想到要讲房间号映射为走廊号,考虑不够仔细。

5 代码:#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int time[200];
int N,T;
int start, end;
cin >> T;
for (int k = 0; k < T; k++)
{
cin >> N;
memset(time, 0, sizeof(time));
for (int i = 0; i < N; i++)
{
cin >> start >> end;
start = (start - 1) / 2;
end = (end - 1) / 2;
if (end> start)
{
int  temp = start;
start= end;
end = start;
}


for (int j = start; j <= end; j++)
time[j] += 10;
}
int max = 0;
for (int i = 0; i < 200; i++)
if (time[i] > max) 
max = time[i];
cout << max<<endl;
}
return 0;
}


1 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 滕州不给报新婚怎么办 体内锁水能力差怎么办 别人说你人品差怎么办 面对没素质的人怎么办 遇到很坏的室友怎么办 餐饮员工与顾客发生矛盾怎么办 新员工老员工出现矛盾怎么办 手机移动4g网慢怎么办 碰到素质低的老公怎么办 小孩做事拖拉 没时间观念怎么办 execl表中日期加3.5怎么办 狗狗喜欢咬人怎么办 烧烤一顿吃多了怎么办 派派背包食物不足怎么办 未转变者下不了怎么办 小升初户籍与房产不一致怎么办 小孩在外地读书怎么办计生证明 泉州居住证要半年小孩读书怎么办 孩子上学有兰山户口没有房产怎么办 培训机构跑路了怎么办 报的培训班跑路怎么办 巡视组举报后会怎么办 巡视组交办不办怎么办 分手以后还要不要联系忘不了怎么办 父母穷且不上进怎么办 惹父母生气了该怎么办 小孩戒奶不吃奶粉怎么办 孩子听不进去话怎么办 异性好朋友喜欢自己亲吻自己怎么办 对方对你反感了怎么办 家长偷看孩子日记老师怎么办 儿子与父母相冲怎么办 初二孩子不争气老师打他怎么办? 孩子被老师打又怎么办 家里2个孩子打架怎么办 一年级的学生特别会顶嘴怎么办 私立学校的学生顶嘴老师该怎么办 孩子做错事家长不道歉怎么办 孩孑语文成绩差怎么办 高三了孩子不愿意补课怎么办 四年级的孩子上课喜欢讲小话怎么办