bzoj4306: Toy Factory

Source: Internet
Author: User

Description in the JIH survey of the map has n cities, by the highway connected to a ring, Jih want to build a toy factory in these cities. Both the city and the highway are numbered 1. N,i Road Connection I-1th City and City I (Highway 1th connects to City N and City 1th), each city demand for toys is WI, the length of each road is di. When Jih built a toy factory in city I, Jih needed to transport the toys to other cities (except of course I city). The cost of transporting toys to City J is l1*l2*wj for the two routes of City No. I to City J, respectively L1 and L2. The total cost of transportation is the sum of the transportation costs of transporting toys to all cities. Jih of course want the total transportation costs least, so he will choose the best city building toy factory, if there are more than the best city, Yue will wait for the probability of choosing one of the construction toy factory. Because Jih's investigation work is not done well, only know 1. WI in city N-1, while wi in City N only knows its value range [A, b], it is assumed that the probability of the value of WI in the real range [A, b] is evenly distributed. Now Jih had to go to the second investigation, so we want to know the probability of building a toy factory in each city.

The first line of input has three positive integer n,a,b. Next N-1 a positive real number for each line, w[1] to w[n-1]. Next N lines A positive real number for each line, d[1] to d[n].

Outputn line, one real number per line, indicating the probability of building a plant in the first city

Sample Input5 1 100
50
25
25
50
1
2
3
2
1Sample Output0.090
0.000
0.000
0.090
0.821HINT

When w[5]<18.75, will build toy factory in 1 or 4th city, when w[5]>18.75, will build toy factory in 5th City,
When w[5]=18.75, the toy factory will be built at 1 or 4 or 5.
100% of the data: n<=100000,a<=b<=10000,w[i]<=10000,d[i]<=10. The cost of each point is expressed in the form of kx+b, and then a convex hull is maintained to find the lowest line in each section, and then the probability of each line being chosen is calculated. Now the bottleneck is finding the B at each point. If the plant is located at the I-1 point l[j],r[j] for the two road lengths of the I-1 and J points, then B[i-1]=σl[j]*r[j]*w[j]Similarly b[i]=σ (L[j]+d[i]) * (R[j]-d[i]) *w[j]To make a difference b[i]-b[i-1]=σw[j]* (R[j]*d[i]-l[j]*d[i]-d[i]*d[i]) =σw[j]*r[j]*d[i]-σw[j]*l[j]*d[i]-σw[j]*d[i]*d[i]Maintenance Σw[j]*r[j]And Σw[j]*l[j]Can. The first storm seeks out the 1th point of B, then O (1) to the other point of the B, the all points of B becomes O (N). Note: There are repeated lines and they want to divide the probabilities. Code
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 #defineMAXN 1000057 #defineEPS 1E-98 #defineINF 1E1009 using namespacestd;Ten intN,FLAG,CNT,SIZ,POS[MAXN]; One DoubleW[MAXN],D[MAXN],DIST[MAXN],TOT,TMP,ANS,T1,T2,T3,VAL[MAXN]; A DoubleA,B,L,R,F[MAXN],P[MAXN]; - structline{ -     Doublek,b; the     intID; - }LINE[MAXN],TL[MAXN]; - BOOLcmp (line X,line y) { -     if(ABS (X.K-Y.K) >eps)returnX.k>Y.K; +     returnx.b<y.b; - } + DoubleCalc (line L1,line L2) {return-(l1.b-l2.b)/(l1.k-l2.k);} A structdata{ at     Doublex; -     intID; - }LIST[MAXN]; - voidsolve () { -memcpy (Tl,line,sizeof(line)); -Sort (tl+1, tl+n+1, CMP); in      for(intI=1, j,t;i<=n;i=j) { -line[++cnt]=tl[i],t=0; to          for(j=i;tl[j].k==tl[i].k;j++)if(tl[j].b==tl[i].b) pos[tl[j].id]=cnt,t++; +          for(j=i;tl[j].k==tl[i].k;j++)if(tl[j].b==tl[i].b) p[tl[j].id]=1.0/T; -     } thelist[siz=1]= (DATA) {-inf,1}; *      for(intI=2; i<=cnt;i++){ $         Doublet=Calc (line[i],line[list[siz].id]);Panax Notoginseng          while(t<list[siz].x) siz--, t=Calc (line[i],line[list[siz].id]); -list[++siz]=(DATA) {t,i}; the     } +List[++siz]= (DATA) {inf,cnt+1}; Al=a,r=b,flag=0; the      for(intI=1; i<=siz&&flag!=2; i++){ +         if(list[i].x>l) { -             if(!flag) flag=1, f[list[i-1].id]= (list[i].x-l)/(Rl); $             Else if(flag==1&AMP;&AMP;LIST[I].X&LT;R) f[list[i-1].id]= (list[i].x-list[i-1].x)/(Rl); $             Else if(list[i].x>=r) f[list[i-1].id]= (r-list[i-1].x)/(r-l), flag=2; -         } -     } the      for(intI=1; i<=n;i++) p[i]=f[pos[i]]*P[i]; -      for(intI=1; i<=n;i++) printf ("%.3lf\n", P[i]);Wuyi } the intMain () { -scanf"%D%LF%LF",&n,&a,&b); Wu      for(intI=1; i<n;i++) scanf ("%LF",&w[i]); -      for(intI=1; i<=n;i++) scanf ("%LF",&d[i]); About      for(intI=1; i<=n;i++) dist[i]=D[i]; $      for(intI=1; i<=n;i++) dist[i]+=dist[i-1]; -tot=Dist[n]; -     if(a==b) { -w[n]=A; At1=w[1]*tot,t3=w[1]; +          for(intI=2; i<=n;i++){ thetmp+=w[i]* (dist[i]-dist[1]) * (tot-dist[i]+dist[1]); -t1+=w[i]* (dist[i]-dist[1]); $t2+=w[i]* (tot-dist[i]+dist[1]); thet3+=W[i]; the         } theval[1]=ans=tmp; the          for(intI=2; i<=n;i++){ -tmp+=t1*d[i]-t2*d[i]-t3*d[i]*D[i]; inans=min (ans,tmp); theval[i]=tmp; thet1+=w[i]*tot,t2-=w[i]*tot; Aboutt1-=t3*d[i],t2+=t3*D[i]; the         } theCnt=0; the          for(intI=1; i<=n;i++)if(ABS (Val[i]-ans) <=eps) cnt++; +          for(intI=1; i<=n;i++)if(ABS (Val[i]-ans) <=eps) printf ("%.3lf\n",1.0/CNT); -         ElsePuts"0.000"); the         return 0;Bayi     } theL=0, r=tot; the      for(intI=1; i<=n;i++) l+=d[i],r-=d[i],line[i].k=l*R; -t1=w[1]*tot,t3=w[1]; -      for(intI=2; i<=n;i++){ thetmp+=w[i]* (dist[i]-dist[1]) * (tot-dist[i]+dist[1]); thet1+=w[i]* (dist[i]-dist[1]); thet2+=w[i]* (tot-dist[i]+dist[1]); thet3+=W[i]; -     } theline[1].b=tmp; the      for(intI=2; i<=n;i++){ thetmp+=t1*d[i]-t2*d[i]-t3*d[i]*D[i];94line[i].b=tmp; thet1+=w[i]*tot,t2-=w[i]*tot; thet1-=t3*d[i],t2+=t3*D[i]; the     }98      for(intI=1; i<=n;i++) line[i].id=i; About solve (); -     return 0;101}

bzoj4306: Toy Factory

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.