poj1201 Intervals

http://poj.org/problem?id=1201

s[i]表示[0..i]中选取了几个整数

则可以得到一些不等式

s[a]-s[b-1]>=c  ([a,b]区间至少要选取c个)

s[i-1]-s[i]>=-1

s[i]-s[i-1]>=0

然后,使用差分约束系统做

Program poj1201;

type cord=record

             ne,po,da:longint;

          end;

var n,le,lr:longint;

    head:array[0..50000]of longint;

    link:array[1..1000000]of cord;

    dis:array[0..50000]of longint;

    h:array[1..1000000]of longint;

    f:array[0..50000]of boolean;

  Procedure add(x,y,z:longint);

   begin

      inc(le);

      with link[le] do

       begin

          po:=y;

          da:=z;

          ne:=head[x];

       end;

      head[x]:=le;

   end;

  Procedure init;

  var i,j,k,l:longint;

   begin

      readln(n);

      for i:=1 to n do

        begin

          readln(j,k,l);

          add(k,j-1,l);

          if k>lr then lr:=k;

        end;

      for i:=0 to lr do

       begin

        add(i,i+1,-1);

        add(i+1,i,0);

       end;

   end;

  Procedure spfa(x:longint);

  var i,j,k,t,w:longint;

   begin

      for i:=0 to lr do dis[i]:=-maxlongint div 10;

      dis[x]:=0;

      h[1]:=x;

      t:=0;w:=1;

      repeat

          inc(t);

          k:=h[t];

          f[k]:=false;

          i:=head[k];

          while i<>0 do

           begin

              if dis[k]+link[i].da>dis[link[i].po] then

                   begin

                       dis[link[i].po]:=dis[k]+link[i].da;

                       if f[link[i].po]=false then

                          begin

                              inc(w);

                              h[w]:=link[i].po;

                              f[link[i].po]:=true;

                          end;

                   end;

              i:=link[i].ne;

           end;

      until t=w;

   end;

  Procedure main;

   begin

       spfa(lr);

       writeln(dis[0]);

   end;

Begin

   assign(input,‘input.in‘);reset(input);

   assign(output,‘output.out‘);rewrite(output);

         init;

         main;

   close(Input);close(output);

End.
时间: 2024-10-11 23:30:58

poj1201 Intervals的相关文章

POJ1201 Intervals 【差分约束系统】

Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21591   Accepted: 8122 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their end po

POJ1201 Intervals查分约束系统(最短路)

Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. 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

POJ1201 Intervals[差分约束系统]

Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 26028   Accepted: 9952 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their end po

POJ1201 Intervals【SPFA】【差分约束】

Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22307 Accepted: 8413 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their end points

POJ1201 Intervals (差分约束)

You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. 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 wh

POJ1201 Intervals 【差分约束】

题目链接 POJ1201 题解 差分约束 令\(a[i]\)表示是否选择\(i\),\(s[i]\)表示\(a[i]\)的前缀和 对\(s[i] \quad i \in [-1,50000]\)分别建立一个点 首先有 \[s[i] - s[i - 1] \ge 0\] \[s[i] - s[i - 1] \le 1\] 然后就是限制条件 \[s[b] - s[a - 1] \ge c\] 然后就没了 用\(spfa\)跑最长路 由于题目保证有解,所以不会存在正环 复杂度上界是\(O(nm)\)的

POJ1201 Intervals【差分约束系统】

Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. 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

poj1201 Intervals【差分约束+SPFA】

转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4303365.html   ---by 墨染之樱花 题目链接:http://poj.org/problem?id=1201 题目描述:给出n个整数三元组(x,y,c),求一个整数集合Z,使其对每个前述三元组都满足在x与y之间(闭区间)的数的个数至少为c,求这个整数集合Z的最少有几个数 思路:利用差分约束系统求解.构造数列a1a2a3...an(其中ai只能为0或1,0表示i不在Z中,1表示i在

poj1201 Intervals,差分约束问题,spfa

题目大意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai,bi]这个区间的整数至少有ci个.如果存在这样的序列,请求出满足题目要求的最短的序列长度是多少.如果不存在则输出 -1. 输入:第一行包括一个整数n,表示区间个数,以下n行每行描述这些区间,第i+1行三个整数ai,bi,ci,由空格隔开,其中0<=ai<=bi<=50000 而且 1<=ci<=bi-ai+1. 输出:一行,输出满足要求的序列的长度的最小值.