Page 31 of 33

### 102 Ecological Bin Packing in JAVA

Posted: Mon Aug 05, 2013 10:14 pm
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
Try solving it without using floating point.

### Re: 102 whats wrong with this?

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

### Re: 102 whats wrong with this?

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

Code: Select all

``````#include<iostream>
using namespace std;

int main()
{
long long bin,q;
while(cin>>bin>>bin>>bin>>bin
>>bin>>bin>>bin>>bin>>bin)
{
long long min=10000000,e=0;
//bcg
q=bin+bin+bin+bin+bin+bin;
//bgc
q=bin+bin+bin+bin+bin+bin;
//cbg
q=bin+bin+bin+bin+bin+bin;
//cgb
q=bin+bin+bin+bin+bin+bin;
//gbc
q=bin+bin+bin+bin+bin+bin;
//gcb
q=bin+bin+bin+bin+bin+bin;
for (int i=1;i<=6;i++)
{
if (q[i]<min)
{
e=i;
min=q[i];
}
}

if (e==1) cout<<"BCG "<<q<<endl;
if (e==2) cout<<"BGC "<<q<<endl;
if (e==3) cout<<"CBG "<<q<<endl;
if (e==4) cout<<"CGB "<<q<<endl;
if (e==5) cout<<"GBC "<<q<<endl;
if (e==6) cout<<"GCB "<<q<<endl;
}
return 0;
}
``````

### Re: 102 whats wrong with this?

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

### Re: 102 whats wrong with this?

Posted: Thu Aug 08, 2013 12:03 pm
TNX i got AC

### WA 102 - Ecological Bin Packing

Posted: Thu Aug 22, 2013 8:24 pm
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;
char str = {'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[b] + array[g] + array[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
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
AC... Thanks dear....

### 102 Can anyone fix my bug, please~~

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

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

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

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

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

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

}

int main()
{

while (scanf("%d%d%d%d%d%d%d%d%d", &brown, &green, &clear, &brown, &green, &clear, &brown, &green, &clear)==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, binseq, binseq, minv);
}

return 0;
} thank you~

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

Posted: Mon Dec 09, 2013 9:34 pm
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
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 = {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 = {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=1;
bins=2;
bins=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
Try changing your input parsing, maybe
while(getline(cin, input))
while(!cin.eof())

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

Posted: Sat Jan 18, 2014 12:19 am
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   My Code.

[cpp]Got AC
[/code]