把房间号映射在一条坐标上,然后排序,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,

............

次数*10就是答案

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
struct node
{int s,e;
};
istream & operator >>(istream &is,node &a)
{is>>a.s>>a.e;return is;
}
bool cmp(node a,node b)
{return a.s!=b.s?a.s<b.s:a.e<b.e;
}
int cg(int x)
{return x&1?(x+1)>>1:x>>1;
}
int main()
{// freopen("in","r",stdin);bool vis[210];int T,i,j,n,ans;node box[210];node p;cin>>T;while(T--){cin>>n;for(i=0;i<n;i++){cin>>box[i];box[i].s=cg(box[i].s);box[i].e=cg(box[i].e);if(box[i].s>box[i].e)swap(box[i].s,box[i].e);}ans=0;memset(vis,0,sizeof(vis));sort(box,box+n,cmp);for(i=0;i<n;i++){if(vis[i])continue;ans+=10;p=box[i];for(j=i+1;j<n;j++){if(vis[j])continue;if(box[j].s>p.e||box[j].e<p.s){vis[j]=1;p=box[j];}}}cout<<ans<<endl;}return 0;
}

mous ACM (Advanced Computer Maker) Company has rented a floor ofa building whose shape is inthe following figure. The floor has 200 rooms each on the north side and south side along thecorridor. Recently the Companymade a plan to reform its system. The reform includes moving a lot oftables between rooms. Because thecorridor is narrow and all the tables are big, only one table can passthrough the corridor. Some plan is neededto make the moving efficient. The manager figured out the followingplan: Moving a table from a room toanother room can be done within 10 minutes. When moving a table fromroomi to room j, the part of thecorridor between the front of room i and the front of room jis used. So, during each 10 minutes, severalmoving between two rooms not sharing the same part of the corridor willbe done simultaneously. To make itclear the manager illustrated the possible cases and impossible casesof simultaneous moving.

  Table moving Reason
Possible ( room 30 to room 50) and (room60 to room 90) no part of corridor is shared
(room 11 to room 12) and (room14 to room 13) no part of corridor is shared
Impossible (room 20 to room 40) and (room31 to room 80) corridor in front of room 31 toroom 40 is shared
(room 1 to room 4) and (room 3to room 6) corridor in front of room 3 isshared
(room 2 to room 8) and (room 7to room 10) corridor in front of room 7 isshared

For each room, at most one table will be either moved in or moved out.Now, the manager seeks out a methodto minimize the time to move all the tables. Your job is to write aprogram 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 file. Eachtest case begins with a line containing an integerN , 1<=N<=200 , that represents thenumber of tables to move.Each of the followingN lines contains two positive integers sand t, representing that a table is to move fromroom numbers to room number t (each room numberappears at most once in theN lines). From the N+3-rdline, the remaining test cases are listed in the same manner as above.

Output

The output should contain the minimum time in minutes to complete themoving, 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

uva live 2326 - Moving Tables相关推荐

  1. POJ1083 Moving Tables

    1083:Moving Tables 题目分析:初看似乎像贪心算法中的活动安排问题,不同的是这里的所有活动(相当于搬桌子的距离)都需要安排. 有四种贪心策略:最短优先,最长优先,最早开始时间优先,最早 ...

  2. hdu 1050 Moving Tables

    Moving Tables Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Font: ...

  3. Moving Tables(贪心)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 原题: Moving Tables Time Limit: 2000/1000 MS (Java/O ...

  4. UVa 1533:Moving Pegs(迭代加深搜索)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=842& ...

  5. hdu 1050 Moving Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1050 对与每个房间前面过道,操作一次标记一次,标记的最多的次数就是必须用的时间. 1 #include < ...

  6. poj 1083 Moving Tables

    题目 两种做法,开始用贪心做的,有种情况没考虑到,结果排序错了. 这个例子,感觉上有三个交点,以为是30,其实是20. 贪心代码: #include <iostream> #include ...

  7. 【POJ1083】 Moving Tables (并行的搬运)

    BUPT2017 wintertraining(15) #6E 题意 房间1和2,3和4,...,399和400共用一节走廊,有q次从房间li到ri的搬运桌子,一次搬运10分钟.两个搬运如果走廊有重叠 ...

  8. POJ-1083 Moving Tables(imos算法)

    这一题有两个陷阱: 给出的起始点可能小于终点 ,所以必须要加个判断,让第二个数大于第一个数 区间算的时候,一定是奇数到偶数,才能做到真正的区间全覆盖.所以如果第二个数是奇数,要加一变为偶数:第一个数为 ...

  9. HDU 1050 NYOJ 220 Moving Tables

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050  http://acm.nyist.net/JudgeOnline/problem.php?pi ...

最新文章

  1. 软件测试职业培训中心,软件测试工程师就业班
  2. 【项目管理】采购管理
  3. Android框架式编程之MVP架构
  4. Qt 第二步 熟悉文件结构组成(二)
  5. 【Qt开发】Qt让线程休息一段时间
  6. Tabs Outliner(标签系统)
  7. AlexNet详解2
  8. 使用 spring-boot 的 RabbitMQ 范例测试我的 RabbitMQ 服务器
  9. Python新闻网站项目-8.Django前端Web部署
  10. linux readelf,readelf命令常用参数介绍
  11. Mac OS X 快捷键(完整篇)
  12. 别头疼了,你要的算法和数据结构的学习路线来了!
  13. 使用TkMybatis逆向生成带中文注释文件,并使用其常用的方法
  14. Chrome怎么导出扩展程序(插件)为crx文件
  15. PTA 7-2 构建下三角矩阵 (15分) 非得用vector
  16. 查看使用linkedIn Camus 把Kafka中的数据导入HDFS中生成的.deflate文件
  17. 电信手机号段的归属地汇总l表
  18. 中大华工计算机分数,中大华工部分专业分数线猛涨
  19. 电气工程与计算机最好的大学,加州大学伯克利分校电气工程与计算机科学研究生怎么样?好不好...
  20. 梦幻西游H5私服服务端超详细图文架设教程

热门文章

  1. 在linux下一般用scp这个命令来通过ssh传输文件
  2. wordpress通过$wpdp更新数据表内容
  3. 编译Nginx提示gzip module requires the zlib library
  4. 解决hibernate双向关系造成的一方重复执行SQl,或者死循环的问题
  5. 20190520算法题存档
  6. java8中stream中的任务拆分
  7. 区块链入门与去中心化应用实战 之一 第2章 区块链技术的核心概念和原理
  8. 如何避免用动态语言的思维写Go代码
  9. 给网站添加灰白滤镜(默哀主题色)
  10. Stopping ADB server failed(code -1)