Wednesday, September 01, 2010

[UVa] 102 - Ecological Bin Packing

Simple enough. Just have to check the six combinations and the answer is ready.
Here's my solution. I know it has an extremely short solution but I did this one.


#include <stdio.h>
int main()
{

char comb[6][4]={"BCG","BGC","CBG","CGB","GBC","GCB"};
long int input[9]={0}, i=1, count=0, mincount=999999999, com;

while (scanf("%ld",&input[i])==1)
{
for (i=2 ; i<=9 ; i++)
{
scanf("%ld",&input[i]);
}

for (i=0, count=0 ; i<6 ; i++)
{
if (comb[i][0]=='B')
{
if (comb[i][1]=='C')
{
count=input[4]+input[7]+input[3]+input[9]+input[2]+input[5];
} else
{
count=input[4]+input[7]+input[2]+input[8]+input[3]+input[6];
}
} else if (comb[i][0]=='C')
{
if (comb[i][1]=='B')
{
count=input[6]+input[9]+input[1]+input[7]+input[2]+input[5];
} else
{
count=input[6]+input[9]+input[2]+input[8]+input[1]+input[4];
}
} else if (comb[i][0]=='G')
{
if (comb[i][1]=='B')
{
count=input[5]+input[8]+input[1]+input[7]+input[3]+input[6];
} else
{
count=input[5]+input[8]+input[3]+input[9]+input[1]+input[4];
}
}

if (count<mincount)
{
mincount=count;
com=i;
count=0;
}
}

printf("%s %ld\n",comb[com],mincount);

i=1;
mincount=999999999;
}

return 0;
}

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...