102 - Ecological Bin Packing

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 102 - Ecological Bin Packing

Post by brianfry713 » Tue Feb 10, 2015 9:58 pm

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!

Zin_tas
New poster
Posts: 3
Joined: Mon Feb 09, 2015 11:05 pm

Re: 102 - Ecological Bin Packing

Post by Zin_tas » Mon Apr 06, 2015 4:43 pm

Thanksss a lott...... :) :) :) :) :)

simeng
New poster
Posts: 1
Joined: Thu Jul 09, 2015 9:21 pm

Re: 102 - Ecological Bin Packing

Post by simeng » Thu Jul 09, 2015 9:47 pm

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

Marcgal
New poster
Posts: 3
Joined: Tue Jul 02, 2013 6:19 pm

Re: 102 - Ecological Bin Packing

Post by Marcgal » Fri Jul 10, 2015 11:32 am

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:

Code: Select all

0 0 0 5 1 1 0 0 0
0 1 0 0 0 1 1 0 0
Your program prints:

Code: Select all

GBC 2
CGB 0
The correct answer should be: (checked with the debugger)

Code: Select all

CBG 2
GCB 0

Sakib773
New poster
Posts: 1
Joined: Wed Aug 26, 2015 11:33 am

Re: 102 - Ecological Bin Packing

Post by Sakib773 » Wed Aug 26, 2015 11:38 am

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

Cramer
New poster
Posts: 2
Joined: Wed Aug 26, 2015 7:25 pm

Re: 102 - Ecological Bin Packing

Post by Cramer » Wed Aug 26, 2015 7:30 pm

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

Post Reply

Return to “Volume 1 (100-199)”