Page 31 of 33

102 Ecological Bin Packing in JAVA

Posted: Mon Aug 05, 2013 10:14 pm
by pop7983
Hello everyone, I've got a problem in 102. I still got a WA !! but I don't know what happened with my code :(
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 :)

Re: 102 Ecological Bin Packing in JAVA

Posted: Tue Aug 06, 2013 1:22 am
by brianfry713
Try solving it without using floating point.

Re: 102 whats wrong with this?

Posted: Tue Aug 06, 2013 1:24 am
by brianfry713
If you want to use q[6], then q should be defined to have size 7.

Re: 102 whats wrong with this?

Posted: Wed Aug 07, 2013 3:34 pm
by f.maru
i have tried that but i got WA answer

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;
}

Re: 102 whats wrong with this?

Posted: Wed Aug 07, 2013 11:20 pm
by brianfry713
The minimum might be bigger than 10000000, try 2147483647 instead.

Re: 102 whats wrong with this?

Posted: Thu Aug 08, 2013 12:03 pm
by f.maru
TNX i got AC

WA 102 - Ecological Bin Packing

Posted: Thu Aug 22, 2013 8:24 pm
by shikhorroy
Where is the problem ??? I got WA.....

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;
}

Re: WA 102 - Ecological Bin Packing

Posted: Thu Aug 22, 2013 11:49 pm
by brianfry713
Swap lines 50 and 51 from:
planning(2, 1, 0);
planning(2, 0, 1);
to:
planning(2, 0, 1);
planning(2, 1, 0);

Re: WA 102 - Ecological Bin Packing

Posted: Fri Aug 23, 2013 8:42 am
by shikhorroy
AC... :)
Thanks dear....

102 Can anyone fix my bug, please~~

Posted: Sun Dec 08, 2013 7:48 am
by EricM
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int minv=2147483647;
int brown[3], green[3], clear[3];
int movev=0;
char binseq[3];

void trybin(int bin1, int bin2, int bin3){
movev=0;
if (bin1==0) {
movev=movev+brown[1]+brown[2];
}
else if (bin1==1){
movev=movev+green[1]+green[2];
}
else{
movev=movev+clear[1]+clear[2];
}

if (bin2==0) {
movev=movev+brown[0]+brown[2];
}
else if (bin2==1){
movev=movev+green[0]+green[2];
}
else{
movev=movev+clear[0]+clear[2];
}
if (bin3==0) {
movev=movev+brown[0]+brown[1];
}
else if (bin3==1){
movev=movev+green[0]+green[1];
}
else{
movev=movev+clear[0]+clear[1];
}

if (movev<=minv) {
minv=movev;
if (bin1==0) {
binseq[0]='B';
}
else if (bin1==1){
binseq[0]='G';
}
else{
binseq[0]='C';
}

if (bin2==0) {
binseq[1]='B';
}
else if (bin2==1){
binseq[1]='G';
}
else{
binseq[1]='C';
}

if (bin3==0) {
binseq[2]='B';
}
else if (bin3==1){
binseq[2]='G';
}
else{
binseq[2]='C';
}
}

}


int main()
{


while (scanf("%d%d%d%d%d%d%d%d%d", &brown[0], &green[0], &clear[0], &brown[1], &green[1], &clear[1], &brown[2], &green[2], &clear[2])==9) {
minv=2147483647;
trybin(0, 1, 2);
trybin(0, 2, 1);
trybin(1, 0, 2);
trybin(1, 2, 0);
trybin(2, 0, 1);
trybin(2, 1, 0);
printf("%c%c%c %d\n",binseq[0], binseq[1], binseq[2], minv);
}

return 0;
} thank you~

Re: 102 Can anyone fix my bug, please~~

Posted: Mon Dec 09, 2013 9:34 pm
by brianfry713
Doesn't match the sample I/O

Problem 102 Bins - 8 submissions and all of them wrong

Posted: Wed Jan 15, 2014 6:52 am
by DevJustinCC
Hi there,

I cannot seem to figure out where I am going wrong. I have used numerous data sets and all seem to come out correctly. Perhaps someone can help. I took a more complicated than necessary approach, but it still ought to work, as follows:

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;
}

Re: Problem 102 Bins - 8 submissions and all of them wrong

Posted: Fri Jan 17, 2014 1:07 am
by brianfry713
Try changing your input parsing, maybe
while(getline(cin, input))
instead of
while(!cin.eof())

Re: Problem 102 Bins - 8 submissions and all of them wrong

Posted: Sat Jan 18, 2014 12:19 am
by DevJustinCC
Thank you :)

That seemed to be it. I would have expected the eof bit to be set after the last successful getline. In fact, that is exactly what happens with my compiler(VS2010 C++ compiler) This seems odd. I appreciate your time.

EDIT: it would appear I need to read passed eof for the bit to be set. This didn't appear to be happening, although using the peek function could have returned ios_base::eofbit and an equality checked perhaps could have gotten out of loop as well. Funny, the VS2010 compiler seems to not require getting passed EOF as judging from the logic it would have been getline that fails and then non-compliant output. That doesnt happen when I run it with the original code. Time to run it on the uva compiler lol.

Thanks again.

Justin.

WA: 102 Why???

Posted: Fri Feb 28, 2014 1:46 am
by me33
:D :) :lol:
My Code.

[cpp]Got AC
[/code]