problem link:
discuss: in this problem you have to combine the color as much it get minimum. there is six combination possibile,so do it lexographically order.
try your self before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
//freopen("input.txt","r",stdin);
//freopen("out.txt","w",stdout);
long long ara[10];
string mnm;
while(cin >>ara[0]>>ara[1]>>ara[2]>>ara[3]>>ara[4]>>ara[5]>>ara[6]>>ara[7]>>ara[8])
{
long long i,j,n,cnt=0,flag=0,bcg=0,bgc=0,cbg=0,cgb=0,gbc=0,gcb=0,mn=10000000000;
bcg=ara[3]+ara[6]+ara[2]+ara[8]+ara[1]+ara[4];
if(mn>bcg)
{
mnm="BCG";
mn=bcg;
}
bgc=ara[3]+ara[6]+ara[1]+ara[7]+ara[2]+ara[5];
if(mn>bgc)
{
mnm="BGC";
mn=bgc;
}
cbg=ara[5]+ara[8]+ara[0]+ara[6]+ara[1]+ara[4];
if(mn>cbg)
{
mnm="CBG";
mn=cbg;
}
cgb=ara[5]+ara[8]+ara[1]+ara[7]+ara[0]+ara[3];
if(mn>cgb)
{
mnm="CGB";
mn=cgb;
}
gbc=ara[4]+ara[7]+ara[0]+ara[6]+ara[2]+ara[5];
if(mn>gbc)
{
mnm="GBC";
mn=gbc;
}
gcb=ara[4]+ara[7]+ara[2]+ara[8]+ara[0]+ara[3];
if(mn>gcb)
{
mnm="GCB";
mn=gcb;
}
cout <<mnm<<' '<<mn<<endl;
}
return 0;
}
discuss: in this problem you have to combine the color as much it get minimum. there is six combination possibile,so do it lexographically order.
try your self before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
//freopen("input.txt","r",stdin);
//freopen("out.txt","w",stdout);
long long ara[10];
string mnm;
while(cin >>ara[0]>>ara[1]>>ara[2]>>ara[3]>>ara[4]>>ara[5]>>ara[6]>>ara[7]>>ara[8])
{
long long i,j,n,cnt=0,flag=0,bcg=0,bgc=0,cbg=0,cgb=0,gbc=0,gcb=0,mn=10000000000;
bcg=ara[3]+ara[6]+ara[2]+ara[8]+ara[1]+ara[4];
if(mn>bcg)
{
mnm="BCG";
mn=bcg;
}
bgc=ara[3]+ara[6]+ara[1]+ara[7]+ara[2]+ara[5];
if(mn>bgc)
{
mnm="BGC";
mn=bgc;
}
cbg=ara[5]+ara[8]+ara[0]+ara[6]+ara[1]+ara[4];
if(mn>cbg)
{
mnm="CBG";
mn=cbg;
}
cgb=ara[5]+ara[8]+ara[1]+ara[7]+ara[0]+ara[3];
if(mn>cgb)
{
mnm="CGB";
mn=cgb;
}
gbc=ara[4]+ara[7]+ara[0]+ara[6]+ara[2]+ara[5];
if(mn>gbc)
{
mnm="GBC";
mn=gbc;
}
gcb=ara[4]+ara[7]+ara[2]+ara[8]+ara[0]+ara[3];
if(mn>gcb)
{
mnm="GCB";
mn=gcb;
}
cout <<mnm<<' '<<mn<<endl;
}
return 0;
}
No comments:
Post a Comment