
and i also try before many guys there input , and i got the anser of the AC-code is the same answer. but the problem is I still got the WA.
so , plz help me to solved the problem, thx

here is my code in java.
Code: Select all
removed
I got AC

Moderator: Board moderators
Code: Select all
removed
Code: Select all
#include<iostream>
using namespace std;
int main()
{
long long bin[4][4],q[7];
while(cin>>bin[1][1]>>bin[1][2]>>bin[1][3]>>bin[2][1]
>>bin[2][2]>>bin[2][3]>>bin[3][1]>>bin[3][2]>>bin[3][3])
{
long long min=10000000,e=0;
//bcg
q[1]=bin[2][1]+bin[3][1]+bin[1][3]+bin[3][3]+bin[1][2]+bin[2][2];
//bgc
q[2]=bin[2][1]+bin[3][1]+bin[1][2]+bin[3][2]+bin[1][3]+bin[2][3];
//cbg
q[3]=bin[2][3]+bin[3][3]+bin[1][1]+bin[3][1]+bin[1][2]+bin[2][2];
//cgb
q[4]=bin[2][3]+bin[3][3]+bin[1][2]+bin[3][2]+bin[1][1]+bin[2][1];
//gbc
q[5]=bin[2][2]+bin[3][2]+bin[1][1]+bin[3][1]+bin[1][3]+bin[2][3];
//gcb
q[6]=bin[2][2]+bin[3][2]+bin[1][3]+bin[3][3]+bin[1][1]+bin[2][1];
for (int i=1;i<=6;i++)
{
if (q[i]<min)
{
e=i;
min=q[i];
}
}
if (e==1) cout<<"BCG "<<q[1]<<endl;
if (e==2) cout<<"BGC "<<q[2]<<endl;
if (e==3) cout<<"CBG "<<q[3]<<endl;
if (e==4) cout<<"CGB "<<q[4]<<endl;
if (e==5) cout<<"GBC "<<q[5]<<endl;
if (e==6) cout<<"GCB "<<q[6]<<endl;
}
return 0;
}
Code: Select all
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<list>
#include<map>
using namespace std;
#define ll long long int
#define sf scanf
#define pf printf
#define MAX 50
ll array[3][3];
char str[4] = {'B','G','C','\0'};
///B = 0, G = 1, C = 2
ll x, sum, MIN,
B, G, C;
void planning(ll b, ll g, ll c){
x = sum - (array[0][b] + array[1][g] + array[2][c]);
if(x < MIN){
MIN = x;
B = b, G = g, C = c;
}
}
int main()
{
while(true)
{
bool flag = false;
sum = 0, MIN = 999999999999999999;
for(ll i = 0; i < 3; i++)
{
for(ll j = 0; j < 3; j++){
if(sf("%lld",&array[i][j]) == EOF){
flag = true;
i = 10;
break;
}
sum += array[i][j];
}
}
if(flag) break;
planning(0, 2, 1);
planning(0, 1, 2);
planning(2, 1, 0);
planning(2, 0, 1);
planning(1, 0, 2);
planning(1, 2, 0);
printf("%c%c%c %lld\n",str[B],str[G],str[C],MIN);
}
return 0;
}
Code: Select all
Code: Select all
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <ctime>
using namespace std;
int main(char* args)
{ string input,token;
bool set=false;
int permuts[18] = {1,2,3,1,3,2,2,1,3,2,3,1,3,1,2,3,2,1};
while(!cin.eof())
{ int periterator=0;
string winner;
getline(cin,input);
stringstream ss(input);
unsigned long bins[3] = {1,2,3};
unsigned long binno=1,maxbrown=0,maxgreen=0,maxclear=0,minmoves=0, counter=0,brownbin=0,greenbin=0,clearbin=0,i=0,first=1,second=2,third=3,j=0,winnerl=0;
set=false;
while(j < 6)
{ binno=1,maxbrown=0,maxgreen=0,maxclear=0,minmoves=0, counter=0,brownbin=0,greenbin=0,clearbin=0,i=1,first=1,second=2,third=3;
bins[0]=1;
bins[1]=2;
bins[2]=3;
while(i<=3) //for each bin on a line
{ counter=0;
binno=1;
if(j>0 || i>1)
{ ss.clear();
ss.seekg(0);
}
while(getline(ss,token,' ')) // for each corresponding bottle per bin
{ counter++;
unsigned long bottles=0;
istringstream(token) >> bottles;
if(counter==3 && i==permuts[periterator]) //clear bottles
{ if(bottles>=maxclear && bins[binno-1]!=-1) //if new max and bin not taken
{ minmoves+=maxclear;
if(clearbin!=0)bins[clearbin-1]=clearbin;
bins[binno-1]=-1;
clearbin=binno;
maxclear=bottles;
}
else
if(bottles>0)minmoves+=bottles;
}
else if(counter==2 && i==permuts[periterator+1]) //green bottles
{ if(bottles>=maxgreen && bins[binno-1]!=-1)
{ minmoves+=maxgreen;
if(greenbin!=0)bins[greenbin-1]=greenbin;
bins[binno-1]=-1;
greenbin=binno;
maxgreen=bottles;
}
else
if(bottles>0)minmoves+=bottles;
}
else if(counter==1 && i==permuts[periterator+2])//brown bottles
{ if(bottles>=maxbrown && bins[binno-1]!=-1)
{ minmoves+=maxbrown;
if(brownbin!=0)bins[brownbin-1]=brownbin;
bins[binno-1]=-1;
brownbin=binno;
maxbrown=bottles;
}
else
if(bottles>0)minmoves+=bottles;
}
if(counter%3==0)
{ ++binno;
counter=0;
}
}
++i;
}
periterator+=3;
++j;
string binout;
for(int k=1;k<4;++k)
{ if(k==brownbin)binout+="B";
if(k==greenbin)binout+="G";
if(k==clearbin)binout+="C";
}
if(!set || minmoves<winnerl || ( minmoves==winnerl && binout < winner))
{ set=true;
winnerl=minmoves;
winner=binout;
}
}
cout << winner << " " << winnerl;
if(!cin.eof()) cout << endl;
}
return 0;
}