102 - Ecological Bin Packing
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 102 - Ecological Bin Packing
There is always a newline char at the end of the last line of the input.
Check input and AC output for thousands of problems on uDebug!
Re: 102 - Ecological Bin Packing
Thanksss a lott......
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
Re: 102 - Ecological Bin Packing
Hey guys,
I'm stuck with this problem. I've tried the debugger and all my answers are correct, but I get WA when I submit.
Here's my code: http://pastebin.com/Lf1Ygnez
Any help/hints are appreciated.
Thanks in advance
I'm stuck with this problem. I've tried the debugger and all my answers are correct, but I get WA when I submit.
Here's my code: http://pastebin.com/Lf1Ygnez
Any help/hints are appreciated.
Thanks in advance
Re: 102 - Ecological Bin Packing
You got two problems here.
First and foremost, you count the values of your total[] table as if G was before C in the alphabet.
In addition to this, you also have a typo in your switch.
Correct the order of the values of your total[] table, modify your switch accordingly and double-check it for typos and you'll get Accepted.
Sample input:
Your program prints:
The correct answer should be: (checked with the debugger)
First and foremost, you count the values of your total[] table as if G was before C in the alphabet.
In addition to this, you also have a typo in your switch.
Correct the order of the values of your total[] table, modify your switch accordingly and double-check it for typos and you'll get Accepted.
Sample input:
Code: Select all
0 0 0 5 1 1 0 0 0
0 1 0 0 0 1 1 0 0
Code: Select all
GBC 2
CGB 0
Code: Select all
CBG 2
GCB 0
Re: 102 - Ecological Bin Packing
anybody please give me some sensitive case for this problem...i m getting wa...i didn't find any fault in my code,so i need some sensitive cases for check my code
Re: 102 - Ecological Bin Packing
Can't find the reason of getting wrong answer.
Code: Select all
#include <bits/stdc++.h>
using namespace std;
unsigned b0,b1,b2,g0,g1,g2,c0,c1,c2;
bool record;
char arr[] = {'B', 'C', 'G'};
char ans[3];
/*vector<char>arr, out_view;
int taken[20] = {0};*/
unsigned calculation()
{
unsigned total = 0;
for(int i = 0; i < 3; i++)
{
switch(arr[i])
{
case 'B':
switch(i)
{
case 0:
total = total + b1 + b2;
break;
case 1:
total = total + b0 + b2;
break;
case 2:
total = total + b0 + b1;
break;
}
break;
case 'C':
switch(i)
{
case 0:
total = total + c1 + c2;
break;
case 1:
total = total + c0 + c2;
break;
case 2:
total = total + c0 + c1;
break;
}
break;
case 'G':
switch(i)
{
case 0:
total = total + g1 + g2;
break;
case 1:
total = total + g0 + g2;
break;
case 2:
total = total + g0 + g1;
break;
}
break;
}
}
return total;
}
/*
void permutation()
{
int total;
if(arr.size() == 3)
{
/*for(int i=0;i<3;i++)
printf("%c",arr[i]);
total = calculation();
//cout << " " << record << " " << total << endl;
if(record)
{
Min = total;
record = 0;
out_view = arr;
}
else if(total < Min)
{
Min = total;
out_view = arr;
}
//puts("");
return;
}
for(int i = 0; i<3; i++)
{
if(taken[i] == 0)
{
taken[i] = 1; arr.push_back(arr[i]);
permutation();
taken[i] = 0; arr.pop_back();
}
}
}
*/
main()
{
unsigned total, Min;
while(scanf("%u%u%u%u%u%u%u%u%u",&b0,&g0,&c0,&b1,&g1,&c1,&b2,&g2,&c2)!=EOF)
{
record = false;
//permutation();
//sort(arr, arr + 3);
do{
total = calculation();
if(!record)
{
Min = total;
strcpy(ans, arr);
record = true;
//copy(std::begin(src), std::end(src), std::begin(dest));
}
else if(total < Min)
{
Min = total;
strcpy(ans, arr);
}
}while(next_permutation(arr, arr + 3));
for(int i=0;i<3;i++)
printf("%c",ans[i]);
printf(" %u\n",Min);
}
return 0;
}