POJ1201 Intervals
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
正解:SPFA+差分约束系统
解题报告:
大致题意是给定一些要求,比如说,1到7之间至少有5个数,然后条件需要全部满足,问
这几天刷了几道差分约束系统+SPFA的题目,现在向总给的题目清单里面就只剩下一道半平面交没做了。夏令营回来有时间再切了吧。
这道题也没什么好说的,只不过是根据大于号建图,跑最长路就可以了。
唯一要注意的是因为是前缀和建图,需要把这个序列依次连边,比如说1连2连3这么一直连接下去。
- //It is made by jump~
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- #include <cstdio>
- #include <cmath>
- #include <algorithm>
- #include <ctime>
- #include <vector>
- #include <queue>
- #include <map>
- #ifdef WIN32
- #define OT "%I64d"
- #else
- #define OT "%lld"
- #endif
- using namespace std;
- typedef long long LL;
- const int inf = (<<);
- const int MAXN = ;
- const int MAXM = ;
- int n;
- int first[MAXN],next[MAXM],to[MAXM],w[MAXM];
- int dis[MAXN];
- bool pd[MAXN];
- int ecnt;
- int Min,Max;
- int ans;
- queue<int>Q;
- inline int getint()
- {
- int w=,q=;
- char c=getchar();
- while((c<'' || c>'') && c!='-') c=getchar();
- if (c=='-') q=, c=getchar();
- while (c>='' && c<='') w=w*+c-'', c=getchar();
- return q ? -w : w;
- }
- inline void Init(){
- ecnt=; memset(first,,sizeof(first));
- Max=; Min=inf;
- while(!Q.empty()) Q.pop();
- ans=;
- }
- inline void link(int x,int y,int z){
- next[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y; w[ecnt]=z;
- }
- inline void spfa(){
- for(int i=;i<=n;i++) dis[i]=-inf;
- Q.push(Min); pd[Min]=; dis[Min]=;
- while(!Q.empty()) {
- int u=Q.front(); Q.pop(); pd[u]=;
- for(int i=first[u];i;i=next[i]) { //最长路
- int v=to[i];
- if(dis[v]<dis[u]+w[i]) {
- dis[v]=dis[u]+w[i];
- if(!pd[v]){
- Q.push(v); pd[v]=;
- }
- }
- }
- }
- ans=dis[Max];
- }
- inline void solve(){
- while(scanf("%d",&n)!=EOF){
- Init();
- int x,y,z;
- for(int i=;i<=n;i++) {
- x=getint()-;y=getint();z=getint();
- link(x,y,z);
- Min=min(Min,x); Max=max(Max,y);
- }
- for(int i=Min;i<Max;i++){//以前缀和为结点
- link(i+,i,-); link(i,i+,);//要使所有点满足s[i+1]-s[i] <= 1 && s[i]-s[i+1] <= 0
- }
- spfa();
- printf("%d",ans);
- }
- }
- int main()
- {
- solve();
- return ;
- }
POJ1201 Intervals的更多相关文章
- POJ1201 Intervals[差分约束系统]
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 26028 Accepted: 9952 Descri ...
- POJ1201 Intervals差分约束系统(最短路)
Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p ...
- POJ1201 Intervals(差分约束)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 10966 Description You ...
- POJ1201 Intervals 【差分约束】
题目链接 POJ1201 题解 差分约束 令\(a[i]\)表示是否选择\(i\),\(s[i]\)表示\(a[i]\)的前缀和 对\(s[i] \quad i \in [-1,50000]\)分别建 ...
- POJ1201 Intervals【差分约束系统】
Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a p ...
- POJ1201 Intervals (差分约束)
You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: ...
- POJ1201 Intervals(差分约束系统)
与ZOJ2770一个建模方式,前缀和当作点. 对于每个区间[a,b]有这么个条件,Sa-Sb-1>=c,然后我就那样连边WA了好几次. 后来偷看数据才想到这题还有两个隐藏的约束条件. 这题前缀和 ...
- poj1201 Intervals【差分约束+SPFA】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4303365.html ---by 墨染之樱花 题目链接:http://poj.org/pr ...
- POJ1201:Intervals(差分约束)
差分约束经典题.设s[i]为前缀和,则有 s[i]-s[i-1]<=1 (i往i-1连-1的边) s[i]>=s[i-1] (i-1往i连0的边) s[b]-s[a-1]>=c (a ...
随机推荐
- 优化mysql主从下的slave延迟问题
一般而言,slave相对master延迟较大,其根本原因就是slave上的复制线程没办法真正做到并发.简单说,在master上是并发模式(以InnoDB引擎为主)完成事务提交的,而在slave上,复制 ...
- 24Mybatis_延迟加载——用association来实现
resultMap可以实现高级映射(使用association.collection实现一对一及一对多映射),association.collection具备延迟加载功能. 需求: 如果查询订单并且关 ...
- 【WPF】WPF中调用Winform
1.添加两个引用:WindowsFormsIntegration.dll(负责整合WPF和Windows).System.Windows.Forms.2.在 XAML文件中添加两个引用(粗体部分): ...
- C语言 读取文件中特定数据
//读取文件数据 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> struct jia ...
- Linux非root用户安装jdk和tomcat
转载自:http://blog.csdn.net/wuyigong111/article/details/17410661,进行部分修改 创建一个用户 sgmm,并在其用户目录里面安装 jdk和tom ...
- php基础19:文件
<?php //1.打开文件的更好的方法是通过 fopen() 函数.此函数为您提供比 readfile() 函数更多的选项. //fopen() 的第一个参数包含被打开的文件名,第二个参数规定 ...
- 关联规则算法(The Apriori algorithm)详解
一.前言 在学习The Apriori algorithm算法时,参考了多篇博客和一篇论文,尽管这些都是很优秀的文章,但是并没有一篇文章详解了算法的整个流程,故整理多篇文章,并加入自己的一些注解,有了 ...
- Opencv step by step - 图像变换
这里举出三个案例: #include <cv.h> #include <highgui.h> void image_smooth(IplImage * image) { cvN ...
- MVC4/5+jquery+bootstrap样式+dataTables+linq+WCF+EF6后台和前台的框架集合!好蛋疼哦!数据库支持MYSQL 和MSSQL,oracle。集成腾讯企业邮箱收邮件同步用户SSO登陆等功能。
花费了我好多心血,才做出来,下个项目准备用这个框架! 大家有没有做这方面的可以交流一下! 花费了我好多心血,才做出来,下个项目准备用这个框架! 大家有没有做这方面的可以交流一下! 花费了我好多心血,才 ...
- linux上svn版本库创建小记
[新建svn仓库] 先创建一个文件夹mkdir /opt/svn/wechat; 然后创建svn版本库 svnadmin create /opt/svn/wechat; [创建用户组权限 ...