## 102: Wrong answer. Why? Anything i have misunderstand?

Moderator: Board moderators

### 102: Wrong answer. Why? Anything i have misunderstand?

Thanks for the help

Code: Select all
`#include<iostream>#include<vector>using namespace std;void add(vector<vector<int> >& bin,vector<vector<int> >& result){    for(int i=0; i<3;++i){    for(int n=0; n<3; ++n){      if(n==i) continue;      result[i][0]+=bin[n][0];      result[i][1]+=bin[n][1];      result[i][2]+=bin[n][2];    }  }}string minfunction(vector<vector<int> >& result, int& min){  int a,b,c,sum;  string bgc;  sum=result[0][1]+result[1][2]+result[2][0];  if(min>=sum){ min=sum;bgc="GCB";}  sum=result[0][1]+result[1][0]+result[2][2];  if(min>=sum){ min=sum;bgc="GBC";}  sum=result[0][2]+result[1][1]+result[2][0];  if(min>=sum){ min=sum;bgc="CGB";}   sum=result[0][2]+result[1][0]+result[2][1];  if(min>=sum){ min=sum;bgc="CBG";}  sum=result[0][0]+result[1][1]+result[2][2];  if(min>=sum){ min=sum;bgc="BGC";}  sum=result[0][0]+result[1][2]+result[2][1];  if(min>=sum){ min=sum;bgc="BCG";}return bgc;}  int main(){  vector< vector<int> > bin(6,vector<int>(3,0));  while(cin>>bin[0][0]>>bin[0][1]>>bin[0][2]>>bin[1][0]>>bin[1][1]>>bin[1][2]>>bin[2][0]>>bin[2][1]>>bin[2][2]){    vector<vector<int> > result(3,vector<int>(3,0));    add(bin,result);    int min=10000000;    string res=minfunction(result,min);      cout <<res<<' '<<min << endl;  }  return 0; }`
jingtra
New poster

Posts: 1
Joined: Sun Nov 16, 2008 1:35 am

### Re: 102: Wrong answer. Why? Anything i have misunderstand?

jingtra wrote:

Code: Select all
`    add(bin,result);    int min=10000000;.......`

You can take any of the values of sum as min initially and then continue to find which one is actual min. At least it will solve the problem if your min is not large enough..
Solving for fun..

linux
Learning poster

Posts: 56
Joined: Sat Jul 01, 2006 12:21 pm