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 ...
随机推荐
- Leetcode166. Fraction to Recurring Decimal分数到小数
给定两个整数,分别表示分数的分子 numerator 和分母 denominator,以字符串形式返回小数. 如果小数部分为循环小数,则将循环的部分括在括号内. 示例 1: 输入: numerator ...
- HTML+css 小组件
1.三角 代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <t ...
- CF1097E Egor and an RPG game
最少反链划分数 = 最长链.实现:每次找出所有极大元作为一个反链. 任意长度小于k * (k + 1) / 2的排列都能被划分为不多于k个单调序列.且这是一个紧的上界. 然后这题就可以切了. 题意:给 ...
- 0823NOIP模拟测试赛后总结
考了两场感觉虚了... NOIP模拟测试30 分着考的. 就只有T2的美妙的暴力拿分了,60分rank10,挂了. T1是一道sb题,爆零了十分遗憾. 许多人都掉进了输出格式的坑里,C没大写.少个空格 ...
- 安装vmware和装虚拟机
今日任务 .Linux发行版的选择 .vmware创建一个虚拟机(centos) .安装配置centos7 .xshell配置连接虚拟机(centos) 选择性 pc可以选择 -纯系统 Linux/w ...
- Django项目订单接入支付宝
1.首先下载所需要的包 pip install python-alipay-sdk 2.在视图函数里面引入所需要的类 from alipay import AliPay 3.利用这个类创建一个实例对象 ...
- “Error: Encountered an improper argument”的解决方法
之前遇到过的问题,后来解决后再次遇到又忘记了, 这是keil 的bug 路径只要都是字母就可以了
- uploadify附件上传 传参
首先 在刚加载jsp时就加入上传方法,所以 formDate 中的参数 zFileName是页面刚加载时 exp1的值 ,后来通过js方法赋值不被读过来,如果 你想要获得这个值,可在 调用upload ...
- RaspberryPi(一)
[1]格式化TF卡 // 注意格式 [2]烧录系统 // 烧录完成后不要点弹出的击格式化选项 [3]查找IP.修改静态IP(保持和台式机或笔记本同网段) arp -a //物理地址以B8开头 //或者 ...
- 《数据结构与算法分析——C语言描述》ADT实现(NO.05) : 散列(Hash)
散列(Hash)是一种以常数复杂度实现查找功能的数据结构.它将一个关键词Key,通过某种映射(哈希函数)转化成索引值直接定位到相应位置. 实现散列有两个关键,一是哈希函数的选择,二是冲突的处理. 对于 ...