(~ ̄▽ ̄)~*

//求一个集合,这个集合与任意一个区间的交集,需至少有两个数字
//贪心过程:按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. Qt-剪切板

    ClipBoard 存在的意义 进程间数据共享. 方式 Drag And Drop: clipBoard的拖曳方式 app's ClipBoard 缺点 没有权限管理 在Model View中实现Dr ...

  2. Android高级开发专题晋升班

    Android高级开发专题晋升班 适用人群:1-3年以上经验的开发者丨学员平均薪酬20K/月

  3. OBIEE接受外部参数

    样例: http://192.168.0.99/analytics/saw.dll?Go&Path=/shared/goxiangyibiaopan/SBDW_GSYDL_ZZT&Ac ...

  4. NGINX----源码阅读----init配置脚本

    /auto/init init脚本负责初始化各种目录环境变量值. 1.make文件.源文件.头文件.配置头文件路径变量初始化. NGX_MAKEFILE=$NGX_OBJS/Makefile NGX_ ...

  5. MyBatis 学习-动态 SQL 篇

    MyBatis 为我们提供了如下几个动态 SQL 元素: if choose foreach where/set trim 一.IF 元素 <select id="selectProj ...

  6. Alamofire4.0 在 CocoaPods无法更新的问题

    因为淘宝镜像已经不能使用,使用新的镜像升级ruby到最新状态 platform :ios, '9.0'use_frameworks! target '输入你的工程名字' do pod 'Alamofi ...

  7. 关于js的那些事儿

    什么是JS? JavaScript是一种基于对象(Object)和事件驱动(Event Driven),并具有相对安全性的客户端脚本语言.同时也是一种广泛用户客户端Web开发的脚本语言,常用来给HTM ...

  8. magento表单的导出

    1.Grid.php中得有:   $this->addExportType('*/*/exportXml' , Mage::helper('hpusernetwork' )->__('Ex ...

  9. Java 内部类 this

    内部类访问外部类的一个例子: public class Abc { private class Bc { public void print() { System.out.println(Abc.th ...

  10. CF Round #355 Div.2

    http://codeforces.com/contest/677 B. Vanya and Food Processor 题意:有一个食物加工器,每次能加工不超过h高度的土豆,且每秒加工至多k高度的 ...