AOJ-517 序列(差分约束)
来源:互联网 发布:linux 删除匹配文件名 编辑:程序博客网 时间:2024/06/14 05:05
序列
Time Limit: 1000 ms Case Time Limit: 1000 ms Memory Limit: 64 MB
Judge By Case
Description
有一个整数序列,它的每个数各不相同,我们不知道它的长度是多少(即整数个数),但我们知道在某些区间中至少有多少个整数,用区间(Li,Ri,Ci)来描述,表示这个整数序列中至少有Ci个数来自区间[Li,Ri],给出若干个这样的区间,问这个整数序列的长度最少能为多少?
Input
第一行一个整数N(N<=1000),表示区间个数;
接下来N行,每行三个整数(Li,Ri,Ci)(0<=Li<=Ri<=1000,1<=Ci<=Ri-Li+1),描述一个区间。
接下来N行,每行三个整数(Li,Ri,Ci)(0<=Li<=Ri<=1000,1<=Ci<=Ri-Li+1),描述一个区间。
Output
仅一个数,表示该整数序列的最小长度。
Sample Input
OriginalTransformed44 5 16 10 37 10 35 6 1
Sample Output
OriginalTransformed4
————————————————————集训22.2的分割线————————————————————
前言:终于用正解写出来了。之前是一个姿势相当复杂的贪心A掉的。。
思路:标准的差分约束。只是给出的是点、点上有数值:0或1,要转换成区间,r++就行了。
P.S. 把给出的区间个数当做点的个数WA到死了!低级错误。
代码如下:
/*ID: j.sure.1PROG:LANG: C++*//****************************************/#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <stack>#include <queue>#include <vector>#include <map>#include <string>#include <iostream>#define INF 0x3f3f3f3f#define LL long longusing namespace std;/****************************************/const int N = 1005, M = 5000;int head[N], dis[N], q[N], tot, m;struct Node {int v, w, next;}edge[M];bool inq[N];void add(int u, int v, int w){edge[tot] = (Node){v, w, head[u]};head[u] = tot++;}void spfa(int st){for(int i = 0; i <= N; i++) {dis[i] = -INF;inq[i] = false;}dis[st] = 0;int fron = 0, rear = 1;q[fron] = st;inq[st] = true;while(fron < rear) {int u = q[fron%N]; fron++;inq[u] = false;for(int i = head[u]; i != -1; i = edge[i].next) {int v = edge[i].v;if(dis[v] < dis[u] + edge[i].w) {dis[v] = dis[u] + edge[i].w;if(!inq[v]) {q[rear%N] = v; rear++;inq[v] = true;}}}}}int main(){#ifdef J_Sure//freopen("000.in", "r", stdin);//freopen(".out", "w", stdout);#endiftot = 0;memset(head, -1, sizeof(head));scanf("%d", &m);int l, r, w, R = -1, L = N;for(int i = 0; i < m; i++) {scanf("%d%d%d", &l, &r, &w);r++;R = max(R, r); L = min(L, l);//S[r] - S[l] >= wadd(l, r, w);}for(int i = L+1; i <= R; i++) {//S[i] - S[i-1] <= 1add(i, i-1, -1);//S[i] - S[i-1] >= 0add(i-1, i, 0);}spfa(L);printf("%d\n", dis[R]);return 0;}
0 0
- AOJ-517 序列(差分约束)
- 序列长度 差分约束
- 【差分约束系统】序列长度
- ZOJ1508 (差分约束)
- hdu3592(差分约束)
- BZOJ2330(差分约束)
- poj3169Layout (差分约束)
- poj3169Layout(差分约束)
- poj1275(差分约束)
- Intervals (差分约束)
- 种树(差分约束)
- hdu3666(差分约束)
- 【图-差分约束】 差分约束
- poj 1364 差分约束(笨国王求序列)
- 差分约束——洛谷 P1645 序列
- poj1201 Intervals(差分约束)
- poj 1201 Intervals(差分约束)
- POJ 3195 Candies (差分约束)
- 使用python3.0 编写C/S程序,初识wangpython的网络编程
- Android开发中抽象工厂模式
- Android API包名及包的功能的中文介绍
- Java中HashMap详解
- iOS中多线程原理与runloop介绍
- AOJ-517 序列(差分约束)
- POJ 1182 食物链
- JAVA读写文本文档的例子
- 【iOS runtime】iOS中函数的动态加载
- Delphi获取其它进程窗口句柄的3种方法
- 教你透彻了解红黑树
- 我的IT后十年
- 上下游依赖 这种er关系 在mysql 等关系型数据库中 如何设计 存储
- 扩展系统功能——装饰模式