With three kinds of nutrient ingredients of different feed, to form a precise proportion of nutritious feed.
Data range is small, simple enumeration can be over.
/*id:modengd1prog:ratioslang:c++*/#include <iostream> #include <stdio.h>using namespace Std;int main () {F Reopen ("Ratios.in", "R", stdin); Freopen ("Ratios.out", "w", stdout); int input[4][3]; for (int i = 0;i < 4;i++) {for (int j = 0;j < 3;j++) {scanf ("%d", &input[i][j]); }} for (int i=0;i<=100;i++) {for (int. j=0;j<=100;j++) {for (int k=0;k<=100; k++) {int a= (i*input[1][0]+j*input[2][0]+k*input[3][0]); int b= (i*input[1][1]+j*input[2][1]+k*input[3][1]); int c= (i*input[1][2]+j*input[2][2]+k*input[3][2]); if (a==0&&b==0&&c==0) continue; if ((a*input[0][1]) = = (B*input[0][0]) && (b*input[0][2]) = = (C*input[0][1]) && (a>=input[0][0])) {cout<<i<< ' <<j<< ' <<k<< ' <<a/input[0][0]<<endl; return 0; }}}} cout<< "NONE" <<endl; return 0;}
Usaco Feed Ratios