Page 1 of 1

10182 - Bee Maja

Posted: Mon Jan 06, 2003 10:05 am
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

10182-Bee problem

Posted: Sun Jan 30, 2005 9:52 pm
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.

Posted: Mon Jan 31, 2005 3:48 am
by Zuberul
had a little problem.
Got accepted. :P

10182 - bee maja

Posted: Sun Jun 12, 2005 7:26 pm
by Nemo
Can anyone give me any hint on this?
Is there a simple formula?

Posted: Mon Jun 13, 2005 7:28 am
by shamim
It can be solved by simulation.
Draw the system on a rectangular grid , you should be able to spot a pattern.

Posted: Mon Jun 13, 2005 3:53 pm
by Nemo
Thank you.
I got AC with your suggestion.
It seems there is no simple way other than simulation.

Posted: Thu Mar 23, 2006 10:56 pm
by WRJ
In my opinion you shouldn't use fopen and fprintf function.

Posted: Sun Jun 25, 2006 6:37 pm
by Raiyan Kamal
There is a simple way for this problem. You can convert the coordinates using simple mathematical operations, simulation is not necessery.

10182-BeeMaja

Posted: Mon Oct 12, 2009 10:59 am
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;
}

10182- Bee Maja Runtime Error

Posted: Fri Nov 13, 2009 11:38 am
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;
    }

}