用三种营养成分不同的饲料,凑成精确比例营养的饲料。
数据范围比较小,单纯枚举就能过。
/*
ID: modengd1
PROG: ratios
LANG: C++
*/
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
freopen("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;
}
原文:http://www.cnblogs.com/modengdubai/p/4822694.html