ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1103. Pencils and Circles

Why could I get wa? My algo is right, I can bet!!
Posted by Innovative Cat. 11 Jan 2003 18:37
I even have closed qsort procedure.. If anybody could help
me, please write to zhuzeyuan@hotmail.com. In return for
this, I could help you with any program of problems from
1000 to 1102...


#include <fstream.h>
#include <math.h>

//ifstream Fin("1103.in");
//ofstream Fou("1103.out");
#define Fin cin
#define Fou cout

const int MaxN = 5000 + 10;
const double Error = 1e-7;

struct TPoint
{
    int x,y;
} p[MaxN], A, B;
int n;
double angle[MaxN];
int num[MaxN];

/*void qsort(int l, int r)
{
    int i = l, j = r; double x = angle[(l+r)/2];
    while (i<=j)
    {
        while (angle[i]<x-Error) i++;
        while (x<angle[j]-Error) j--;
        if (i<=j)
        {
            double y = angle[i];
            angle[i] = angle[j];
            angle[j] = y;
            int t = num[i];
            num[i] = num[j];
            num[j] = t;
            i++; j--;
        }
    }
    if (l<j) qsort(l,j);
    if (i<r) qsort(i,r);
}

void cp(struct TPoint *a, struct TPoint b)
{
    (*a).x = b.x;
    (*a).y = b.y;
}*/

