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

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

Re: 10589 - Area

Post by hoimo » Tue Jan 14, 2014 11:14 pm

@ brianfry713, plz help.
i am getting WA in this problem.
but i cant find my problem.
thanx in advance.

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

Re: 10589 - Area

Post by brianfry713 » Wed Jan 15, 2014 11:59 pm

Try solving it without using floating point.
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 » Fri Jan 17, 2014 9:38 pm

many many thnx & sorry 4 my late rply.
:)

nada_elnokaly
New poster
Posts: 3
Joined: Thu Oct 23, 2014 12:29 am

Re: 10589 - Area

Post by nada_elnokaly » Mon Jul 13, 2015 4:48 pm

I need help please ,getting so many WA's and can't understand why !!

Code: Select all

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll shift=1e7;

struct point{
    ll x,y;
    point(){}
    point(ll x,ll y):x(x),y(y){}
};
 ll dist(point a,point b){
    ll x=abs(a.x-b.x);
    ll y=abs(a.y-b.y);
    return x*x+y*y;
}
int len(ll x){
    if(!x)return 1;
    int ret=0;
    while(x)x/=10,ret++;
    return ret;
}
int main(){
    ll N,a;
    while(true){
        cin>>N>>a;
        a*=shift;
        if(!N)return 0;

        ll M=0;
        point temp;
        for(int i=0;i<N;i++){
           double d1,d2;
           cin>>d1>>d2;

            temp.x=(ll)(d1*shift);
            temp.y=(ll)(d2*shift);

            ll dist1=dist(point(0,0),temp);
            ll dist2=dist(point(0,a),temp);
            ll dist3=dist(point(a,0),temp);
            ll dist4=dist(point(a,a),temp);
            ll D=a*a;
            if(dist1<=D && dist2<=D && dist3<=D && dist4<=D )M++;

        }
        ll A = M * a/shift * a/shift;

        printf("%lld.",A/N);

        int dec=0;
        ll res2=A%N;
        int len1=len(N)-1;
        int len2=len(res2);

        for(int i=0;i<len1-len2;i++)printf("0"),dec++;
        printf("%lld",A%N),dec+=len(A%N);
        for(int i=0;i<5-dec;i++)printf("0");
        printf("\n");

    }
    return 0;
}

Post Reply

Return to “Volume 105 (10500-10599)”