Rokua P2729 feed Blending feeds Ratios

Source: Internet
Author: User

P2729 Feed Blending Feed Ratios

    • by
    • 103 Submit
    • topic provider The user does not exist
    • label Usaco
    • Difficulty popularity / Improve -

Submit a Discussion

Recent discussions

    • No discussion at the moment

Topic background

Farmer John never feeds his cows with the best feed. Feed is made from three ingredients: barley, oats and wheat. He knew the exact proportions of his feed, which he could not buy in the market. He had to buy three other mixed feeds (also made up of three wheat) and mix them to blend his perfect feed.

Title Description

Give three groups of integers representing barley: oats: The proportion of wheat, and find out how to use these three kinds of feed to allocate x:y:z feed.

For example, the ratio of the target feed 3:4:5 and three feeds is given:

1:2:3 3:7:1 2:1:2 You have to program the program to find the minimum amount of these three feeds, and if the target feed cannot be provisioned with these three feeds, the output is "NONE". "Minimum dosage" means that the amount of three feeds (integers) must be minimal.

For the above example, you can use 8 servings of feed 1, 1 servings of feed 2, and 5 servings of feed 3 to get 7 servings of target feeds:

8* (1:2:3) + 1* (3:7:1) + 5* (2:1:2) = (21:28:35) = 7* (3:4:5)

The integer representing the feed ratio and the target feed are all non-negative integers less than 100. An integer representing the number of copies of the various feeds, both less than 100. The proportions of a mixture are not added directly to the proportions of the other mixtures.

Input/output format

Input format:

Line 1: Three integers separated by a space, indicating the target feed

Line 2..4: Each row consists of three integers separated by a space, indicating the proportion of the feed that farmer John buys

Output format:

The output file is to include a row, which either has four integers or "NONE". The first three integers represent the number of copies of three feeds, and the target feeds can be obtained with such ratios. The fourth integer indicates the number of copies of the target feed that were obtained after mixing three kinds of feeds.

Input/Output sample

Input Sample #1 :

3 4 5

1 2 3

3 7 1

2 1 2

Output Sample #1 :

8 1 5 7

Description

The title translation comes from Nocow.

Usaco Training Section 3.2

Analysis: Just start without a clue, but see not more than 100, you can think of this is an enumeration, because there are only three kinds of feed, then enumerate the number of three kinds of feed, and then calculate the proportion, if found a proportion and other proportions are different, then skip, if the demand is 0, you can not directly except, to special treatment.

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;inta[5], b[5], c[5], TA, TB, tc,bi;intMain () {scanf ("%d%d%d", &a[0], &b[0], &c[0]);  for(inti =1; I <=3; i++) scanf ("%d%d%d", &a[i], &b[i], &C[i]);  for(inti =0; I < -; i++)         for(intj =0; J < -; J + +)             for(intK =0; K < -; k++) {Ta= i * a[1] + J * a[2] + K * a[3]; TB= i * b[1] + J * b[2] + K * b[3]; TC= i * c[1] + J * c[2] + K * c[3]; Bi=0; if(a[0] !=0) Bi= ta/a[0]; if(b[0] !=0)            if(BI = =0) Bi= tb/b[0]; Else                if(Bi! = tb/b[0])                    Continue; if(c[0] !=0)            if(BI = =0) Bi= tc/c[0]; Else                if(Bi! = tc/c[0])                    Continue; if(Bi! =0&& a[0] * bi = TA && b[0] * Bi = = TB && c[0] * Bi = =TC) {printf ("%d %d%d%d\n", I, J, K,bi); return 0; }} printf ("none\n"); return 0;}

Rokua P2729 feed Blending feeds Ratios

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.