Usaco Feed ratios, solution linear Equation Group, gram law, 0 remainder

Source: Internet
Author: User

C + +, 0 (%) of any number 0, such as 0 5 = 0 instead of 5
Violence enumeration: Because the maximum factor is 100, the maximum calculation of 100 cubic, can be violent enumeration, reference: http:// Www.cppblog.com/Ylemzy/articles/99550.html (This code does not consider 0)
or the law of Lyme: http://wenku.baidu.com/view/ a50e676c1eb91a37f1115c49.html


My Code, using the law of Lyme; Notice that the first few times did not pass, one should pay attention to the use of Clem Law to calculate ans[i] to check getdet (map)% Getdet (DP) = = 0, the quotient is an integer to continue; second, the data source is very cheap, some is not the simplest, the result is negative, so the output before the test

/* Id:wangxin12 Prog:ratios lang:c++/* #include <iostream> #include <fstream> using namespace std;
int d[3];
int dp[3][3];
int map[3][3];
int ans[4];
Ifstream fin ("ratios.in");

Ofstream fout ("Ratios.out");
	void Read () {fin>>d[0]>>d[1]>>d[2];
	int I, J;
			for (i = 0; i < 3; i++) {for (j = 0; J < 3; J +) {fin>>map[j][i];
		Dp[j][i] = Map[j][i]; Getdet int det[3][3]) {//Calculate value of three row determinant int ans = det[0][0] * det[1][1] * det[2][2] + det[0][1] * det[1][2] * Det[2][0] + det[1][0] * det[2][1] * det[0][2]-det[0][2] * det[1][1] * det[2][0]-det[0][1] * det[1][0] * det[2][2
	]-det[0][0] * det[1][2] * det[2][1];
return ans;
	} void Modifymap (int col, int multiple) {//replaces the Col column of the determinant with array d for INT i,j;

	for (i = 0; i < 3; i++) for (j = 0; J < 3; J +) Map[i][j] = Dp[i][j];
for (i = 0; i < 3; i++) Map[i][col] = d[i] * multiple;
	BOOL Calculate () {int i, J;
	BOOL F[3]; for (j = 1; J <= J + +) {foR (i = 0; i < 3; i++) {Modifymap (i, j);//j is multiple, from 1 to 100 to probe if (getdet (map)% Getdet (DP) = 0) {//must pay attention to the sentence here
				Whether the broken divisible ans[i] = Getdet (map)/Getdet (DP);
			F[i] = true;
				else {f[0] = false; f[1] = false; f[2] = false;
			Break
			} if (f[1] = = True && f[2] = = True && F[0] = = True) {ans[3] = j;
			fout<<ans[0]<< "" <<ans[1]<< "" <<ans[2]<< "" <<ans[3]<<endl;
		return true;
return false;

	int main () {read ();
	if (Getdet (DP) = = 0) {fout<< "NONE" <<endl;
		else {calculate (); if (Ans[0] >= 0 && ans[1] >= 0 && ans[2] >= 0 && ans[3] > 0)//Some source data is not the simplest and may result in negative answers appearing here
		To check fout<<ans[0]<< "" <<ans[1]<< "<<ans[2]<<" "<<ans[3]<<endl;	
	else fout<< ' NONE ' <<endl;
	} fin.close ();
	Fout.close ();
return 0;
 }



Description

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

Gives three sets of integers, indicating barley: oats: The proportion of wheat, to find out how to use these three kinds of feed to allocate x:y:z feed.

For example, give the target feed 3:4:5 and the proportion of three kinds of feeds:

    1:2:3   
    3:7:1  
    2:1:2

You have to program to find the least amount of these three feeds, and if you can't use the three feeds for the target feed, output "NONE". "Minimum dosage" means that the amount of three feeds (integers) must be minimal.


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

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

Integer that represents the feed ratio and the target feed is a non-negative integer less than 100. An integer that represents the number of copies of a variety of feeds, all less than 100. The proportions of a mixture are not directly added to the proportions of other mixtures. [Edit] Format

Program NAME: Ratios

INPUT FORMAT:

(File ratios.in)

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

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

OUTPUT FORMAT:

(File ratios.out)

The output file is to be included in one row, which has either four integers or NONE. The first three integers indicate the number of copies of three kinds of feeds, and the target feed can be obtained with this ratio. The fourth integer represents the number of target feeds obtained after mixing three kinds of feeds. [Edit]sample INPUT

3 4 5 1 2 3 3 7 1 2 1-
2 
[Edit]sample OUTPUT
8 1 5 7

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.