Bzoj 1822[jsoi2010]frozen Nova Frozen Wave

Source: Internet
Author: User

Network flow + two points.

The N^3 enumeration determines the sprites that each lich can attack, connecting 1 of its edges, each of which has a 1 edge to the sink point.

Two-point answer, modify the source points to each lich's cap, run the maximum flow to see if it equals the number of sprites.

Well, there's nothing wrong with it.

And then mad WA not only. For one night. Most of the night, found on the internet to get the program is a WA ... What else can I say?

It was only then that I should count the distance to the line rather than the line. Keep smiling.

So there is a tag for calculating the geometry of this problem?

Calculate the distance from point to line D, point to line two points distance, short for L, long for R.

The Pythagorean theorem calculates tmp=sqrt (r*r-d*d); if TMP is less than the segment length, then D is returned, otherwise l;

//Twenty#include <cstdio>#include<cstdlib>#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#include<queue>#include<vector>#defineINF 0x3f3f3f3ftypedefLong LongLL;Const intmaxn=299*299*2+5;using namespacestd;intAns,s,t,n,u,v,w,ecnt=1, FIR[MAXN],D[MAXN],CUR[MAXN],C[MAXN],P[MAXN],ED[MAXN];structwuyao{intx,y,r,t;} WY[MAXN],JL[MAXN],SM[MAXN];structEdge {int  from, TO,CAP,FLOW,NXT; Edge () {} Edge (int  from,intTo,intCapintFlowintNXT): from( from), to, Cap (CAP), flow (flow), NXT (NXT) {}}E[MAXN];voidAddintUintVintW) {e[++ecnt]=edge (U,v,w,0, Fir[u]); e[++ecnt]=edge (V,u,0,0, Fir[v]); Fir[u]=ecnt-1; fir[v]=ecnt;} Queue<int>que;voidBFsintSintt) { for(intI=1; i<=n;i++) d[i]=N; D[t]=0;    Que.push (t);  while(!Que.empty ()) {        intx=Que.front (); Que.pop ();  for(intI=fir[x];i;i=e[i].nxt)if(d[e[i].to]==n&&e[i].flow==E[i].cap) {D[e[i].to]=d[x]+1;         Que.push (e[i].to); }    }}intCalintSintt) {intFl=INF;  for(intX=T;X!=S;X=E[P[X]]. from) FL=min (fl,e[p[x]].cap-E[p[x]].flow);  for(intX=T;X!=S;X=E[P[X]]. from) {E[p[x]].flow+=FL; E[P[X]^1].flow-=FL; }    returnFL;}intMaxflow (intSintt) {BFS (s,t); intres=0;  for(intI=1; i<=n;i++) cur[i]=fir[i],c[d[i]]++;  for(intx=s;d[x]<N;) {        if(x==t) {res+=cal (S,t); X=s; }        intok=0;  for(int&i=cur[x];i;i=e[i].nxt)if(d[e[i].to]+1==d[x]&&e[i].cap>E[i].flow) {p[x=e[i].to]=i; OK=1; Break; }        if(!OK) {Cur[x]=FIR[X];intm=N;  for(intI=cur[x];i;i=e[i].nxt)if(e[i].cap>E[i].flow) M=min (m,d[e[i].to]+1); if(! (--c[d[x])) Break; C[D[X]=m]++; if(X!=s) x=e[p[x]]. from; }    }    returnRes;}DoubleDisintXintYintXxintyy) {    returnsqrt ((Double) (X-XX) * (X-XX) + (Double) (y-yy) * (Y-yy));}DoubleDis (intXintYDoubleADoubleBDoubleC) {returnFabs ((a*x+b*y+c))/sqrt (a*a+b*B);} intwys,jls,sms;DoubleYyj;intCheckintti) {     for(intI=1; i<=ecnt;i++) e[i].flow=0;  for(intI=1; i<=wys;i++) {        intfl=ti/wy[i].t+1; E[ed[i]].cap=FL; }    return(Maxflow (s,t) = =JLS);}intMain () {//freopen (". In", "R", stdin); //freopen (". Out", "w", stdout);scanf ("%d%d%d",&wys,&jls,&SMS); N=wys+jls+2; s=n-1; t=N;  for(intI=1; i<=wys;i++) {scanf ("%d%d%d%d",&wy[i].x,&wy[i].y,&wy[i].r,&wy[i].t); Add (S,i,0); ed[i]=ecnt-1; }     for(intI=1; i<=jls;i++) {scanf ("%d%d",&jl[i].x,&jl[i].y); Add (Wys+i,t,1); }     for(intI=1; i<=sms;i++) scanf ("%d%d%d",&sm[i].x,&sm[i].y,&SM[I].R);  for(intI=1; i<=wys;i++) {         for(intj=1; j<=jls;j++)             if((Yyj=dis (WY[I].X,WY[I].Y,JL[J].X,JL[J].Y)) <= (Double) {WY[I].R) {DoubleA= (WY[I].Y-JL[J].Y), b=jl[j].x-wy[i].x,c=wy[i].x*jl[j].y-wy[i].y*jl[j].x; if(i== -) {                   intdebug=1; }                if(!SMS) Add (I,wys+j,1);  for(intk=1; k<=sms;k++) {                    Doubletmp; Doubleddx=Dis (SM[K].X,SM[K].Y,A,B,C); DoubleZb=dis (WY[I].X,WY[I].Y,SM[K].X,SM[K].Y), yb=dis (JL[J].X,JL[J].Y,SM[K].X,SM[K].Y); if(zb<yb) Swap (ZB,YB); DoubleWOC=SQRT (zb*zb-ddx*DDX); TMP=woc<=yyj?Ddx:yb; if(Tmp<= (Double) SM[K].R) Break; if(k==SMS) Add (I,wys+j,1); }            }        }        intL=0, r=4e6+5; if(!check (R)) ans=-1; Else {         while(l<=r) {intMid= (l+r) >>1; if(Check (mid)) ans=mid,r=mid-1; ElseL=mid+1; }} printf ("%d\n", ans); return 0;}
View Code

Surface

Bzoj 1822[jsoi2010]frozen Nova Frozen Wave

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.