http://poj.org/problem?id=1083

  这道题题意是有若干段线段,每次要求线段不重叠地取,问最少取多少次.

  因为这些线段都是必须取的,所以需要让空隙最小

思路:

  循环直到线段全部取完,对于某个刚取得线段ij,下一个线段km取起点k尽量靠近j且满足k>j的.记录循环次数cnt,答案是cnt*10

注意:

  房间是相对的,也就是说对于奇数房间号,利用的走廊相当于对应的偶数房间号开始的那一段路程,

  一段路程的开头不能是另外一段路程的结尾.

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 400;
int n;
typedef pair<int,int> P;
P a[maxn];
bool vis[maxn];
int main()
{
freopen("data.in","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i = 0;i < n;i++)
{
scanf("%d%d",&a[i].first,&a[i].second);
if(a[i].first&1)a[i].first++;
if(a[i].second&1)a[i].second++;
if(a[i].first>a[i].second)swap(a[i].first,a[i].second);
}
sort(a,a+n);
memset(vis,false,sizeof(vis));
int cnt = 0;
for(int st = 0;st < n;st++)
{
if(vis[st])continue;
vis[st] = true;
cnt++;
for(int i = st + 1,e = a[st].second;i < n;i++)
{
if(a[i].first <= e || vis[i])continue;
vis[i] = true;
e = a[i].second;
}
}
printf("%d\n",cnt * 10);
}
return 0;
}

POJ 1083 Moving Tables 思路 难度:0的更多相关文章

  1. OpenJudge/Poj 1083 Moving Tables

    1.链接地址: http://poj.org/problem?id=1083 http://bailian.openjudge.cn/practice/1083/ 2.题目: 总时间限制: 1000m ...

  2. POJ 1083 Moving Tables

    题意:一个建筑物里有400个房间,房间都在一层里,在一个走廊的两侧,如图,现在要搬n张桌子,告诉你每张桌子是从哪个屋搬到哪个屋,搬桌子的线路之间不可以有重叠,问最少搬几次. 解法:贪心.一开始觉得只要 ...

  3. 1083 Moving Tables

    题目链接:http://poj.org/problem?id=1083 题意: 走廊两边分别有200个房间,一边连续编号为1-399的奇数,另一边是2-400的偶数, 如果从房间 i 移动桌子到房间 ...

  4. POJ 2253 Frogger 最短路 难度:0

    http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...

  5. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

  6. POJ 1035 Spell checker 字符串 难度:0

    题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...

  7. POJ 3984 迷宫问题 bfs 难度:0

    http://poj.org/problem?id=3984 典型的迷宫问题,记录最快到达某个点的是哪个点即可 #include <cstdio> #include <cstring ...

  8. POJ 2251 Dungeon Master bfs 难度:0

    http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...

  9. POJ 1321 棋盘问题 dfs 难度:0

    http://poj.org/problem?id=1321 注意是在'#'的地方放棋子 矩阵大小不过8*8,即使是8!的时间复杂度也足以承受,可以直接dfs求解 dfs时标注当前点的行和列已被访问, ...

随机推荐

  1. GooglePlay_下载apk

    关键字:"APK Downloader" 方式: (1)."APK Downloader"网站在线下载(无需我们的GooglePlay账户信息,也就无需Goog ...

  2. Python学习(6)循环语句

    目录 Python循环语句 - while循环语句 -- 无线循环 -- 循环使用else语句 -- 简单语句组 - for循环语句 -- 通过序列索引迭代 -- 循环使用else语句 - 循环嵌套 ...

  3. mysql 编码测试

    insert into t1(v1) values('cn中国'); select * from t1; 1.输入gbk,交互latin1,数据库latin1 insert,客户端把gbk的输入当成l ...

  4. 关于Socket的经验小结

    前言 IM通信在互联网发展到现在已经是码农的世界里人尽皆知的技术,特别在当下移动互联网迅猛发展的时代这种技术的开发也更加火热,其中老牌的代表作就有QQ和MSN,和最近新崛起的微信,默默,易信,来往等眼 ...

  5. [css] line boxes

    原文链接:http://www.zhangxinxu.com/wordpress/2010/01/css-float%E6%B5%AE%E5%8A%A8%E7%9A%84%E6%B7%B1%E5%85 ...

  6. PHP 注册树模式

    /** * 注册树模式 * 将对象注册到一个类中 * 通过该类实现全局访问操作对象 */ class Tree { private static $treeList = []; private fun ...

  7. 【linux 命令】:查看系统开机,关机时间【转载】

    转载原文:http://www.cnblogs.com/kerrycode/p/3759395.html 看Linux开机关机时间的方法(非常全面) 1: who 命令查看 who -b 查看最后一次 ...

  8. SqlServer_事务

    事务处理是在数据处理时经常遇到的问题,经常用到的方法有以下三种总结整理如下:方法1:直接写入到sql 中在存储过程中使用 BEGIN TRANS, COMMIT TRANS, ROLLBACK TRA ...

  9. 【c++】读写txt

    #include<iostrea> #include<fstream> int main() { ofstream fout;// 创建一个ofstream对象 fout.op ...

  10. 3D动画

    先上一道菜 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...