Usaco-3.2-ratios-pass

Source: Internet
Author: User

This ratio problem, hehe, linear algebra knowledge, enumeration bar, this number is small.

/*Id:qq104801lang:c++task:ratios*/#include<iostream>#include<fstream>#include<bitset>#include<cstdio>#include<algorithm>using namespacestd;intgoal[3];intii[3][3];intans[4];intminsum=100000; inlineintAsum (int inch,intIintJintk) {    returnii[0][inch]*i+ii[1][inch]*j+ii[2][inch]*K;} InlineintXsumintIintJintk) {    returnAsum (0, i,j,k) +asum (1, i,j,k) +asum (2, i,j,k);}voidTest () {freopen ("ratios.in","R", stdin); Freopen ("Ratios.out","W", stdout); intisum=0;  for(intI=0;i<3; i++) {cin>>Goal[i]; Isum+=Goal[i]; }     for(intI=0;i<3; i++)         for(intj=0;j<3; j + +) Cin>>Ii[i][j]; if(isum==0) {cout<<"0 0 0 0"<<Endl; return; }     for(intI=0;i< -&& i<minsum;i++)         for(intj=0;j< -&& j<minsum;j++)             for(intk=0;k< -&& k<minsum;k++)            {                if(i+j+k==0)Continue; intcc[3];  for(intC=0;c<3; C + +) Cc[c]=asum (c,i,j,k); if(cc[0]*goal[1]!=cc[1]*goal[0])Continue; if(cc[1]*goal[2]!=cc[2]*goal[1])Continue; if(cc[0]<goal[0] || cc[1]<goal[1]                     || cc[2]<goal[2])Continue; Minsum=i+j+K; ans[0]=i;ans[1]=j;ans[2]=K; ans[3]=xsum (i,j,k)/isum; }            if(ans[0]+ans[1]+ans[2]==0) {cout<<"NONE"<<Endl; return; } cout<<ans[0]<<" "<<ans[1]<<" "<<ans[2]<<" "<<ans[3]<<Endl;}intMain () {test (); return 0;}

Test data:

Usaco Traininggrader Results10Users Onlinechn/4 USA/6USER:CN Tom [Qq104801]task:ratioslang:c++compiling...compile:okexecuting ... Test1:test OK [0.008 secs, 3376KB] Test2:test OK [0.011 secs, 3376KB] Test3:test OK [0.008 secs, 3376KB] Test4:test OK [0.022 secs, 3376KB] Test5:test OK [0.027 secs, 3376KB] Test6:test OK [0.011 secs, 3376KB] All tests OK. YOUR Program (' ratios ') worked first TIme! That ' s fantastic--and a rare thing. Please accept these special automated congratulations.  Here is the test data inputs:-------Test 1----5 8 3 2-------Test 0----2 3 5 4 2 7  ----244 5 5 612-------Test 4----8098 9689 8878-------Test 5----99 99 991 0 00 1 00 0 1-------Test 6----9798 0 98 0 98Keep up the good work! Thanks for your submission!

Usaco-3.2-ratios-pass

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.