Bzoj thousand plan 123:bzoj1027: [JSOI2007] Alloy

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=1027

Because X+y+z=1, so z=1-x-y

The third dimension can be ignored

Consider X, y as a point on a plane

Simplify the problem:

If there are only two materials, then all points on the two-point segment can be synthesized.

Extended to a variety of materials:

If the user points inside the convex hull of the material point, it can be synthesized

So the title is transformed into a minimum loop of material points that can contain all user points

With Floyd

Enumerates every two pairs of material points, if all the user points are on the left side of a segment or on a line segment

Then f[i][j]=1 indicates that there is an edge between I and J

Cross product judgment point on which side of the line

So if you're in a straight line, you're going to have to be on the line.

#include <cmath>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;#defineN 501Const Doubleeps=1e-9;structnode{Doublex, Y, Z;} Metal[n],user[n];intF[n][n];DoubleCross (node A,node b,node p) {Doublexa=b.x-a.x; Doubleya=b.y-a.y; Doublexb=p.x-a.x; Doubleyb=p.y-a.y; returnxa*yb-xb*ya;}DoubleGetdis (node A,node b) {returnsqrt ((a.x-b.x) * (a.x-b.x) + (A.Y-B.Y) * (a.y-b.y));}intMain () {intM,n; scanf ("%d%d",&m,&N);  for(intI=1; i<=m;++i) scanf ("%LF%LF%LF",&metal[i].x,&metal[i].y,&metal[i].z);  for(intI=1; i<=n;++i) scanf ("%LF%LF%LF",&user[i].x,&user[i].y,&user[i].z); Memset (F, the,sizeof(f)); intK; DoubleTmp,dis1,dis2;  for(intI=1; i<=m;++i) { for(intj=1; j<=m;++j) { for(k=1; k<=n;++k) {tmp=Cross (Metal[i],metal[j],user[k]); if(Fabs (TMP) >EPS) {                    if(tmp>0)Continue;  Break; } dis1=Getdis (Metal[i],user[k]); Dis2=Getdis (Metal[i],metal[j]); if(Fabs (TMP) <eps && fabs (dis1-dis2) >eps && Dis1>dis2) Break; }            if(k==n+1) f[i][j]=1; }    }     for(intk=1; k<=m;++k) for(intI=1; i<=m;++i) for(intj=1; j<=m;++j) F[i][j]=min (f[i][k]+F[k][j],f[i][j]); intans=m+1;  for(intI=1; i<=m;++i) ans=min (ans,f[i][i]); if(ans==m+1) ans=-1; printf ("%d", ans);}

1027: [JSOI2007] Alloy time limit:4 Sec Memory limit:162 MB
submit:4407 solved:1327
[Submit] [Status] [Discuss] 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 Output5

Bzoj thousand plan 123: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.