Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁帮忙看下,讨论里面的所有数据都过了,还是WA。。。

Posted by keycobing at 2012-12-24 00:17:49 on Problem 2187
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define MAX 50006

struct Point{
       int x;
       int y;
};
Point zero;

inline int dist(Point &P1, Point &P2)
{
       return (P1.x-P2.x)*(P1.x-P2.x)+(P1.y-P2.y)*(P1.y-P2.y);
}
inline int Product(Point &A, Point &B, Point &C)
{
       return (A.x*B.y + B.x*C.y + C.x*A.y - A.x*C.y - B.x*A.y - C.x*B.y);
}

bool compare_point(Point P1, Point P2)
{
       double a1 = atan((double)(P1.y-zero.y)/(P1.x-zero.x));
       double a2 = atan((double)(P2.y-zero.y)/(P2.x-zero.x));

       if(a1 == a2)
              return dist(P1,zero) < dist(P2,zero);
       else
              return a1 < a2;

}

int main()
{
    int N,min;
    Point input[MAX];
    Point stack[MAX];
    int sp;
    while(cin >> N)
    {
           min = 0;
           sp = 1;
           //memset(input, 0, sizeof(input));
           //memset(stack, 0, sizeof(stack));
           cin >> zero.x >> zero.y;
           for(int i = 1; i < N; i++)
           {
                 cin >> input[i].x >> input[i].y;
                 if((input[i].y < zero.y) || (input[i].y == zero.y && input[i].x < zero.x))
                     swap(zero, input[i]);
           }

           sort(input+1, input+N-1, compare_point);

           //cout << "sorted:" << endl;
           //cout << zero.x << " " << zero.y << endl;
           //for(int i = 1; i < N; i++)
             // cout << input[i].x <<" " << input[i].y  << endl;

           stack[0] = input[N-1];
           stack[1] = zero;

           for(int i = 1; i < N-1; i++)
           {
              if(Product(stack[sp-1], stack[sp], input[i]) >= 0)
                     stack[++sp] = input[i];
              else
                     --sp;
           }

          // cout << "stack:" << sp << endl;
          // for(int i =0;i <=sp;i++)
           //   cout << stack[i].x <<" " << stack[i].y << endl;

           int maxdist = 0;
           for(int i = 0; i < sp; i++)
              for(int j = i+1; j <= sp; j++)
              {
                     int temp = dist(stack[i], stack[j]);
                     if(temp > maxdist)
                            maxdist = temp;
              }
           cout << maxdist << endl;
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator