Problem - 1050

  过两天要给12的讲贪心,于是就做一下水贪心练习练习。

代码如下:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector> using namespace std; typedef pair<int, int> PII;
typedef vector<PII> VPII; multiset<int> cor;
multiset<int>::iterator msi;
VPII rec;
VPII::iterator vi; int main() {
int n, T, l, r;
cin >> T;
while (T-- && cin >> n) {
cor.clear();
rec.clear();
for (int i = ; i < n; i++) {
cin >> l >> r;
if (l > r) swap(l, r);
rec.push_back(PII(l + >> , r + >> ));
}
sort(rec.begin(), rec.end());
vi = rec.begin();
cor.insert((*vi).second);
for (vi++ ; vi != rec.end(); vi++) {
msi = cor.lower_bound((*vi).first);
if (msi == cor.begin()) cor.insert((*vi).second);
else {
msi--;
cor.erase(msi);
cor.insert((*vi).second);
}
}
cout << cor.size() * << endl;
}
return ;
}

——written by Lyon

hdu 1050 Moving Tables (Greedy)的更多相关文章

  1. POJ 1083 &amp;&amp; HDU 1050 Moving Tables (贪心)

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. hdu 1050 Moving Tables 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 这道题目隔了很久才做出来的.一开始把判断走廊有重叠的算法都想错了.以为重叠只要满足,下一次mov ...

  3. --hdu 1050 Moving Tables(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1050 AC code: #include<stdio.h> #include<str ...

  4. hdu 1050 Moving Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1050 这个题我首先直接用的常规贪心,用的和那个尽可能看更多完整节目那种思路.但是.......一直WA....T ...

  5. HDU – 1050 Moving Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1050 当时这道题被放在了贪心专题,我又刚刚做了今年暑假不AC所以一开始就在想这肯定是个变过型的复杂贪心,但是后来 ...

  6. HDU 1050 Moving Tables (贪心)

    题意:在一个走廊两边都有对称分布的连续房间,现在有n张桌子需要从a移动到b房间.每次移动需要10分钟, 但是如果两次移动中需要经过相同的走廊位置,则不能同时进行,需要分开移动.最后求最少需要多长时间移 ...

  7. hdu 1050 Moving Tables(迷之贪心...)

    题意:有400间房间按题目中图片所给的方式排列,然后给出要移动的n张桌子所要移动的范围,每张桌子要移动的范围不能出现重叠的区域:问最少要多少次才能移动完所有的桌子. 题解思路:把题目转换下,就是有n个 ...

  8. HDOJ 1050 Moving Tables

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. 1050 Moving Tables

    Moving Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

随机推荐

  1. Apache HttpComponents 工具类 [ HttpUtil ]

    pom.xml <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId&g ...

  2. 2019-9-2-win10-uwp-保存用户选择文件夹

    title author date CreateTime categories win10 uwp 保存用户选择文件夹 lindexi 2019-09-02 12:57:38 +0800 2018-2 ...

  3. redis范围查询应用 数据库 数据库学习 Redis redis范围查询的方法

    redis范围查询应用. 需求 根据IP找到对应的城市 原来的解决方案 oracle表(ip_country): 查询IP对应的城市: 1.把a.b.c.d这样格式的IP转为一个数字,例如为把210. ...

  4. 导出excel表

    <?phppublic function export(){          #提现状态               $status = isset($_REQUEST['status'])? ...

  5. Maven常用命令备忘

    1. 修改版本号 mvn versions:set -DnewVersion=1.0.1-SNAPSHOT 2. <relativePath>的默认值是../pom.xml,如果没有配置, ...

  6. web前端学习(二)html学习笔记部分(9)-- 响应式布局

    1.2.23  响应式布局基础 1.2.23.1  响应式布局介绍 1.响应式布局是2010年5月份提出的一个概念,简而言之,就是一个网站能够兼容多终端 -- 而不是为每个终端做一个特定的版本.这个概 ...

  7. springboot-mybatis双数据源配置

    yml文件 spring: datasource: test1: driverClassName: com.mysql.jdbc.Driver url: jdbc:mysql://localhost: ...

  8. mysql实现行拼接、列拼接

    举例:有t_person表如下: 一.mysql行拼接: 拼接某一行: 无分隔符:select   CONCAT(id,idcard,`status`,content)   from  t_perso ...

  9. SSH免密码登录的方法

    在你的自己的机器下面使用ssh-keygen命令来实现创建公钥 将你~/.ssh目录中的id_rsa.pub这个文件拷贝到你要登录的服务器的~/.ssh目录中,然 后再运行以下命令来将公钥导入到~/. ...

  10. Balanced Binary Tree 判断平衡二叉树

    Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...