POJ 1201 Intervals

Source: Internet
Author: User

Test instructions: There are n intervals [a, b], and each interval has a value of C. Find the elements in a set so that each interval has at least C elements in this set, asking the smallest set size.

Idea: Set d[i+1] means 0 to i how many number in this set, obviously for each interval, d[b+1]-d[a]>=c, in order to meet the requirements of the topic. But this does not make all the collections connected. Continue to excavate the condition, according to d[] 's definition can get, 0<=d[i+1]-d[i]<=1.

Thus three inequalities can be derived:

D[b+1]-d[a]>=c

D[i+1]-d[i]>=0

D[i]-d[i+1]>=-1

It is obvious that this is a differential constraint system, but it is the longest road to be obtained. The longest way to find the minimum to maximum value after building a map is the answer.

1#include <stdio.h>2#include <string.h>3 Const intn=50000+111, m=200000, inf=0x3f3f3f3f;4 structnode{5     intV,w,next;6 }e[m];7 intHead[n],p[n],d[n];8 intq[m<<2],l,r,js;9 voidAddintUintVintW)Ten { Onee[js].v=v,e[js].w=W; Ae[js].next=head[u],head[u]=js++; - } - voidSPFA (intSintt) the { -L=r=0;intu,v,w,i; -      for(i=s;i<=t;i++) d[i]=-INF; -Memset (P,0,sizeof(P)); +q[++r]=s;d[s]=0; -      while(l<R) +     { Ap[u=q[++l]]=0; at          for(i=head[u];i!=-1; i=e[i].next) -         { -v=e[i].v,w=E[I].W; -             if(d[v]<d[u]+W) -             { -d[v]=d[u]+W; in                 if(!P[v]) -                 { top[v]=1; +q[++r]=v; -                 } the             } *         } $     }Panax Notoginsengprintf"%d\n", D[t]); - } the intMain () + { A     intN,u,v,w,i,ma,mi; the      while(SCANF ("%d", &n)! =EOF) +     { -memset (head,-1,sizeof(head)); $Js=ma=0; mi=INF; $          while(n--) -         { -scanf"%d%d%d",&u,&v,&W); theAdd (u,v+1, W); -             if(U&LT;MI) mi=u;Wuyi             if(v+1&GT;MA) ma=v+1; the         } -          for(i=mi;i<ma;i++) Wu         { -Add (i,i+1,0); AboutAdd (i+1, i,-1); $         } - SPFA (mi,ma); -     } -     return 0; A}

POJ 1201 Intervals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.