Hdu1050 Moving Tables 2016-05-19 16:08 87人阅读 评论(0) 收藏
Moving Tables
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
10
20
30
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include<vector>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f
struct node
{
int a,b,flag;
} p[10000];
bool cmp(node a,node b)
{
return a.a<b.a;
}
int main()
{
int m,t,n;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%d",&n);
memset(p,0,sizeof p);
for(int i=0; i<n; i++)
{
scanf("%d%d",&p[i].a,&p[i].b);
if(p[i].a>p[i].b)
swap(p[i].a,p[i].b);
if(p[i].a%2==0)
p[i].a--;
if(p[i].b%2)
p[i].b++;
}
sort(p,p+n,cmp);
int cnt=0;
int ans=0;
for(int i=0; i<n; i++)
{
if(p[i].flag==0)
{
ans++;
p[i].flag=1;
int cur=i;
int k=i;
while(k<n)
{
if(p[k].a>p[cur].b&&p[k].flag==0)
{
cur=k;
p[cur].flag=1;
}
k++;
}
}
}
printf("%d\n",ans*10);
}
}
return 0;
}
Hdu1050 Moving Tables 2016-05-19 16:08 87人阅读 评论(0) 收藏的更多相关文章
- SQL 存储过程 通过多个ID更新数据 分类: SQL Server 2014-12-08 16:08 299人阅读 评论(0) 收藏
下面举个例子说明: 我想让一部分品牌的名称(即Brand_Name)后面加上1,Brand_ID是主键,sql语句很容易实现,但是存储过程如何写呢? 错误写法如下: //*************** ...
- 【solr专题之四】在Tomcat 中部署Solr4.x 分类: H_HISTORY 2014-07-17 16:08 1286人阅读 评论(0) 收藏
1.安装Tomcat (1)下载并解压至/opt/tomcat中 # cd /opt/jediael # tar -zxvf apache-tomcat-7.0.54.tar.gz # mv apac ...
- Mahout快速入门教程 分类: B10_计算机基础 2015-03-07 16:20 508人阅读 评论(0) 收藏
Mahout 是一个很强大的数据挖掘工具,是一个分布式机器学习算法的集合,包括:被称为Taste的分布式协同过滤的实现.分类.聚类等.Mahout最大的优点就是基于hadoop实现,把很多以前运行于单 ...
- OC基础:block.字面量 分类: ios学习 OC 2015-06-22 19:08 155人阅读 评论(0) 收藏
block 块语法,可以用block去保存一段代码,或者封装一段代码. block 实际是由c语言实现的,执行效率很高. block 实际借鉴了函数指针的语法. block,在多线程.异步任务,集合遍 ...
- 烂漫爱心表白动画 分类: C# 2014-10-07 19:08 28人阅读 评论(0) 收藏
曾经我说过我会用程序来表达我对你的爱. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- 网上关于sort结构体排序都不完整,我来写一个完整版的 2014-08-09 16:50 60人阅读 评论(0) 收藏
主要参考sort函数_百度文库, 但是那篇有错误 2.结构体排序,a升,b降,c降 平板视图 打印? 01 #include <iostream> 02 #include <algo ...
- C语言基础总结 分类: iOS学习 c语言基础 2015-06-11 10:08 23人阅读 评论(0) 收藏
//欲练此功必先自宫!!! //第一天:C语言的基础 //进制 //2进制, 10进制, 8进制, 16进制 //注:8进制数前加0, 16进制数前加0x ...
- NavBarControl控件 2015-07-23 16:56 2人阅读 评论(0) 收藏
NavBarControl控件 1. 新建一个windows窗体应用程序项目 2. 在工具箱中的Navigation& Layout选项卡下找到NavBarControl, ...
- one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏
one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...
随机推荐
- SVM支持向量机推导,工具介绍及python实现
支持向量机整理 参考: Alexandre KOWALCZYK大神的SVM Tutorial http://blog.csdn.net/alvine008/article/details/909711 ...
- Mac和iOS开发资源汇总—更新于2013-10-14
小引本文主要汇集一些苹果开发的资源,会经常更新,建议大家把这篇文章单独收藏(在浏览器中按command+D).今天(2013年10月14日)收录了answer哥(黄爱武)的博客,欢迎大家围观! 今天( ...
- cookie保存用户名及密码
登陆页中,用户输入用户名密码,点击提交,后台对照mysq数据库中,看是否有对应的用户名,以及密码是否正确.如果正确 则将用户名密码分两份Cookie保存.页面跳转到登陆成功页. 用户再次访问登陆页时, ...
- 自然对数e(转)
e表示增长的极限 e=limx→+∞ (1+1/x)^x≍2.71828 假设,一根竹子,第一天是1米,第二天长了1米,然后这根柱子的长度变成了2米.相当于 (1+1/1)^1.上面这个假设,如果仔细 ...
- sysdig
centos 7 安装 https://sysdig.com/opensource/sysdig/install/ 1) Trust the Draios GPG key, configure the ...
- ubuntu中vim的设置
问题:刚安装的VIM中,backspace不能删除字符,且上下左右箭头没反应. 解决方法: sudo vi /etc/vim/vimrc.tiny 修改 set compatible为set noc ...
- mysql物理备份
原本以为直接将data文件夹下每个数据库对应的文件夹拷贝到新的MySQL的data文件夹就可以了,其实不然. 这样做有几个问题: 1.如果是用了引擎的表,还需要复制ibdata文件,并且frm文件所在 ...
- 'org.springframework.beans.factory.xml.XmlBeanFactory' is deprecated
'org.springframework.beans.factory.xml.XmlBeanFactory' is deprecated XmlBeanFactory这个类已经被摒弃了.可以用以下代替 ...
- reduction
reduction - 必应词典 美[rɪ'dʌkʃən]英[rɪ'dʌkʃ(ə)n] n.还原:降低:减少:缩小 网络缩减:减量:减小 变形复数:reductions:
- 3sum, 3sum closest
[抄题]: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find ...