(~ ̄▽ ̄)~*

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

    安装说明 安装环境:CentOS-6.3 安装方式:源码安装  软件:apache-tomcat-7.0.29.tar.gz 下载地址:http://tomcat.apache.org/downloa ...

  2. 利用Hibernate监听器实现用户操作日志

    网上搜索发现,实现用户操作日志的方式有:自定义注解方式.Hibernate拦截器方式.Hibernate监听器方式等. 1.自定义注解方式较为麻烦,需要进行操作记录的方法均需要添加注解,但是相对的操作 ...

  3. NoSQL数据建模技术

    原文来自“NoSQL Data Modeling Techniques”,由酷壳网陈皓编译<NoSQL数据建模技术>.这篇文章看完之后,你可能会对NoSQL的数据结构会有些感觉.我的感觉是 ...

  4. Intellj idea 安装JUnit

    1.file-Settings-Plugins-Browse repositories-HTTP Proxy Settings将No proxy改成Auto-detect proxy settings ...

  5. mybatis学习笔记四(动态sql)

    直接贴图,注解在代码上,其他的配置文件在学习一中就不贴了 1 数据库 2 实体类 package com.home.entity; /** * 此类是: 用户实体类 * @author hpc * @ ...

  6. Linux下制作静(动)态库

    关键命令: 动态库制作命令 gcc xxx.c -fPIC -shared -o libxxx.so 静态库制作命令 gcc -c xxx.c ar crv libxxx.a xxx.o 例: //h ...

  7. Unity3D脚本使用:Time

    1.Time 使用方式 使用效果 2.yield 延迟执行    嵌套延迟   

  8. AndroidStudio0.5.2 BUG 导致 menu 菜单键崩溃

    郁闷了半天,今天发现一点击手机 menu 键应用就崩溃了,记得之前都是好好的,调试了半天代码还是搞不定,于是网上google了一番,发现仅国外有一两篇文章有提到类似问题,据说是 0.5.2 版本的 B ...

  9. VS2012及以上版本 程序打包部署详解

    引用:  http://blog.csdn.net/zhang_xinxiu/article/details/9099757 程序编写测试完成后接下来我们要做的是打包部署程序,但VS2012让人心痛的 ...

  10. python绝技 — 用Scapy解析TTL字段的值

    #!/usr/bin/env python #--*--coding=utf-8--*-- #打印收到的数据包的源IP和TTL值 from scapy.all import * def testTTL ...