贪心算法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.
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
- 贪心算法6之1000
- 算法之贪心算法
- 算法之贪心算法
- acm之贪心算法题目6
- 贪心算法之找钱
- 贪心算法之Dijkstra
- 常用算法之贪心
- 算法之贪心思想
- 贪心算法之Entropy
- 贪心算法之Packets
- 贪心算法之Stripies
- 算法设计之贪心
- leetcode之贪心算法
- c++算法之贪心
- 算法之贪心书架
- 算法进阶之贪心
- 贪心算法之+-字符串
- 常用算法之贪心算法
- iOS 获取已经安装应用
- Problem I-1008
- 将win7 firefox WebStorm PyCharm等JetBrains系列开发软件设置为豆沙绿护眼背景
- 顺序表实现
- openCV学习笔记---开门篇
- 贪心算法6之1000
- c++ 强制类型转换 static_cast dynamic_cast reinterpret_cast和const_
- 解析XML方式-DOM,SAX
- 关于React Native的一些麻烦事 mac
- 结构体大小问题
- 堆-堆排序学习总结
- Python垃圾回收机制
- atan2(a,b)和atan的区别
- [疯狂Java]UDP:UDP协议的概念