Bzoj 1027 [JSOI2007] Alloy

Source: Internet
Author: User

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

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. 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 proportion of Fe-al-Sn in a user-required alloy.

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 Output5HINT Source

The puzzle: Oh, God, I won't.

Converted to two-dimensional problems, the third dimension can be determined by the first two dimensions, so you can not tube.

Considering the proportions, you can yy the slope of God horse ... Then the two kinds of raw materials can be paired with the product must be at two points on the line.

"translates to a minimum of one point in M, so that it completely contains the N points. "

Then it becomes the Floyd minimum ring ... I've seen the wood.

You can not write a look, I still fill Floyd ...

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