Re: Wrong Answer for 102
Posted: Sun Jan 04, 2009 2:32 am
Can someone explain to me why "CBG" is alphabetically superior to "BGC"?
Edit: Never mind, I was doing it wrong.
Edit: Never mind, I was doing it wrong.
Code: Select all
#include <iostream>
#include <map>
using namespace std;
long long Color[3][3];
long long SumColor[3];
map<int ,char> M;
bool ColorUsed[3];
int BinColor[3];
//output
int MinBinColor[3];
long long MinMove;
void GetInput()
{
for (int i = 0 ;i<3 ;i++)
{
SumColor[i] = 0;
ColorUsed[i] = false;
BinColor[i] = 0;
}
MinMove = (long long)1<<31 ;
for (int i = 0 ;i<3 ;i++)
{
cin>>Color[i][0]>>Color[i][2]>>Color[i][1];
SumColor[i] = Color[i][0]+Color[i][2]+Color[i][1];
}
}
void Process(int bin)
{
if( bin == 3 )
{
long long TmpMove =0;
for (int j = 0; j<3 ;j++)
{
TmpMove += SumColor[j]-Color[j][BinColor[j]];
}
if (TmpMove < MinMove)
{
MinMove = TmpMove;
for (int j = 0 ; j<3 ; j++)
{
MinBinColor[j] = BinColor[j];
}
}
return;
}
for (int i = 0 ; i<3 ; i++)
{
if(ColorUsed[i] == false)
{
ColorUsed[i] = true;
BinColor[bin] = i;
Process(bin+1);
ColorUsed[i] = false;
}
}
}
void SetOutput()
{
for (int i = 0 ; i<3 ; i++)
{
cout<<M[MinBinColor[i]];
}
cout<<' ';
cout<<MinMove;
cout<<endl;
}
int main()
{
M[0] = 'B';
M[1] = 'C';
M[2] = 'G';
while(!cin.eof())
{
GetInput();
Process(0);
SetOutput();
}
return 0;
}
Code: Select all
#include <iostream>
#include <string>
using namespace std;
int solution (int a, int b, int c, const int (&solarray)[9]) {
return solarray[a]+solarray[b]+solarray[c];
};
string solution_id_to_string(int solID) {
string out;
switch (solID) {
case 1:
out="BCG";
break;
case 2:
out="BGC";
break;
case 3:
out="CBG";
break;
case 4:
out="CGB";
break;
case 5:
out="GBC";
break;
case 6:
out="GCB";
break;
default: out="";
}
return out;
};
int main () {
int input[9];
int line_max = 1000;
int solves[line_max][2];
int line_no=0;
while((cin >> input[0] >> input[1] >> input[2] >> input[3] >> input[4] >> input[5] >> input[6] >> input[7] >> input[8]) and (line_no < line_max)) {
int total = input[0]+input[1]+input[2]+input[3]+input[4]+input[5]+input[6]+input[7]+input[8];
int max = solution(0,5,7,input);
int solution_id=1;
if (max<solution(0,4,8,input)) {max=solution(0,4,8,input);solution_id=2;};
if (max<solution(2,3,7,input)) {max=solution(2,3,7,input);solution_id=3;};
if (max<solution(2,4,6,input)) {max=solution(2,4,6,input);solution_id=4;};
if (max<solution(1,3,8,input)) {max=solution(1,3,8,input);solution_id=5;};
if (max<solution(1,5,6,input)) {max=solution(1,5,6,input);solution_id=6;};
//cout << solution_id << "\t" << total -max <<endl;
solves[line_no][0]=solution_id;
solves[line_no][1]=total-max;
line_no++;
}
for(int i=0;i<line_no;i++) {
cout << solution_id_to_string(solves[i][0]) << " " << solves[i][1] << endl;
}
return 0;
}
Code: Select all
0 1 0 0 0 1 1 0 0
Code: Select all
GCB 0
Code: Select all
1 0 0 0 1 0 0 0 1
Code: Select all
BGC 0
Code: Select all
0 0 1 1 0 0 0 1 0
Code: Select all
CBG 0
Code: Select all
//THIS CODE HAS BEEN WRITTEN BY CODEWORRIOR(SHIVMITRA MISHRA)
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<cstring>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
using namespace std;
typedef long long int64;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define A first
#define B second
#define PII pair<int,int>
#define VI vector<int>
#define CLR(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define pb push_back
typedef long long int64;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","wt",stdout);
int64 b1,c1,g1,b2,c2,g2,b3,c3,g3;
int64 total[8];
//int64 cases=0;
while(scanf("%lld%lld%lld%lld%lld%lld%lld%lld%lld",&b1,&g1,&c1,&b2,&g2,&c2,&b3,&g3,&c3)==9)
{
CLR(total,0);
//1
total[5]=c1+g1+b2+c2+b3+g3;
//2
total[6]=c1+g1+b2+g2+b3+c3;
//3
total[2]=b1+c1+g2+c2+b3+g3;
//4
total[1]=b1+c1+b2+g2+c3+g3;
//5
total[4]=b1+g1+c2+g2+b3+c3;
//6
total[3]=b1+g1+b2+c2+c3+g3;
//FOR(i,1,6)
//printf("%d\n",total[i]);
int64 ans=1<<20,pos=1;
FOR(i,1,6)
{
ans=min(total[i],ans);
if(ans==total[i])
pos=i;
}
switch (pos)
{
case 1:
{printf("GCB %d",total[1]);break;}
case 2:
{printf("GBC %d",total[2]);break;}
case 3:
{printf("CGB %d",total[3]);break;}
case 4:
{printf("CBG %d",total[4]);break;}
case 5:
{printf("BGC %d",total[5]);break;}
case 6:
{printf("BCG %d",total[6]);break;}
}
printf("\n");
}
}
Code: Select all
Code: Select all
#include<iostream>
#include<cstdio>
using namespace std;
long bo[3][3],maxs,maxt,cot[3],cos[3],maxa;
bool flag[3];
char cr[3]={'B','G','C'};
void se(int b)
{
if(b==0){int i;
for(i=0;i<3;++i)
{
maxs=0;
flag[i]=false;
maxs+=(bo[i][1]+bo[i][2]);
cot[b]=i;
se(1);
flag[i]=true;
}}
else if(b==1)
{ int i;
for(i=0;i<3;++i)
if(flag[i])
{
maxs+=(bo[i][0]+bo[i][2]);
flag[i]=false;cot[b]=i;
se(2);flag[i]=true;
maxs-=(bo[i][0]+bo[i][2]);
}
}
else if(b==2){int i;
for(i=0;i<3;++i)
if(flag[i])
{maxs+=(bo[i][0]+bo[i][1]);
cot[b]=i;
if(maxs<=maxt)
{if(maxs<maxt)
{maxt=maxs;
for(int i=0;i<3;++i){cos[i]=cot[i];}
}
else {
for(int i=0;i<3;++i)
{if(cr[cot[i]]<=cr[cos[i]])
{
if(cr[cot[i]]<=cr[cos[i]])
for(int j=i;j<3;++j)cos[j]=cot[j];
}else break;}
}
}maxs-=(bo[i][0]+bo[i][1]);
}
}
}
int main()
{
int i,j;
while(cin>>bo[0][0]>>bo[1][0]>>bo[2][0]>>bo[0][1]
>>bo[1][1]>>bo[2][1]>>bo[0][2]>>bo[1][2]>>bo[2][2])
{
for(int i=0;i<3;++i)flag[i]=true;
maxt=0xfffffff;se(0);
for(int i=0;i<3;++i)printf("%c",cr[cos[i]]);
printf(" %lld\n",maxt);
}
}
Code: Select all
import java.io.IOException;
public class Main {
public final static int BCG = 0;
public final static int BGC = 1;
public final static int CBG = 2;
public final static int CGB = 3;
public final static int GBC = 4;
public final static int GCB = 5;
long[] moves = new long[6];
static String readln(int maxLg) {
byte lin[] = new byte[maxLg];
int lg = 0, car = -1;
try {
while (lg < maxLg) {
car = System.in.read();
if ((car < 0) || (car == '\n')) {
break;
}
lin[lg++] += car;
}
} catch (IOException e) {
return (null);
}
if ((car < 0) && (lg == 0)) {
return (null); // eof
}
return (new String(lin, 0, lg));
}
public void run() {
String s = "", result = "";
boolean first = true;
while ((s = readln(255)) != null) {
String splitted[] = s.trim().split(" +");
if (splitted.length != 9) {
continue;
}
long b1B = Long.parseLong(splitted[0]);
long b1G = Long.parseLong(splitted[1]);
long b1C = Long.parseLong(splitted[2]);
long b2B = Long.parseLong(splitted[3]);
long b2G = Long.parseLong(splitted[4]);
long b2C = Long.parseLong(splitted[5]);
long b3B = Long.parseLong(splitted[6]);
long b3G = Long.parseLong(splitted[7]);
long b3C = Long.parseLong(splitted[8]);
moves[BCG] = b1G + b1C + b2B + b2G + b3B + b3C;
moves[BGC] = b1G + b1C + b2C + b2B + b3G + b3B;
moves[CBG] = b1B + b1G + b2C + b2G + b3B + b3C;
moves[CGB] = b1B + b1G + b2B + b2C + b3C + b3G;
moves[GBC] = b1B + b1C + b2C + b2G + b3B + b3G;
moves[GCB] = b1B + b1C + b2B + b2G + b3C + b3G;
long mresult = moves[BCG];
int morder = BCG;
for (int i = 1; i < 6; i++) {
if (moves[i] < mresult) {
mresult = moves[i];
morder = i;
}
}
if(!first) result += "\n";
if (morder == BCG) {
result += "BCG";
} else if (morder == BGC) {
result += "BGC";
} else if (morder == CBG) {
result += "CBG";
} else if (morder == CGB) {
result += "GCB";
} else if (morder == GBC) {
result += "GBC";
} else if (morder == GCB) {
result += "GCB";
}
result += " " + mresult;
first = false;
}
System.out.println(result);
}
public static void main(String[] args) {
Main m = new Main();
m.run();
}
}