10589 - Area

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

Moderator: Board moderators

User avatar
CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

Post by CodeMaker » Tue Jul 04, 2006 6:13 am

Hi, i am confused with this problem.

i read the posts in here. but couldn't figure out what is wrong. i got WA for more than 10 times.

i am considering that all the point coordinates has 7 digits after the decimal point ( as the problem statement says)

can anyone point out my mistake?

thanks...

Code: Select all

int n,a;


void process()
{
	int i,j;
	int cnt=0;
	char xx[30],yy[30];
	unsigned long long px,py,radius,c1x,c1y,c2x,c2y,c3x,c3y,c4x,c4y,d1,d2,d3,d4,first,last;

	radius = a * 10000000;

	c1x = 0;
	c1y = 0;
	c2x = radius;
	c2y = 0;
	c3x = radius;
	c3y = radius;
	c4x = 0;
	c4y = radius;

	for(i=0;i<n;i++)
	{
		px = py = 0;
		scanf("%s%s",xx,yy);

		for(j=0;xx[j];j++)
		{
			if(isdigit(xx[j]))
				px = px*10+(xx[j]-'0');
		}

		for(j=0;yy[j];j++)
		{
			if(isdigit(yy[j]))
				py = py*10+(yy[j]-'0');
		}

		d1 = (px - c1x)*(px - c1x) + (py - c1y)*(py - c1y);
		d2 = (px - c2x)*(px - c2x) + (py - c2y)*(py - c2y);
		d3 = (px - c3x)*(px - c3x) + (py - c3y)*(py - c3y);
		d4 = (px - c4x)*(px - c4x) + (py - c4y)*(py - c4y);

		if(d1<=radius * radius && d2<=radius * radius && d3<= radius * radius && d4<=radius * radius)
			cnt++;
		
	}

	first = cnt * a * a / n;
	last = cnt * a * a % n;

	printf("%llu.%llu",first,last);

	int digcnt=1;

	while(last>=10)
	{
		digcnt++;
		last/=10;
	}

	for(i=0;i<5-digcnt;i++)
		putchar('0');
	printf("\n");


}


int main(void)
{
	freopen("in.in","r",stdin);
//	freopen("out.txt","w",stdout);

	int cases=1;


	while(scanf("%d%d",&n,&a)==2)
	{
		if(n==0)
			break;

		process();
	}

	
	return 0;
}
Jalal : AIUB SPARKS

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko » Sun Jul 23, 2006 11:59 pm

CodeMaker wrote:Hi, i am confused with this problem.
i read the posts in here. but couldn't figure out what is wrong. i got WA for more than 10 times.
If cnt*a*a/n=10.0047, you write 10.47000 instead of 10.00470. Check tho following part of the code:
your code wrote:........first = cnt * a * a / n;
........last = cnt * a * a % n;

........printf("%llu.%llu",first,last);

........int digcnt=1;

........while(last>=10)
........{
................digcnt++;
................last/=10;
........}

........for(i=0;i<5-digcnt;i++)
................putchar('0');
........printf("\n");

User avatar
CodeMaker
Experienced poster
Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm
Location: AIUB, Bangladesh

Post by CodeMaker » Wed Aug 02, 2006 2:34 pm

Hi martin, thanks for the reply. ya, that is wrong. as i was confused by the previous posts and was getting lot of wa's , so i tried many thing. and i guess i have completed half century of WA for this problem. now i want to put it away. may be i am missing something small and sily, but looks like it is beyond my vision and i will never find it. this is my final code. if anyone notice any mistake and informs me, then thanks to him. but i have really lost interest on this problem

Code: Select all

int n,a;


void process()
{
	
	int i;
	dPoint p;   // a point class that has double perameters (x,y)
	long long r = a * 10000000,aa = a*10000000,px,py,d,m;
	r *= r;


	int cnt=0;
	for(i=0;i<n;i++)
	{
		scanf("%lf%lf",&p.x,&p.y);

		px = p.x * 10000000 ;
		py = p.y * 10000000 ;

		if(px * px + py * py <= r)
			if( px * px + (py - aa) * (py - aa) <=r)
				if( (px - aa) * (px - aa) + py * py <= r)
					if( (px - aa)*(px - aa) + (py - aa)*(py - aa) <=r)
						cnt++;

	}


	d = m = cnt;

	d = d*a*a;
	m = m*a*a;

	d/=n;
	m%=n;

	printf("%lld.",d);


	for(i=(int)(log10((double)(m)))+1;i<(int)(log10((double)(n)));i++)
		putchar('0');

	printf("%lld",m);

	for(i=(int)(log10((double)(n)))+1;i<=5;i++)
		putchar('0');

	putchar('\n');

	
}


