[JSOI2007] Alloy

Source: Internet
Author: User

Description

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.

Input

The first line is two integers m and n (M, n≤500), which represent the number of raw materials and the number of alloy species required by the user, respectively. 2nd to M + 1 lines, three per row
A, B, C (A, B, c≥0 and A + b + c = 1), respectively, representing the proportion of Fe-al-Sn in a raw material. Section M + 2 to M +
n + 1 lines, three reals per row, A, B, C (A, B, c≥0 and A + b + c = 1), respectively, in a user-required alloy
The proportion of the total.

Output

An integer that represents the minimum number of raw material species required. If there is no solution, the output –1.

Sample Input10 10
0.1 0.2 0.7
0.2 0.3 0.5
0.3 0.4 0.3
0.4 0.5 0.1
0.5 0.1 0.4
0.6 0.2 0.2
0.7 0.3 0
0.8 0.1 0.1
0.9 0.1 0
1 0 0
0.1 0.2 0.7
0.2 0.3 0.5
0.3 0.4 0.3
0.4 0.5 0.1
0.5 0.1 0.4
0.6 0.2 0.2
0.7 0.3 0
0.8 0.1 0.1
0.9 0.1 0
1 0 0
Sample Output5The third dimension can be determined by the first two dimensions, so you can ignoresuch a material has only two properties, turning it into a coordinatefor two materials, the alloy they can synthesize is the point on the line segment at the end of the two pointif the convex hull of the n material point consists of all the alloy points, it will be feasible, because an alloy point can be regarded as a point on a segment consisting of two points on the convex edge.If there is an alloy point on the left of A[i]->a[j], there is no alloy point on the rightso build a (i,j) right side of 1If there is no point on the left, build a (j,i) edgeif it's all in a straight line, it's not built,so the transformation for the Floyd to find the smallest ringall points are to be awarded (possibly Output 1), and all points on the segment (i.e. output 2)
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6 using namespacestd;7 structNode8 {9   Doublex, y;Ten}a[501],b[501]; One Doubleeps=1e-8; A intdis[501][501],n,m,inf,ans; -Nodeoperator-(Node U,node v) - { the   return(Node) {u.x-v.x,u.y-v.y}; - } - Double operator*(Node U,node v) - { +   returnu.x*v.y-v.x*u.y; - } + BOOLSPJ () A{inti,j; at    for(i=1; i<=n;i++) -     if(Fabs (a[i].x-a[1].x) >eps| | Fabs (a[i].y-a[1].Y) >eps)return 0; -    for(i=1; i<=m;i++) -     if(Fabs (b[i].x-a[1].x) >eps| | Fabs (b[i].y-a[1].Y) >eps)return 0; -cout<<1<<Endl; -   return 1; in } - BOOLPD (Node x,node y) to{inti,j; +   if(x.x>y.x) Swap (x, y); -    for(i=1; i<=m;i++) the     { *       if(b[i].x<x.x| | b[i].x>y.x)return 0; $     }Panax Notoginseng   if(x.y>y.y) Swap (x, y); -    for(i=1; i<=m;i++) the     { +       if(b[i].y<x.y| | B[I].Y&GT;Y.Y)return 0; A     } the   return 1; + } - intjudge (Node X,node y) ${inti; $   intc1=0, c2=0; -    for(i=1; i<=m;i++) -     { the       Doublet= (y-x) * (b[i]-x); -       if(t>eps) c1++;Wuyi       if(t<-eps) c2++; the       if(C1*C2)return 0; -     } Wu   if(!C1&AMP;&AMP;!C2&AMP;&AMP;PD (x, y))return-1; -   if(C1)return 1; About   if(C2)return 2; $   return 3; - } - intMain () -{inti,j,k; A   DoubleD; +Cin>>n>>m; the    for(i=1; i<=n;i++) -     { $scanf"%LF%LF%LF",&a[i].x,&a[i].y,&d); the     } the    for(i=1; i<=m;i++) the     { thescanf"%LF%LF%LF",&b[i].x,&b[i].y,&d); -     } in   if(SPJ ())return 0; thememset (DIS,127/3,sizeof(DIS)); theinf=dis[0][0]; About    for(i=1; i<=n;i++) the     { the        for(j=i+1; j<=n;j++) the     { +       intp=judge (A[i],a[j]); -       if(p==-1) the         {Bayicout<<2<<Endl; the           return 0; the         } -       if(p==1) dis[i][j]=1; -       Else if(p==2) dis[j][i]=1; the     } the     } the    for(k=1; k<=n;k++) the     { -        for(i=1; i<=n;i++) the     if(dis[i][k]!=inf) the     { the        for(j=1; j<=n;j++)94         if(dis[i][k]+dis[k][j]<Dis[i][j]) thedis[i][j]=dis[i][k]+Dis[k][j]; the     } the     }98ans=inf; About    for(i=1; i<=n;i++) -ans=min (ans,dis[i][i]);101   if(Ans==inf) cout<<"-1";102   Elseprintf"%d\n", ans);103}

[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.