ACM 推桌子
推桌子
- 描述
- 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 推桌子的更多相关文章
- nyoj220 推桌子(贪心算法)
这道题太坑了,from 和to有可能写反,还得正过来: 推桌子 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The famous ACM (Advanced Co ...
- ny220 推桌子
推桌子 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The famous ACM (Advanced Computer Maker) Company has rent ...
- nyoj 220——推桌子——————【贪心】
推桌子 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 The famous ACM (Advanced Computer Maker) Company has re ...
- nyist 220 推桌子
题目链接:推桌子 题目意思:给你一些操作,将S出的桌子推到L出,但是这个过道有时会被占用,推一次是10min,不影响的操作可以同时开始,并且只记一次. 思路:贪心,首先按照S从小到大排序,决策:从第一 ...
- 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...
- ACM学习历程—UESTC 1217 The Battle of Chibi(递推 && 树状数组)(2015CCPC C)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 题目大意就是求一个序列里面长度为m的递增子序列的个数. 首先可以列出一个递推式p(len, i) = ...
- ACM组队安排-——杭电校赛(递推)
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #in ...
- 牛客网暑期ACM多校训练营(第二场) 题解 A run 递推 dp
链接:https://www.nowcoder.com/acm/contest/140/A来源:牛客网 White Cloud is exercising in the playground. Whi ...
- ACM/ICPC 之 简单DP-记忆化搜索与递推(POJ1088-滑雪)
递推型DP 将每个滑雪点都看作起点,从最低点开始逐个由四周递推出到达此点的最长路径的长度,由该点记下. 理论上,也可以将每一点都看作终点,由最高点开始计数,有兴趣可以试试. //经典DP-由高向低海拔 ...
随机推荐
- 微信支付:“当前页面的URL未注册”
最近在尝试着写微信支付方面的内容,今天下午的时候遇到了一个问题,也就是当前页面没有进行注册的问题. 在写好后台代码之后我在微信后台配置了测试授权目录和支付白名单,如下图所示,但是无论我如何进行测试总是 ...
- Delphi的TThread中的FreeOnTerminate成员
类 Create 了就要 Free; 但 TThread(的子类) 有特殊性, 很多时候我们不能确定新建的线程什么时候执行完(也就是什么时候该释放); 如果线程执行完毕自己知道释放就好了, 所以 ...
- Delphi面向对象的属性
可以把属性看成是能对类中的数据进行修改和执行代码的特殊的辅助域.对于组件来说,属性就是列在Object Inspector窗口的内容.下面的例子定义了一个有属性的简单对象 TMyObject = cl ...
- Pyqt 设置 背景颜色和背景图片、 QPalette 调色板 与QPainter 画板区别 、 不规则图片
设置 背景颜色和背景图片 首先设置autoFillBackground属性为真然后定义一个QPalette对象设置QPalette对象的背景属性(颜色或图片)最后设置QWidget对象的Palette ...
- org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:
详细错误堆栈信息: org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" ...
- leetcode4568
date: 2015-09-13 16:32:49 Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of ...
- silverlight和wpf中暴露 给子类override
protected virtual void OnSelectionChanged(SelectionChangedEventArgs args) { } public TestTabControl( ...
- 已解决:Strict Standards: Non-static method cls_image::gd_version() should not be called statically in...
在安装Ecshop的时候,遇到两个⚠️问题: Strict Standards: Non-static method cls_image::gd_version() should not be cal ...
- 解决phpMyAdmin“登录超时 (1440 秒未活动),请重新登录”的问题
问题描述 phpMyAdmin打开一段时间后会出现“登录超时 (1440 秒未活动),请重新登录”的问题: 解决方法 永久有效: vim config.inc.php 然后在里面加上下面这一行: $c ...
- Spring常用工具类
Spring框架下自带了丰富的工具类,在我们开发时可以简化很多工作: 1.Resource访问文件资源: 具体有: ResourceUtils.getFile(url); FileSystemReso ...