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

Common Board

What's wrong on my program, Problem 1111 (+)????????
Posted by Miguel Angel 2 Feb 2002 10:25
#include<iostream.h>
#include<math.h>

struct point {
    float x,y;
}  p[100][2];
point q;
float min[100];
short N;
short name[100];

float dist(point a, point b)
{
    double x = (a.x-b.x)*(a.x-b.x);
    double y = (a.y-b.y)*(a.y-b.y);
return sqrt(x+y);
}

void main()
{
short i, j;
point d;
char  joinx, joiny;
    cin>>N;
    for (i=0; i<N; i++)
        cin>>p[i][0].x>>p[i][0].y>>p[i][1].x>>p[i][1].y;
    cin>>q.x>>q.y;
    for (i=0; i<N; i++)
    {
        if (p[i][0].x<p[i][1].x) joinx = (p[i][0].x<=q.x &&
q.x<=p[i][1].x);

else joinx = (p[i][1].x<=q.x && q.x<=p[i][0].x);
        if (p[i][0].y<p[i][1].y) joiny = (p[i][0].y<=q.y &&
q.y<=p[i][1].y);

else joiny = (p[i][1].y<=q.y && q.y<=p[i][0].y);
        if (abs(q.x-p[i][0].x) < abs(q.x-p[i][1].x)) d.x = p
[i][0].x;

                             else d.x = p
[i][1].x;
        if (abs(q.y-p[i][0].y) < abs(q.y-p[i][1].y)) d.y = p
[i][0].y;

                             else d.y = p
[i][1].y;
        if (joinx && joiny)
        {
            min[i] = 0;
            continue;
        }
        if (joinx)
        {
            min[i] = abs(d.y - q.y);
            continue;
        }
        if (joiny)
        {
            min[i] = abs(d.x - q.x);
            continue;
        }
        min[i] = dist(d,q);
    }
    for (i=0; i<N; i++) name[i] = i;
float m;
short n;
    for (i=1; i<N; i++)
        for (j=i; j>0; j--)
            if (min[j]<min[j-1])
            {
                m = min[j],min[j]=min[j-1], min[j-1]
= m;
                n=name[j],name[j]=name[j-1],name[j-1]
=n;
            }
    for (i=0; i<N; i++)
        cout<<(name[i]+1)<<" ";
}
There are squares with sides not parralel to axes(+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 2 Feb 2002 23:09
See at this:

  / /  /    \    /
 \  /
  \/

May be it is not a square, but I think that you can imagine that I
want to say.

If you need more help you can e-mail to me nsc2001@rambler.ru

But I didn't solved this problem (I get WA with program(i think that
it's rigth) 4 kByte )