[JSOI2007] Alloy

Source: Internet
Author: User

Title Description

A company processes an alloy consisting of iron, aluminum, and tin. Their work is very simple. First import some Fe-al-SN alloy raw materials, different kinds of raw materials in the proportion of Fe-al-Sn. Then, each raw material is taken out of a certain amount, after melting, mixing, to obtain a new alloy. The new alloy's Fe-al-SN specific gravity is required by the user.

Now, the user gives the n kinds of alloys they need, and the proportion of Fe-al-sn in each alloy. The company wants to be able to order a minimum variety of raw materials and use the raw materials to produce all the kinds of alloys the user needs.

Input/output format

Input format:

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, each line three real numbers a, B, C (A, B, c≥0 and A + b + c = 1), respectively, represents the proportion of iron and aluminum in a raw material.

The M + 2 to M +n + 1 lines, three real numbers a, B, C (A, B, c≥0 and A + b + c = 1) per line, respectively, representing the Fe-al-Sn in a user-required alloy

The proportion of the total.

Output format:

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

Input and Output Sample input example # #:
10 100.1 0.2 0.70.2 0.3 0.50.3 0.4 0.30.4 0.5 0.10.5 0.1 0.40.6 0.2 0.20.7 0.3 00.8 0.1 0.10.9 0.1 01 0 00.1 0.2 0.70.2 0. 3 0.50.3 0.4 0.30.4 0.5 0.10.5 0.1 0.40.6 0.2 0.20.7 0.3 00.8 0.1 0.10.9 0.1 01 0 0

Did not resist and went to Kang a computational geometry ...
First of all it is not difficult to find that C is an unused amount,, because a+b+c=1, so c=1-a-b, when a, B are satisfied when C is certainly satisfied.
So just consider a A-B.
And because a vector that can be linearly combined by a number of points in a plane must be within the convex hull of these points in the plane, the title becomes
The minimum number of points allows them to form a convex hull that contains all the demand points.

This is also equivalent to finding a loop starting from one point, so that the demand points are on the left side of the loop and the number of sides on the road is minimized.
So build a picture, run a floyed.

#include <bits/stdc++.h>#definell Long Long#defineMAXN 1005using namespacestd;Const Doubleeps=0.000000001;Doublea,b,c;intN,M,DIS[MAXN][MAXN];structnode{Doublex, y; Nodeoperator-(Constnode& u)Const{        return(node) {x-u.x,y-U.Y}; }}Base[Maxn],user[maxn];inlineintZtDoublex) {    if(Fabs (x) <=eps)return 0; returnX>0?1:-1;} InlineDoublePointmul (node X,node y) {returnx.x*y.x+x.y*y.y;} InlineDoubleXmul (node X,node y) {returnx.x*y.y-y.x*x.y;}intMain () {scanf ("%d%d",&n,&m);  for(intI=1; i<=n+m;i++) {scanf ("%LF%LF%LF",&a,&b,&c); if(i<=n)Base[i]=(node) {A, b}; Elseuser[i-n]=(node) {A, b}; } memset (Dis,0x3f,sizeof(DIS));//for (int i=1;i<=n;i++) dis[i][i]=0;         for(intI=1; i<=n;i++)         for(intj=1; j<=n;j++){            BOOLflag=1; Node Vec=Base[j]-Base[i];  for(intk=1; k<=m;k++){                DoubleX=zt (Xmul (vec,user[k]-Base[i])); if(x<0|| (! X&&zt (Pointmul (user[k]-Base[i],user[k]-Base[j])) >0) ) {flag=0;  Break; }            }                        if(flag) dis[i][j]=1; }        intans=1<< -;  for(intk=1; k<=n;k++)         for(intj=1; j<=n;j++)             for(intI=1; i<=n;i++) Dis[j][i]=min (dis[j][i],dis[j][k]+Dis[k][i]);  for(intI=1; i<=n;i++) ans=min (ans,dis[i][i]); if(Ans>n) puts ("-1"); Elseprintf"%d\n", ans); return 0;}

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