10182 - Bee Maja

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

Moderator: Board moderators

Post Reply
mie
New poster
Posts: 3
Joined: Sun Jan 05, 2003 1:45 pm

10182 - Bee Maja

Post by mie »

i always get compile error as reply.. can any one tell me how to handle this? is it because my program is too long? plz reply thiz post.. thx..

@begin_of_source_code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define INPUTFILE "BEEMAJA.IN"
#define OUTPUTFILE "BEEMAJA.OUT"

FILE *finput;
FILE *foutput;

void BeeMaja(int *k1, int *k2, long number) {
long c,test;
int n,i;
int p1,p2;
int up;

c=1;
n=1;
p1=p2=0;
while (c < number) {
c+=(n*6);
n++;
p1++;
}

for (i=1;i<n;i++) {
c--;
p2--;
if (c==number) goto ketemu;
}

for (i=1;i<n;i++) {
c--;
p1--;
if (c==number) goto ketemu;
}

for (i=1;i<n;i++) {
c--;
p1--;
p2++;
if (c==number) goto ketemu;
}

for (i=1;i<n;i++) {
c--;
p2++;
if (c==number) goto ketemu;
}

for (i=1;i<n;i++) {
c--;
p1++;
//p2++;
if (c==number) goto ketemu;
}

for (i=1;i<n;i++) {
c--;
p1++;
p2--;
if (c==number) goto ketemu;
}


ketemu:
*k1 = p1;
*k2 = p2;
}


void main () {
int m,n,i;
char input[10];
long number;
char ch[2];

printf("Bee Maja\n");
printf("========\n\n\n");

printf("Open input file %s...\n",INPUTFILE);
finput = fopen(INPUTFILE,"rt");
if (finput == NULL) {
printf("Open File Fail.\n");
exit(EXIT_FAILURE);
}
printf("Open File Success.\n\n");

printf("Open output file %s...\n",INPUTFILE);
foutput = fopen(OUTPUTFILE,"wt");
if (foutput == NULL) {
printf("Open File Fail.\n");
exit(EXIT_FAILURE);
}
printf("Open File Success.\n\n");

printf("Processing input file...\n");
while (1) {
input[0]='\0';
if (fgets(ch,2,finput)==NULL) break;
i=0;
while (1) {
if (i<=10) input=ch[0];
if (fgets(ch,2,finput)==NULL) break;
if (ch[0] == '\n') {

break;
}
i++;
}
input[i+1]='\0';
if (strlen(input) > 0) {
printf(" input : %s ",input);
number = atol(input);
BeeMaja (&m,&n,number);
fprintf(foutput,"%d,%d\n",m,n);
printf(" -->done. output : %d,%d\n",m,n);
}
}
printf("Processing completed\n");
fclose(finput);
fclose(foutput);

}
@end_of_source_code

Zuberul
New poster
Posts: 28
Joined: Sun Oct 24, 2004 9:46 pm
Location: dhaka
Contact:

10182-Bee problem

Post by Zuberul »

I simply generated the whole table for the maximum size.
and after reading a number print positionX[number],positionY[number].
got wrong ans.

please give me some I/O.

Zuberul
New poster
Posts: 28
Joined: Sun Oct 24, 2004 9:46 pm
Location: dhaka
Contact:

Post by Zuberul »

had a little problem.
Got accepted. :P

Nemo
New poster
Posts: 16
Joined: Thu Apr 14, 2005 10:40 am

10182 - bee maja

Post by Nemo »

Can anyone give me any hint on this?
Is there a simple formula?

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

It can be solved by simulation.
Draw the system on a rectangular grid , you should be able to spot a pattern.

Nemo
New poster
Posts: 16
Joined: Thu Apr 14, 2005 10:40 am

Post by Nemo »

Thank you.
I got AC with your suggestion.
It seems there is no simple way other than simulation.

WRJ
New poster
Posts: 11
Joined: Sun Mar 19, 2006 8:28 pm

Post by WRJ »

In my opinion you shouldn't use fopen and fprintf function.

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

There is a simple way for this problem. You can convert the coordinates using simple mathematical operations, simulation is not necessery.

Farzii
New poster
Posts: 1
Joined: Mon Oct 12, 2009 8:49 am

10182-BeeMaja

Post by Farzii »

I have been trying to submit this code for the past few days but every time it shows the same error- WRONG OUTPUT.I am new at uva. Plz help me find what has gone wrong in the code as I am not able to see what is wrong with it.



#include<iostream>
#include<list>

using namespace std;

int main(){
list<int> l;
list<int>::iterator I;
int n;
while(1){
cin>>n;
if(n==EOF) break;
int a=6,b=1;
n--;
while(n>a){
n-=b*6;
a=(b+1)*6;
b++;
}

int k1=(n-1)/b,k2=(n-1)%b,x=0,y=0;
//cout<<b<<" "<<n<<"\n";
switch(k1){
case 0:
x=b-(1+k2);
y=k2+1;
break;
case 1:
x=-(k2+1);
y=b;
break;
case 2:
x=-b;
y=b-(k2+1);
break;
case 3:
x=k2+1-b;
y=-(k2+1);
break;
case 4:
x=k2+1;
y=-b;
break;
case 5:
x=b;
y=k2+1-b;
break;
}
//cout<<x<<" "<<y<<endl;
l.push_back(x);l.push_back(y);

}
for(I=l.begin();I!=l.end();I++){
cout<<*I<<" ";
I++;
cout<<*I<<"\n";

}
return 0;
}

Fatal_eror
New poster
Posts: 1
Joined: Fri Nov 13, 2009 11:34 am

10182- Bee Maja Runtime Error

Post by Fatal_eror »

Hi,

I've been getting Runtime Errors for the Bee Maja problem. I cannot figure out what I am doing wrong though. Any suggestions?

Code: Select all

import java.util.Scanner;

class BeeMaja
{

    public static void main(String[] args) throws Exception
    {
        Scanner in = new Scanner(System.in);

        while(in.hasNextInt())
        {
            int coord = in.nextInt();
            int[] resultCoord = convertCoord(coord);
            System.out.println(resultCoord[0]+ " " + resultCoord[1]);
        }
        in.close();
        System.exit(0);
        return;
    }

    private static int[] convertCoord(int coord)
    {
        int[] converted = new int[2];

        int ringNumber = 0, i;

        for(i = 0; 6 * i + 1 < coord; i+=ringNumber)
        {
            ringNumber ++;
        }

        int ringMax = 6 * i + 1;

        converted[0] = ringNumber;

        for(i = 0; i < ringNumber && ringMax > coord; i++)
        {
            converted[1]--;
            ringMax--;
        }
        for(i = 0; i < ringNumber && ringMax > coord; i++)
        {
            converted[0]--;
            ringMax--;
        }
        for(i = 0; i < ringNumber && ringMax > coord; i++)
        {
            converted[0]--;
            converted[1]++;
            ringMax--;
        }
        for(i = 0; i < ringNumber && ringMax > coord; i++)
        {
            converted[1]++;
            ringMax--;
        }
        for(i = 0; i < ringNumber && ringMax > coord; i++)
        {
            converted[0]++;
            ringMax--;
        }
        for(i = 0; i < ringNumber && ringMax > coord; i++)
        {
            converted[0]++;
            converted[1]--;
            ringMax--;
        }

        return converted;
    }

}

Post Reply

Return to “Volume 101 (10100-10199)”