int main()
{
    Fin>>n;
    int i;
    for (i=1; i<=n; i++)
        Fin>>p[i].x>>p[i].y;
    int min=0x7FFFFFFF, dir;
    for (i=1; i<=n; i++)
        if (p[i].x<min)
        {
            min = p[i].x;
            dir = i;
        }
    p[0].x = p[1].x;
    p[0].y = p[1].y;
    p[1].x = p[dir].x;
    p[1].y = p[dir].y;
    p[dir].x = p[0].x;
    p[dir].y = p[0].y;
//    cp(&p[0],p[1]);
//    cp(&p[1],p[dir]);
//    cp(&p[dir],p[0]);
    double max = -1e100;
    for (i=2; i<=n; i++)
        if (atan2((double)(p[i].y-p[1].y),(double)(p
[i].x-p[1].x))>max)
        {
            max = atan2((double)(p[i].y-p[1].y),
(double)(p[i].x-p[1].x));
            dir = i;
        }
    p[0].x = p[2].x;
    p[0].y = p[2].y;
    p[2].x = p[dir].x;
    p[2].y = p[dir].y;
    p[dir].x = p[0].x;
    p[dir].y = p[0].y;
//    cp(&p[0],p[2]);
//    cp(&p[2],p[dir]);
//    cp(&p[dir],p[0]);
    A.x = p[1].x;
    A.y = p[1].y;
    B.x = p[2].x;
    B.y = p[2].y;
    double c = sqrt(pow(B.x-A.x,2)+pow(B.y-A.y,2));
    for (i=3; i<=n; i++)
    {
        double a = sqrt(pow(B.x-p[i].x,2)+pow(B.y-p
[i].y,2));
        double b = sqrt(pow(A.x-p[i].x,2)+pow(A.y-p
[i].y,2));
        angle[i] = acos((a*a+b*b-c*c)/(2*a*b));
        num[i] = i;
    }
//    qsort(3,n);
    int j;
    for (i=3; i<=n; i++)
        for (j=i+1; j<=n; j++)
            if (angle[i]>angle[j])
            {
                double y = angle[i];
                angle[i] = angle[j];
                angle[j] = y;
                int t = num[i];
                num[i] = num[j];
                num[j] = t;
            }
    Fou<<A.x<<' '<<A.y<<endl<<B.x<<' '<<B.y<<endl;
    Fou<<p[num[(3+n)/2]].x<<' '<<p[num[(3+n)/2]].y<<endl;
    return 0;
}
The test datas might be wrong. I have WAed for 50 times.
Posted by Innovative Cat. 11 Jan 2003 18:40
> I even have closed qsort procedure.. If anybody could help
> me, please write to zhuzeyuan@hotmail.com. In return for
> this, I could help you with any program of problems from
> 1000 to 1102...
>
>
> #include <fstream.h>
> #include <math.h>
>
> //ifstream Fin("1103.in");
> //ofstream Fou("1103.out");
> #define Fin cin
> #define Fou cout
>
> const int MaxN = 5000 + 10;
> const double Error = 1e-7;
>
> struct TPoint
> {
>     int x,y;
> } p[MaxN], A, B;
> int n;
> double angle[MaxN];
> int num[MaxN];
>
> /*void qsort(int l, int r)
> {
>     int i = l, j = r; double x = angle[(l+r)/2];
>     while (i<=j)
>     {
>         while (angle[i]<x-Error) i++;
>         while (x<angle[j]-Error) j--;
>         if (i<=j)
>         {
>             double y = angle[i];
>             angle[i] = angle[j];
>             angle[j] = y;
>             int t = num[i];
>             num[i] = num[j];
>             num[j] = t;
>             i++; j--;
>         }
>     }
>     if (l<j) qsort(l,j);
>     if (i<r) qsort(i,r);
> }
>
> void cp(struct TPoint *a, struct TPoint b)
> {
>     (*a).x = b.x;
>     (*a).y = b.y;
> }*/
>
> int main()
> {
>     Fin>>n;
>     int i;
>     for (i=1; i<=n; i++)
>         Fin>>p[i].x>>p[i].y;
>     int min=0x7FFFFFFF, dir;
>     for (i=1; i<=n; i++)
>         if (p[i].x<min)
>         {
>             min = p[i].x;
>             dir = i;
>         }
>     p[0].x = p[1].x;
>     p[0].y = p[1].y;
>     p[1].x = p[dir].x;
>     p[1].y = p[dir].y;
>     p[dir].x = p[0].x;
>     p[dir].y = p[0].y;
> //    cp(&p[0],p[1]);
> //    cp(&p[1],p[dir]);
> //    cp(&p[dir],p[0]);
>     double max = -1e100;
>     for (i=2; i<=n; i++)
>         if (atan2((double)(p[i].y-p[1].y),(double)(p
> [i].x-p[1].x))>max)
>         {
>             max = atan2((double)(p[i].y-p[1].y),
> (double)(p[i].x-p[1].x));
>             dir = i;
>         }
>     p[0].x = p[2].x;
>     p[0].y = p[2].y;
>     p[2].x = p[dir].x;
>     p[2].y = p[dir].y;
>     p[dir].x = p[0].x;
>     p[dir].y = p[0].y;
> //    cp(&p[0],p[2]);
> //    cp(&p[2],p[dir]);
> //    cp(&p[dir],p[0]);
>     A.x = p[1].x;
>     A.y = p[1].y;
>     B.x = p[2].x;
>     B.y = p[2].y;
>     double c = sqrt(pow(B.x-A.x,2)+pow(B.y-A.y,2));
>     for (i=3; i<=n; i++)
>     {
>         double a = sqrt(pow(B.x-p[i].x,2)+pow(B.y-p
> [i].y,2));
>         double b = sqrt(pow(A.x-p[i].x,2)+pow(A.y-p
> [i].y,2));
>         angle[i] = acos((a*a+b*b-c*c)/(2*a*b));
>         num[i] = i;
>     }
> //    qsort(3,n);
>     int j;
>     for (i=3; i<=n; i++)
>         for (j=i+1; j<=n; j++)
>             if (angle[i]>angle[j])
>             {
>                 double y = angle[i];
>                 angle[i] = angle[j];
>                 angle[j] = y;
>                 int t = num[i];
>                 num[i] = num[j];
>                 num[j] = t;
>             }
>     Fou<<A.x<<' '<<A.y<<endl<<B.x<<' '<<B.y<<endl;
>     Fou<<p[num[(3+n)/2]].x<<' '<<p[num[(3+n)/2]].y<<endl;
>     return 0;
> }
>