int main(void)
{
	freopen("in.in","r",stdin);
//	freopen("out.txt","w",stdout);

	int cases=1;


	while(scanf("%d%d",&n,&a)==2)
	{
		if(n==0)
			break;

		process();
	}

	
	return 0;
}
:evil: :evil:
Jalal : AIUB SPARKS

User avatar
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko » Sat Aug 05, 2006 3:45 am

CodeMaker wrote:Hi martin, thanks for the reply. ya, that is wrong. as i was confused by the previous posts and was getting lot of wa's , so i tried many thing. and i guess i have completed half century of WA for this problem. now i want to put it away. may be i am missing something small and sily, but looks like it is beyond my vision and i will never find it. this is my final code. if anyone notice any mistake and informs me, then thanks to him. but i have really lost interest on this problem
I don't thing the following part of your code is precise enough:
your code wrote:...for(i=(int)(log10((double)(m)))+1;i<(int)(log10((double)(n)));i++)
......putchar('0');

...printf("%lld",m);

...for(i=(int)(log10((double)(n)))+1;i<=5;i++)
......putchar('0');.
Think about some other (and more precise) way to measure length of an integer.

ashikzinnatkhan
New poster
Posts: 8
Joined: Wed Jan 25, 2006 6:25 pm
Location: Dhaka, Bangladesh

Post by ashikzinnatkhan » Sun Nov 19, 2006 9:58 am

Hi,
I am really bored with this problem.
I have read all the posts and my code also gives correct output
(i think!!!:oops: ). But it is producing WA again and again and again.........
Can anyone help me finding my mistake, please.

My code is:

Code: Select all

#include <stdio.h>
#include <string.h>

//typedef __int64 BIG;



long long dis(long long x1,long long y1,long long x2, long long y2)
{
	return ( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
}

main()
{
	long long len,n,i,j,k,m,a,x,y,x1,y1,d1,d2,d3,d4,area,max;
	char out[200],t[200],N[200];

	while( scanf("%lld %lld",&n,&a) == 2 )
	{
		if(n == 0) break;

		m = 0;

		max = a*a*10000000*10000000;


		for(i=0; i<n; i++)
		{
			scanf("%lld%*c%lld %lld%*c%lld",&x,&x1,&y,&y1);

			x = x*10000000 + x1;
			y = y*10000000 + y1;


			d1 = dis(0,0,x,y);
			d2 = dis(a,0,x,y);
			d3 = dis(a,a,x,y);
			d4 = dis(0,a,x,y);

			if(d1 <= max && d2 <= max && d3 <= max && d4 <= max) m++;
		
		}


		area = m * a * a;
	
	
		sprintf(N,"%lld",n);
		len = strlen(N) - 1;

		sprintf(t,"%lld",area);

		j = strlen(t);

		for(i=0; i<len; i++,j--);

		for(k=strlen(t),i=0; i<10; i++) t[k+i] = '0';  
		
		for(i=0; i<j; i++) out[i] = t[i];

		out[i] = '.';

		for(k=0; k<5; k++) out[i+k+1] = t[i+k];
		
		out[i+k+1] = '\0';

		printf("%s\n",out);

		
	}

}
Ashik

User avatar
kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

Re: 10589 - Area

Post by kbr_iut » Sat Feb 14, 2009 12:26 am

got AC using double...Judge data is okay now.
Last edited by kbr_iut on Sun Feb 15, 2009 6:25 pm, edited 1 time in total.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................

Moshiur Rahman
New poster
Posts: 13
Joined: Mon Sep 08, 2008 6:57 pm
Location: State University of Bangladesh

Re: 10589 - Area

Post by Moshiur Rahman » Sat Feb 14, 2009 7:38 pm

You don't need to use this complex and error prone long long method any more...
The very straightforward approach using doubles is enough to get AC. I think the judge data is ok now :)
Never think too hard, let ideas come to you...

