标签:
题目传送门:http://www.nocow.cn/index.php/Translate:USACO/ratios
这道题也是直接枚举。。。
/* ID:abc31261 LANG:C++ TASK:ratios */ #include<cstdio> #include<cstring> #include<iostream> using namespace std; int a[5][5]; int main() { int i,j,l,k,p,ansmin=0x7f,ansfen,ans[5],count[4],sum[4],num[4]; bool flag=false; freopen("ratios.in","r",stdin); freopen("ratios.out","w",stdout); for (i=0;i<=3;i++)scanf("%d%d%d",&a[i][1],&a[i][2],&a[i][3]); for (num[1]=0;num[1]<=100;num[1]++) for (num[2]=0;num[2]<=100;num[2]++) for (num[3]=0;num[3]<=100;num[3]++) { memset(count,0,sizeof(count)); memset(sum,0,sizeof(sum)); for (k=1;k<=3;k++) for (p=1;p<=3;p++)sum[p]+=num[k]*a[k][p]; sum[0]=sum[1]+sum[2]+sum[3]; for (k=1;k<=3;k++) if (sum[k]%a[0][k]==0 && a[0][k]!=0)count[k]=sum[k]/a[0][k]; if (count[1]==count[2] && count[2]==count[3] && (count[1]!=0||count[2]!=0||count[3]!=0) && sum[0]<ansmin) { flag=true; memcpy(ans,num,sizeof(num)); ansfen=count[1]; ansmin=sum[0]; } } if (flag)printf("%d %d %d %d\n",ans[1],ans[2],ans[3],ansfen); else printf("none\n"); return 0; }
标签:
原文地址:http://www.cnblogs.com/Sun-Sea/p/5143764.html