(~ ̄▽ ̄)~*

//求一个集合,这个集合与任意一个区间的交集,需至少有两个数字
//贪心过程:按n个区间的最右值从小到大对区间进行排列,
//集合首先取第一个区间的最右两个数字,
//到第二个区间,判断集合里的数有没有在区间里
//没有的话,就从第二个区间的最右开始往左取(cnt=0取最后两个数,cnt=1取最后一个数)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std; struct interval
{
int l,r;
}a[10005]; bool cmp(interval a,interval b)
{
return a.r<b.r;
} int main()
{
int n,res=0; scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d %d",&a[i].l,&a[i].r);
sort(a,a+n,cmp); vector<int> Set;
Set.push_back(a[0].r-1);
Set.push_back(a[0].r);
res=2;
for(int i=1;i<n;i++)
{
int cnt=0;
for(int j=0;j<Set.size();j++)
{
if(Set[j]>=a[i].l&&Set[j]<=a[i].r)
cnt++; }
if(cnt==0)
{
Set.push_back(a[i].r-1);
Set.push_back(a[i].r);
res+=2;
}
else if(cnt==1)
{
Set.push_back(a[i].r);
res++;
}
}
printf("%d\n",res);
return 0;
}

POJ 1716 Integer Intervals#贪心的更多相关文章

  1. poj 1716 Integer Intervals(差分约束)

    1716 -- Integer Intervals 跟之前个人赛的一道二分加差分约束差不多,也是求满足条件的最小值. 题意是,给出若干区间,需要找出最少的元素个数,使得每个区间至少包含两个这里的元素. ...

  2. poj 1716 Integer Intervals (差分约束 或 贪心)

    Integer Intervals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12192   Accepted: 514 ...

  3. POJ 1201 Intervals || POJ 1716 Integer Intervals 差分约束

    POJ 1201 http://poj.org/problem?id=1201 题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai, ...

  4. POJ 1716 Integer Intervals 差分约束

    题目:http://poj.org/problem?id=1716 #include <stdio.h> #include <string.h> #include <ve ...

  5. POJ 1716 Integer Intervals

    题意:给出一些区间,求一个集合的长度要求每个区间里都至少有两个集合里的数. 解法:贪心或者差分约束.贪心的思路很简单,只要将区间按右边界排序,如果集合里最后两个元素都不在当前区间内,就把这个区间内的最 ...

  6. 【POJ 1716】Integer Intervals(差分约束系统)

    id=1716">[POJ 1716]Integer Intervals(差分约束系统) Integer Intervals Time Limit: 1000MS   Memory L ...

  7. 【POJ 1201】 Intervals(差分约束系统)

    [POJ 1201] Intervals(差分约束系统) 11 1716的升级版 把原本固定的边权改为不固定. Intervals Time Limit: 2000MS   Memory Limit: ...

  8. POJ 3190 Stall Reservations贪心

    POJ 3190 Stall Reservations贪心 Description Oh those picky N (1 <= N <= 50,000) cows! They are s ...

  9. 【38.24%】【POJ 1201】Intervals

    Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25902 Accepted: 9905 Description You are ...

随机推荐

  1. Python 调用shell

    第一种,os.system("The command you want"). 这个调用相当直接,且是同步进行的,程序需要阻塞并等待返回.返回值是依赖于系统的,直接返回系统的调用返回 ...

  2. orm2

    数据库连接 var orm = require("orm"); orm.connect("mysql://username:password@host/database& ...

  3. YARN的capacity调度器主要配置分析

    yarn中一个基本的调度单元是队列. yarn的内置调度器: 1.FIFO先进先出,一个的简单调度器,适合低负载集群.2.Capacity调度器,给不同队列(即用户或用户组)分配一个预期最小容量,在每 ...

  4. python爬虫---python3.5---eclipse

    解析中文会出现\xbe\c8\90\hd........ 这个和你的编码选择有关.如果是解析成html,则需 fout = open('output.html', 'w',encoding='utf- ...

  5. linux看代码方法和建议

    http://blog.csdn.net/lxl584685501/article/details/46803077

  6. PyQt5+python3+pycharm开发环境配置

    1.下载PyQt https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.6/PyQt5-5.6-gpl-Py3.5-Qt5.6.0-x32- ...

  7. [HMLY]2.CocoaPods详解----进阶

    作者:wangzz 原文地址:http://blog.csdn.net/wzzvictory/article/details/19178709 转载请注明出处   一.podfile.lock文件   ...

  8. NYOJ 299

    (前言:这是一道关于矩阵快速幂的问题,介绍矩阵快速幂之前,首先看"快速幂"问题. 在前面的博客里有记录到快速幂取模算法,不过总体的思想总是和取模运算混淆在一起,而忽略了" ...

  9. Chapter 3 Phenomenon——1

    When I opened my eyes in the morning, something was different. 这天早上当我睁开眼睛的时候,一些事变得不同了. It was the li ...

  10. Java 并发 线程属性

    Java 并发 线程属性 @author ixenos 线程优先级 1.每当线程调度器有机会选择新线程时,首先选择具有较高优先级的线程 2.默认情况下,一个线程继承它的父线程的优先级 当在一个运行的线 ...