Feed Ratios USACO 3.2
额,要求都要最小,4重循环直接搜索即可...
1 /* 2 3 ID: hubiao cave 4 5 PROG: ratios 6 7 LANG: C++ 8 9 */ 10 11 12 13 14 #include<iostream> 15 16 #include<fstream> 17 18 #include<string> 19 20 using namespace std; 21 22 23 bool CanFit(int,int,int,int); 24 int arry[12]; 25 int main() 26 27 { 28 29 30 ifstream fin("ratios.in"); 31 32 ofstream fout("ratios.out"); 33 for(int i=0;i<12;i++) 34 fin>>arry[i]; 35 36 for(int i=0;i<=100;i++) 37 for(int j=0;j<=100;j++) 38 for(int m=0;m<=100;m++) 39 for(int n=0;n<=100;n++) 40 { 41 if(CanFit(i,j,m,n)) 42 { 43 fout<<i<<" "<<j<<" "<<m<<" "<<n<<endl; 44 return 0; 45 } 46 } 47 fout<<"NONE"<<endl; 48 return 0; 49 50 51 } 52 bool CanFit(int i,int j,int m,int n) 53 { 54 if(!i&&!j&&!m) 55 return false; 56 int sum1=i*arry[3]+j*arry[6]+m*arry[9]; 57 int sum2=i*arry[4]+j*arry[7]+m*arry[10]; 58 int sum3=i*arry[5]+j*arry[8]+m*arry[11]; 59 60 if(sum1==n*arry[0]&&sum2==n*arry[1]&&sum3==n*arry[2]) 61 return true; 62 return false; 63 }