User avatar
kbr_iut
Experienced poster
Posts: 103
Joined: Tue Mar 25, 2008 11:00 pm
Location: IUT-OIC, DHAKA, BANGLADESH
Contact:

Re: 10589 - Area

Post by kbr_iut » Sun Feb 15, 2009 6:19 pm

thnx "Moshiur Rahman"
u r right. judge data is okay now. and I got AC with double.
It is tough to become a good programmer.
It is more tough to become a good person.
I am trying both...............................

ajmer
New poster
Posts: 7
Joined: Thu Mar 07, 2013 2:16 am

Re: 10589 - Area

Post by ajmer » Fri Mar 08, 2013 1:30 am

Why am I getting runtime error? Code in C. Thanks for help.

Code: Select all

solved
Last edited by ajmer on Sun Mar 10, 2013 5:59 pm, edited 1 time in total.

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

Re: 10589 - Area

Post by brianfry713 » Fri Mar 08, 2013 10:16 pm

Try adding "return 0;" at the end of your code.
Check input and AC output for thousands of problems on uDebug!

ajmer
New poster
Posts: 7
Joined: Thu Mar 07, 2013 2:16 am

Re: 10589 - Area

Post by ajmer » Sun Mar 10, 2013 5:58 pm

Wow, how did I forget about that, thanks.

ajmer
New poster
Posts: 7
Joined: Thu Mar 07, 2013 2:16 am

Re: 10589 - Area

Post by ajmer » Sun Mar 10, 2013 6:42 pm

But now I don't know why I'm getting WA. Am I using a wrong algorithm? Thanks in advance.

Code in C.

Code: Select all

#include <stdio.h>

int main()
{
    int n,a,m,i;
    double x,y,p,odla,odlb,odlc,odld;
    scanf("%d %d",&n,&a);
    while (n!=0)
    {
        m=0;
        for (i=0;i<n;i++)
        {
            scanf("%lf %lf",&x,&y);
            odla=x*x+y*y;
            odlb=(x-a)*(x-a)+y*y;
            odlc=(x-a)*(x-a)+(y-a)*(y-a);
            odld=x*x+(y-a)*(y-a);
            if ((odla<=a*a)&&(odlb<=a*a)&&(odlc<=a*a)&&(odld<=a*a)) m++;
        }
        p=m*a*a/n;
        printf("%.5lf\n",p);
        scanf("%d %d",&n,&a);
    }
    return 0;
}

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

Re: 10589 help

Post by brianfry713 » Tue Mar 12, 2013 10:55 pm

The input posted by Martin Macko isn't valid.
"Each of the next N lines contains two floating-point numbers, which indicates the coordinate of a point. These floating-point numbers always have seven digits after the decimal point"
It should read:

Code: Select all

10 11
5.5000000 5.5000000
5.5000000 5.5000000
0.0000000 0.0000000
0.0000000 0.0000000
0.0000000 0.0000000
0.0000000 0.0000000
0.0000000 0.0000000
0.0000000 0.0000000
0.0000000 0.0000000
0.0000000 0.0000000
0 0
The output should be

Code: Select all

24.20000
Check input and AC output for thousands of problems on uDebug!

hoimo
New poster
Posts: 18
Joined: Sun Sep 23, 2012 3:43 am

Re: 10589 - Area

Post by hoimo » Mon Jan 06, 2014 1:53 pm

Why submiision err? plz help.

Code: Select all

#include<stdio.h>
#include<math.h>
int main()
{
    int N, a, i, M, sq;
    double x, y;
    double hf, rt, minusrt;

    while( scanf("%d %d", &N, &a)==2 && N!=0 )
    {
        M=0;
        sq=a*a;
        for( i=0;i<N;i++ ){
            scanf("%lf %lf", &x, &y);

            hf=a/2;
            rt=sqrt( a*a-hf*hf );
            minusrt=a-rt;

            if( x<=rt && x>=minusrt ){
                if( y<=rt && y>=minusrt ){
                    M++;
                }
            }
        }

        printf( "%.5lf\n",(double)M*a*a/N );
    }
}

hoimo
New poster
Posts: 18
Joined: Sun Sep 23, 2012 3:43 am

Re: 10589 - Area

Post by hoimo » Mon Jan 13, 2014 9:34 am

plz reply:(

Post Reply

Return to “Volume 105 (10500-10599)”