[bzoj1027] [JSOI2007] Alloy

Source: Internet
Author: User

From Falldream's blog, without permission, please do not reprint, thank you.

A company processes an alloy consisting of iron, aluminum, and tin. Their work is very simple. First of all, the import of some Fe-al-SN alloy raw materials, different types of
The proportion of Fe, AL and SN in raw materials is different. Then, each raw material is taken out of a certain amount, after melting, mixing, to obtain a new alloy. New alloys of iron and aluminum
The proportion of the tin to the user needs. Now, the user gives the n kinds of alloys they need, and the proportion of Fe-al-sn in each alloy. The company hopes to
To order a minimum variety of raw materials, and use these raw materials to produce all the types of alloys required by the user.

n,m<=500

See this god problem has no clue, had to look at the puzzle.

Since three parameters add up to 1, so we can ignore the third, using the first two dimensions to represent a plane point, two materials can be mixed out of the material is the line between the two points, so the problem is converted to a minimum of points, so that the convex hull of these points can cover the convex hull of the required material. Specifically, if all the required material points are on the left side of a segment, then the two points are connected to each other, and then Floyd the minimum loop. Complexity of N^3

Pay attention to various special sentences. If all the emphasis is on output 1, if a line covers all the points to determine if it is all on the line, it is output 2. Finally, the answer must be greater than 2.

#include <iostream>#include<cstring>#include<cstdio>#defineINF 1000000000#defineMN 500#defineEPS 1e-8using namespaceStd;inlineintRead () {intx =0, F =1;CharCH =GetChar ();  while(Ch <'0'|| CH >'9'){if(ch = ='-') F =-1; CH =GetChar ();}  while(Ch >='0'&& CH <='9') {x = x *Ten+ CH-'0'; ch =GetChar ();} returnX *F;} intf[mn+5][mn+5];intN,m;Doublexmn=inf,xmx=-inf,ymn=inf,ymx=-INF;structp{Doublex, y; P (Doublex=0,Doubley=0): X (x), Y (y) {}Double operator^ (P b) {returnx*b.y-y*b.x;} Poperator-(P b) {returnP (x-b.x,y-b.y);}} P[mn+5],q[mn+5]; BOOLCheckDoubleX1,DoubleX2,DoubleX3,Doublex4) {    if(x1>x2) Swap (X1,X2); returnx1<=x3&&x4<=x2;} intSolveintXinty) {    intnum1=0, num2=0;  for(intI=1; i<=m;i++)    {        DoubleCrs= (P[y]-p[x]) ^ (q[i]-p[x]); if(crs<-eps) num2++; if(crs>eps) num1++; }    if(!num1&&!num2&&check (P[X].X,P[Y].X,XMN,XMX) &&check (P[X].Y,P[Y].Y,YMN,YMX))return-1; if(NUM1*NUM2)return 0; if(NUM1)return 2; if(num2)return 1; return 3;} BOOLSpecial () { for(intI=2; i<=n;i++)        if(p[i].x!=p[1].x| | p[i].y!=p[1].Y)return 0;  for(intI=1; i<=m;i++)        if(q[i].x!=p[1].x| | q[i].y!=p[1].Y)return 0; return 1;} intMain () {n=read (); M=read ();DoubleD;  for(intI=1; i<=n;i++) scanf ("%LF%LF%LF",&p[i].x,&p[i].y,&d);  for(intI=1; i<=m;i++) {scanf ("%LF%LF%LF",&q[i].x,&q[i].y,&d); Xmn=min (xmn,q[i].x); xmx=Max (xmx,q[i].x); Ymn=min (YMN,Q[I].Y); ymx=Max (YMX,Q[I].Y); }    if(Special ())return 0*puts ("1"); Memset (F, the,sizeof(f));  for(intI=1; i<n;i++)         for(intj=i+1; j<=n;j++)        {            intres=solve (I,J); if(res==-1)return 0*puts ("2"); if(res&1) f[i][j]=1; if(res&2) f[j][i]=1; }     for(intk=1; k<=n;k++)         for(intI=1; i<=n;i++)             if(f[i][k]<=INF) for(intj=1; j<=n;j++) F[i][j]=min (f[i][j],f[i][k]+F[k][j]); intminn=INF;  for(intI=1; i<=n;i++) minn=min (minn,f[i][i]); if(minn>2&&minn<inf) printf ("%d\n", Minn);ElsePuts"-1"); return 0;}

[bzoj1027] [JSOI2007] Alloy

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.