Page 3 of 4
Posted: Tue Jul 04, 2006 6:13 am
by CodeMaker
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;
}
Posted: Sun Jul 23, 2006 11:59 pm
by Martin Macko
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");
Posted: Wed Aug 02, 2006 2:34 pm
by CodeMaker
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;
}

Posted: Sat Aug 05, 2006 3:45 am
by Martin Macko
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.
Posted: Sun Nov 19, 2006 9:58 am
by ashikzinnatkhan
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);
}
}
Re: 10589 - Area
Posted: Sat Feb 14, 2009 12:26 am
by kbr_iut
got AC using double...Judge data is okay now.
Re: 10589 - Area
Posted: Sat Feb 14, 2009 7:38 pm
by Moshiur Rahman
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

Re: 10589 - Area
Posted: Sun Feb 15, 2009 6:19 pm
by kbr_iut
thnx "Moshiur Rahman"
u r right. judge data is okay now. and I got AC with double.
Re: 10589 - Area
Posted: Fri Mar 08, 2013 1:30 am
by ajmer
Why am I getting runtime error? Code in C. Thanks for help.
Re: 10589 - Area
Posted: Fri Mar 08, 2013 10:16 pm
by brianfry713
Try adding "return 0;" at the end of your code.
Re: 10589 - Area
Posted: Sun Mar 10, 2013 5:58 pm
by ajmer
Wow, how did I forget about that, thanks.
Re: 10589 - Area
Posted: Sun Mar 10, 2013 6:42 pm
by ajmer
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;
}
Re: 10589 help
Posted: Tue Mar 12, 2013 10:55 pm
by brianfry713
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
Re: 10589 - Area
Posted: Mon Jan 06, 2014 1:53 pm
by hoimo
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 );
}
}
Re: 10589 - Area
Posted: Mon Jan 13, 2014 9:34 am
by hoimo
plz reply:(