POJ1201 Intervals(差分约束)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 28416 | Accepted: 10966 |
Description
Write a program that:
reads the number of intervals, their end points and integers c1, ..., cn from the standard input,
computes the minimal size of a set Z of integers which has at least ci common elements with interval [ai, bi], for each i=1,2,...,n,
writes the answer to the standard output.
Input
Output
Sample Input
- 5
- 3 7 3
- 8 10 3
- 6 8 1
- 1 3 1
- 10 11 1
Sample Output
- 6
Source
$S\left[ i-1\right] -S\left[ i\right] \geq -1$
- #include<cstdio>
- #include<queue>
- #include<cstring>
- #define INF 1e8+10
- using namespace std;
- const int MAXN=1e6+;
- #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXN,stdin),p1==p2)?EOF:*p1++)
- char buf[MAXN],*p1=buf,*p2=buf;
- inline int read()
- {
- char c=getchar();int x=,f=;
- while(c<''||c>''){if(c=='-')f=-;c=getchar();}
- while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
- return x*f;
- }
- struct node
- {
- int u,v,w,nxt;
- }edge[MAXN];
- int head[MAXN],num=;
- int maxx=-INF,minn=INF;
- int dis[MAXN],vis[MAXN];
- inline void AddEdge(int x,int y,int z)
- {
- edge[num].u=x;
- edge[num].v=y;
- edge[num].w=z;
- edge[num].nxt=head[x];
- head[x]=num++;
- }
- int SPFA()
- {
- queue<int>q;
- memset(dis,-0xf,sizeof(dis));
- dis[minn]=;q.push(minn);
- while(q.size()!=)
- {
- int p=q.front();q.pop();
- vis[p]=;
- for(int i=head[p];i!=-;i=edge[i].nxt)
- {
- if(dis[edge[i].v]<dis[p]+edge[i].w)
- {
- dis[edge[i].v]=dis[p]+edge[i].w;
- if(vis[edge[i].v]==)
- vis[edge[i].v]=,q.push(edge[i].v);
- }
- }
- }
- printf("%d",dis[maxx]);
- }
- int main()
- {
- #ifdef WIN32
- freopen("a.in","r",stdin);
- #else
- #endif
- memset(head,-,sizeof(head));
- int N=read();
- for(int i=;i<=N;i++)
- {
- int x=read(),y=read(),z=read();
- AddEdge(x,y+,z);
- maxx=max(y+,maxx);
- minn=min(x,minn);
- }
- for(int i=minn;i<=maxx-;i++)
- {
- AddEdge(i+,i,-);
- AddEdge(i,i+,);
- }
- SPFA();
- return ;
- }
POJ1201 Intervals(差分约束)的更多相关文章
- poj1201 Intervals——差分约束
题目:http://poj.org/problem?id=1201 差分约束裸题: 设 s[i] 表示到 i 选了数的个数前缀和: 根据题意,可以建立以下三个限制关系: s[bi] >= s[a ...
- hdu 1384 Intervals (差分约束)
Intervals Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- poj 1716 Integer Intervals (差分约束 或 贪心)
Integer Intervals Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12192 Accepted: 514 ...
- zoj 1508 Intervals (差分约束)
Intervals Time Limit: 10 Seconds Memory Limit: 32768 KB You are given n closed, integer interva ...
- poj 1201 Intervals(差分约束)
题目:http://poj.org/problem?id=1201 题意:给定n组数据,每组有ai,bi,ci,要求在区间[ai,bi]内至少找ci个数, 并使得找的数字组成的数组Z的长度最小. #i ...
- poj 1201 Intervals——差分约束裸题
题目:http://poj.org/problem?id=1201 差分约束裸套路:前缀和 本题可以不把源点向每个点连一条0的边,可以直接把0点作为源点.这样会快许多! 可能是因为 i-1 向 i 都 ...
- POJ1201基础差分约束
题意: 有一条直线,直线上做多有50000个点,然后给你组关系 a b c表明a-b之间最少有c个点,问直线上最少多少个点. 思路: a-b最少有c个点可以想象a到b+1的距 ...
- poj1201/zoj1508/hdu1384 Intervals(差分约束)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Intervals Time Limit: 10 Seconds Mem ...
- POJ1201 Intervals差分约束系统(最短路)
Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p ...
随机推荐
- less编译工具——koala使用介绍
1:使用koala编译软件 官网:http://koala-app.com/index-zh.html (目前官网点击下载没有反应,有人说可能是网络问题,但真正的原因是需要FQ才能下载了) 百度 ...
- 315道python面试题(参考答案)
第一部分 Python基础篇 1:为什么学习Python 家里有在这个IT圈子里面,也想让我接触这个圈子,然后给我建议学的Python, 然后自己通过百度和向有学过Python的同学了解了Python ...
- Java异常处理 10 个最佳实践
异常处理是Java 开发中的一个重要部分.它是关乎每个应用的一个非功能性需求,是为了处理任何错误状况,比如资源不可访问,非法输入,空输入等等.Java提供了几个异常处理特性,以try,catch 和 ...
- python元组和字典的简单学习
元组(tuple) 用圆括号()标识,定义元组后,元组元素不可修改.如果想修改元组只能重新定义元组. 因为元组不可更改,所以也没有增删改等用法,主要语法就是访问元组元素,遍历元组. 访问元组元素: t ...
- mysql 开发基础系列12 选择合适的数据类型(上)
一. char 与varchar比较 在上图的最后一行的值只适用在"非严格模式",关于严格模式后面讲到.在“开发基础系列4“ 中讲到CHAR 列删除了尾部的空格.由于char是固定 ...
- RocketMQ事务消息实现分析
这周RocketMQ发布了4.3.0版本,New Feature中最受关注的一点就是支持了事务消息: 今天花了点时间看了下具体的实现内容,下面是简单的总结. RocketMQ事务消息概要 通过冯嘉发布 ...
- Web中的积累:外观模式 Facade
摘要: 原创出处: http://www.cnblogs.com/Alandre/ 泥沙砖瓦浆木匠 希望转载,保留摘要,谢谢! 壹 前言 目测好久没写文章了,距离上一篇文章也有二十多天.我是怎么了?哈 ...
- nohup & expect & netstat学习
1.nohup 用途:不挂断地运行命令,通常加上‘&’命令,& 放在命令后面表示设置此进程为后台进程.分为两种情况,如下: 在不使用密码的情况下使用nohup,只需按如下形式即可: n ...
- Windows编程之模块遍历(C++实现)
Windows编程之模块遍历 PS: 主要扣代码使用,直接滑动到最下面使用. 遍历模块需要几个API,和一个结构体 1.创建进程快照 2.遍历首次模块 3.继续下次遍历 4.模块信息结构体 API 分 ...
- PHP接口的思考
其中就有一个SPL(标准PHP库)的尝试,SPL中实现一些接口,其中最主要的就是Iterator迭代器接口,通过实现这个接口,就能使对象能够用于foreach结构,从而在使用形式上比较统一.比如SPL ...