Hdu 1384(差分约束)
Intervals
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2931 Accepted Submission(s): 1067Problem DescriptionYou are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.Write a program that:
> reads the number of intervals, their endpoints 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
InputThe
first line of the input contains an integer n (1 <= n <= 50 000) -
the number of intervals. The following n lines describe the intervals.
The i+1-th line of the input contains three integers ai, bi and ci
separated by single spaces and such that 0 <= ai <= bi <= 50
000 and 1 <= ci <= bi - ai + 1.Process to the end of file.
OutputThe
output contains exactly one integer equal to the minimal size of set Z
sharing at least ci elements with interval [ai, bi], for each i = 1, 2,
..., n.Sample Input5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1Sample Output6
/*************************************************************************
> File Name: 1384.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年08月26日 星期二 08时59分19秒
> Propose:
************************************************************************/
#include <queue>
#include <cmath>
#include <string>
#include <cstdio>
#include <vector>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
/*Let's fight!!!*/ const int INF = 0x3f3f3f3f;
const int MAX_N = ;
typedef pair<int, int> pii;
vector<pii> G[MAX_N];
int n, d[MAX_N];
bool inq[MAX_N]; void AddEdge(int u, int v, int w) {
G[u].push_back(pii(v, w));
} void spfa(int s) {
queue<int> Q;
memset(d, 0x3f, sizeof(d));
memset(inq, false, sizeof(inq));
d[s] = ;
inq[s] = true;
Q.push(s);
while (!Q.empty()) {
int u = Q.front(); Q.pop(); inq[u] = false;
for (int i = ; i < G[u].size(); i++) {
int v = G[u][i].first, w = G[u][i].second;
if (d[u] + w < d[v]) {
d[v] = d[u] + w;
if (!inq[v]) Q.push(v), inq[v] = true;
}
}
}
} int main(void) {
while (~scanf("%d", &n)) {
for (int i = ; i <= ; i++) G[i].clear();
int s = INF, t = -;
for (int i = ; i < n; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
b++;
s = min(s, a); t = max(t, b);
AddEdge(b, a, -c);
}
for (int i = s; i < t; i++) AddEdge(i, i + , ), AddEdge(i + , i, ); spfa(t); printf("%d\n", -d[s]);
} return ;
}
Hdu 1384(差分约束)的更多相关文章
- hdu 1531(差分约束)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1531 差分约束的题之前也碰到过,刚好最近正在进行图论专题的训练,就拿来做一做. ①:对于差分不等式,a ...
- I - 动物狂想曲 HDU - 6252(差分约束)
I - 动物狂想曲 HDU - 6252 雷格西桑和路易桑是好朋友,在同一家公司工作.他们总是一起乘地铁去上班.他们的路线上有N个地铁站,编号从1到N.1站是他们的家,N站是公司. 有一天,雷格西桑起 ...
- hdu 4598 差分约束
思路:首先就是判断是否有奇环,若存在奇环,则输出No. 然后用差分约束找是否符合条件. 对于e(i,j)属于E,并且假设顶点v[i]为正数,那么v[i]-v[j]>=T--->v[j]-v ...
- HDOJ 1384 差分约束
结题报告合集请戳:http://972169909-qq-com.iteye.com/blog/1185527 /*题意:求符合题意的最小集合的元素个数 题目要求的是求的最短路, 则对于 不等式 f( ...
- hdu 3666(差分约束,手动栈解决超时问题)
THE MATRIX PROBLEM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 1364(差分约束)
King Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12056 Accepted: 4397 Description ...
- hdu 1534(差分约束+spfa求最长路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1534 思路:设s[i]表示工作i的开始时间,v[i]表示需要工作的时间,则完成时间为s[i]+v[i] ...
- hdu 3440 差分约束
看完题目第一遍,感觉很简单.当写完程序跑测试用例的时候,发现第二个总是过不了,然后好好研究了一下测试用例,才知道原来不是程序有问题,而是我的建图方式错了.对于这些无序的点,如果高的在右边,不等式是di ...
- hdu 1534(差分约束)
Schedule Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 3440(差分约束好题)
House Man Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- html--双飞翼布局
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- WPF 免费控件库(2)
最近在逛园子的时候发现的园友分享或提及的WPF控件库~ (1) Bootstrap WPF Style,Bootstrap风格的WPF样式 转:http://www.cnblogs.com/tsliw ...
- l洛谷 NOIP提高组模拟赛 Day2
传送门 ## T1 区间修改+单点查询.差分树状数组. #include<iostream> #include<cstdio> #include<cstring> ...
- java.sql.SQLException
java.sql.SQLException 出错:java.sql.SQLException: com.mchange.v2.c3p0.ComboPooledDataSource[ identityT ...
- Myeclipse 10使用hibernate生成注解(annotation)实体类
以MySQL数据库为例,请在数据库里面建好对应的表. 1.配置数据库链接 打开Myelipse Database Explorer视图 Window-->Open Perspective--&g ...
- rabbit mq 基础流程(转)
从AMQP协议可以看出,MessageQueue.Exchange和Binding构成了AMQP协议的核心,下面我们就围绕这三个主要组件 从应用使用的角度全面的介绍如何利用Rabbit MQ构建 ...
- CAS去掉HTTPS认证
如何去掉HTTPS认证? 说明:默认情况下HTTP也是可以访问CAS SERVER的,但认证,登陆,退出等操作均没有任何的效果.所以必须作出下面的修改 1.进入WEB-INF\spring-confi ...
- Free- Linux必学的60个命令
1.作用 free命令用来显示内存的使用情况,使用权限是所有用户. 2.格式 free [-b|-k|-m] [-o] [-s delay] [-t] [-V] 3.主要参数 -b -k -m:分别以 ...
- Windows API 第21篇 DeleteVolumeMountPoint 删除挂载点
函数原型:BOOL DeleteVolumeMountPoint( LPCTSTR lpszV ...
- windows API 第九篇 _tcslwr _strlwr _wcslwr _mbslwr
将字符串转化为小写Convert a string to lowercase. 函数原型: char *_strlwr( char *string ); //#include ...