推桌子

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述
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 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.
输出
The output should contain the minimum time in minutes to complete the moving, one per line.
样例输入
3
4
10 20
30 40
50 60
70 80
2
1 3
2 200
3
10 100
20 80
30 50
样例输出
10
20
30
注意题目要将给出的数据重新编号为1,2,3,4,......
还要注意s和t的大小
#include <iostream>
#include <vector>
#include <algorithm> using namespace std; struct TableMove{
int first;
int last;
bool visit;
TableMove(int first_ = ,int last_ = , bool visit_ = false):first(first_),last(last_),visit(visit_){}
bool operator <(const TableMove& a) const{
if(first!=a.first) return first < a.first;
else return last < a.last;
}
}; int main(){
int T;
cin >> T;
for(int icase = ; icase < T; icase ++){
int n;
cin >> n;
vector<TableMove> tableMove(n);
for(int i = ; i < n; ++ i){
cin >> tableMove[i].first >> tableMove[i].last;
tableMove[i].first = (tableMove[i].first+)/;
tableMove[i].last = (tableMove[i].last+)/;
if(tableMove[i].first > tableMove[i].last)
swap(tableMove[i].first,tableMove[i].last);
}
sort(tableMove.begin(),tableMove.end());
int cnt = ;
for(int i = ; i < n ; ++ i){
if(!tableMove[i].visit){
cnt++;
TableMove t = tableMove[i];
tableMove[i].visit = true;
for(int j = i +; j < n ; ++ j){
if(!tableMove[j].visit&&tableMove[j].first > t.last){
t =tableMove[j];
tableMove[j].visit = true;
}
}
}
}
cout<<cnt*<<endl;
}
}

 

ACM 推桌子的更多相关文章

  1. nyoj220 推桌子(贪心算法)

    这道题太坑了,from 和to有可能写反,还得正过来: 推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 The famous ACM (Advanced Co ...

  2. ny220 推桌子

    推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 The famous ACM (Advanced Computer Maker) Company has rent ...

  3. nyoj 220——推桌子——————【贪心】

    推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 The famous ACM (Advanced Computer Maker) Company has re ...

  4. nyist 220 推桌子

    题目链接:推桌子 题目意思:给你一些操作,将S出的桌子推到L出,但是这个过道有时会被占用,推一次是10min,不影响的操作可以同时开始,并且只记一次. 思路:贪心,首先按照S从小到大排序,决策:从第一 ...

  5. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  6. ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) =  ...

  7. ACM组队安排-——杭电校赛(递推)

    #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #in ...

  8. 牛客网暑期ACM多校训练营(第二场) 题解 A run 递推 dp

    链接:https://www.nowcoder.com/acm/contest/140/A来源:牛客网 White Cloud is exercising in the playground. Whi ...

  9. ACM/ICPC 之 简单DP-记忆化搜索与递推(POJ1088-滑雪)

    递推型DP 将每个滑雪点都看作起点,从最低点开始逐个由四周递推出到达此点的最长路径的长度,由该点记下. 理论上,也可以将每一点都看作终点,由最高点开始计数,有兴趣可以试试. //经典DP-由高向低海拔 ...

随机推荐

  1. history 清空历史记录 或 history不记录历史命令

    # vi ~/.bash_history 清空里面的记录,并退出当前shell # exit(一定要退出当前shell) # history 1 vi ~/.bash_history 2 histor ...

  2. EF – 2.EF数据查询基础(上)查询数据的实用编程技巧

    目录 5.4.1 查询符合条件的单条记录 EF使用SingleOrDefault()和Find()两个方法查询符合条件的单条记录. 5.4.2 Entity Framework中的内部数据缓存 DbS ...

  3. MVC基础知识 – 2.新语法

    1.自动属性 Auto-Implemented Properties 2.隐式类型 var 3.参数默认值 和 命名参数 4.对象初始化器 与 集合初始化器 { } 5.匿名类 & 匿名方法 ...

  4. Java集合源码学习(五)几种常用集合类的比较

    这篇笔记对几个常用的集合实现,从效率,线程安全和应用场景进行综合比较. >>ArrayList.LinkedList与Vector的对比 (1)相同和不同都实现了List接口,使用类似.V ...

  5. 【PHP绘图技术&&验证码绘制】

    PHP绘图是比较简单的事情,基本绘图如直线.圆.矩形.弧线.填充矩形.填充扇形.非中文字的打印.中文文字的打印在在下面的代码中会纤细讲解. 需要支持中文的字体,可以到windows自带的字体库中找,并 ...

  6. 人人网的账号登录及api操作

    .renren.php <?php /** * PHP Library for renren.com * * @author */ class renrenPHP { function __co ...

  7. 笔记本win7共享WIFI

    创建无线网络 (1)netsh wlan set hostednetwork mode=allow ssid=网络名 key=密码 启动承载网络(2)netsh wlan start hostedne ...

  8. hdu 2509 博弈 *

    多堆的情况要处理好孤单堆 #include<cstdio> #include<iostream> #include<algorithm> #include<c ...

  9. PMP 第十一章 项目风险管理

    1规划风险管理 2识别风险 3 风险定性分析 4风险定量分析 5规划风险应对 6监控风险 1.项目风险是什么?已知未知风险.未知未知风险对应应急储备和管理储备的关系.风险承受力和风险偏好是什么? 2. ...

  10. pylab模式

    启动IPython时ipython --pylab就可以进入pylab模式,这种模式下画图时图片不会直接蹦出来,而是嵌在交互环境中,当然sypder里自动是pylab模式了