poj1716
来源:互联网 发布:windows10 配置mysql 编辑:程序博客网 时间:2024/06/05 14:42
大致题意:
给出数轴上的n个区间,每个区间都是连续的int区间。
现在要在数轴上任意取一堆元素,构成一个元素集合V
要求每个区间和元素集合V的交集至少有两个不同的元素
求集合V最小的元素个数。
题解
差分约束+spfa跑最大流
#include"queue"#include"cstdio"#include"cctype"#include"cstring"#include"iostream"#include"algorithm"#define M 200000using namespace std;int n , m;int ind[M] , e[M] , nex[M] , dis[M] , vis[M] , lon[M] , tot , e_;int ma(int a , int b){return a > b ? a : b;}inline int read(){ int lwd = 0 , pos = 1; static char ysy; for(;!isdigit(ysy) && ysy != '-';ysy = getchar()); if(ysy == '-')pos = -1 , ysy = '0'; for(; isdigit(ysy);ysy = getchar()) lwd = lwd * 10 + ysy - '0'; return lwd * pos;}inline void add(int a , int b , int c){ nex[++tot] = ind[a]; e[ind[a] = tot] = b; lon[tot] = c;}void spfa(){ memset(dis,-100,sizeof dis); queue <int>qu; dis[0] = 0; qu.push(0); while(!qu.empty()){ int v = qu.front(); qu.pop(); vis[v] = 0; for(int i = ind[v] ; i ; i = nex[i]){ if(dis[e[i]] < dis[v] + lon[i]){ dis[e[i]] = dis[v] + lon[i]; if(!vis[e[i]]){ qu.push(e[i]); vis[e[i]] = 1; } } } }}int main(){ n = read(); for(int i = 1 ; i <= n ; i++){ int a, b; //scanf("%d%d",&a,&b); a = read() , b = read(); add(a , b+1 , 2); e_ = ma(e_ , b+1); } for(int i = 0 ; i < e_;i++){ add(i , i+1 , 0); add(i+1 , i ,-1); } spfa(); printf("%d",dis[e_]); return 0;}
阅读全文
0 0
- poj1716
- poj1716
- poj1716
- poj1716 Integer Intervals
- poj1716 Integer Intervals
- poj1716 - Integer Intervals
- 1poj1716(贪心)
- poj1716 Integer Intervals
- POJ1716 Integer Intervals
- 整数区间(poj1716)
- poj1716 Integer Intervals 贪心
- 【poj1716】 Integer Intervals
- poj1716 Integer Intervals
- poj1716 差分约束系统
- poj1716-差分约束+spfa
- poj1716 Integer Intervals(贪心)
- poj1716 Integer Intervals(贪心)
- POJ1716 Integer Intervals(区间选点)
- MFC的计时器Timer
- Android生成Jar包并混淆
- VLC学习(2) VLC架构及流程分析
- 解题报告:J.膜一下将带给你好运(欧拉函数) “盛大游戏杯”第15届上海大学程序设计联赛夏季赛
- Spring Boot Externalized Configuration
- poj1716
- 2017西安交大ACM小学期 神器插座 KMP匹配
- java方法-----猜字母案例
- “我祝你不幸并痛苦”,首席大法官说了番狠话却被追捧刷屏
- 利用linux的df和du命令查看文件和目录的内存占用
- Java加载类(Class)文件过程
- iOS App 唤醒另一个App
- NP完全问题 8.12
- spring boot security mybitis