title:http://acm.hdu.edu.cn/showproblem.php?pid=1384
Test instructions: N indicates that there are several sets of test data, A, B, C-->[a, b] for a closed interval, and C for the number of points in the closed interval that meet the criteria. Find the minimum number of points that the group needs to meet n conditions.
The main problem is to find the constraint equation.
The constraint equation has two: (Have to spit a groove, true nm bad think), set S[i] for 0 ~ i in set Z satisfies the number of points, set Z for the final set;
1, in the set [A, b], s[a+1]-s[b] >= c. (Note the length of the set, the longest way to solve the problem-----> Pay attention to the direction of construction).
2. 1 >= s[i+1]-s[i] >= 0; (This condition is not very obvious, Nm-.-\). Convert---> s[i] >= s[i-1]-1 && s[i + 1] >= 0 + s[i] direction!!! ) yuan point = imPoRtant.
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#defineMin (A, b) a<b? A:b
#defineMax (A, b) a>b? A:b
usingnamespaceStd
ConstintINF =0x3f3f3f3f;
intdis[50010], vis[50010], Min, Max;
structEdge
{
int from, to, Val, next;
} edge[50005*3];
inthead[50005], CNT;
voidADD (intAintBintC
{
Edge E = {A, B, C, head[a]};
EDGE[CNT] = E;
Head[a] = cnt++;
}
voidSPFA ()
{
for(inti = Min; I <= Max; i++)
Dis[i] =-inf;
Dis[min] =0; The longest road;
queue<int> Q;
Q.push (Min);
while(! Q.empty ())
{
intU = Q.front (); Q.pop ();
Vis[u] =0;
for(inti = Head[u]; I! =-1; i = edge[i].next)
{
intv = edge[i].to;
if(Dis[v] < Dis[u] + edge[i].val)
{
DIS[V] = Dis[u] + edge[i].val;
if(!vis[v])
{
VIS[V] =1;
Q.push (v);
}
}
}
}
printf"%d\n", Dis[max]);
}
intMain ()
{
intN
while(~SCANF ("%d", &n))
{
Min = INF; Max =-inf; CNT =0;
memset (Vis,0,sizeof(VIS));
Memset (Edge,0,sizeof(Edge));
Memset (Head,-1,sizeof(head));
for(inti =0; i < N; i++)
{
intU, V, W;
scanf" %d%d%d", &u, &v, &w);
ADD (U, v+1, W); //s[a+1]-s[b] >= C;
min = min (min, u); Find the approximate interval;
max = max (max, v+1);
}
for(inti = Min; i < Max; i++)
{
ADD (i, i+1,0); Two-way edge, the weight value is different.1 >= s[i+1]-s[i] >= 0--->S[i] >= s[i-1]-1 && s[i + 1] >= 0 + s[i]
ADD (i+1, I,-1);
}
SPFA ();
}
return0; }
Hangzhou electric oj1384--intervals (differential constraint)