Problem:
Longest Lane

Mr. KM, the mayor of KM city, decided to build a new elementary school.
The site for the school has an awkward polygonal shape, which caused several problems.
The most serious problem was that there was not enough space for a short distance racetrack.
Your task is to help Mr. KM to calculate the maximum possible length for the racetrack
that can be built in the site.
The track can be considered as a straight line segment whose width can be ignored.
The boundary of the site has a simple polygonal shape without self-intersection,
and the track can touch the boundary.
Note that the boundary might not be convex.

Input

The input consists of multiple test cases, followed by a line containing "0".
Each test case has the following format.
The first line contains an integer N (3 \leq N \leq 100).
Each of the following N lines contains two integers x_i and y_i (-1,000 \leq x_i, y_i \leq 1,000),
which describe the coordinates of a vertex of the polygonal border of the site, in counterclockwise order.

Output

For each test case, print its case number and the maximum possible length of the track in a line.
The answer should be given as a floating point number with an absolute error of at most 10^{-6}.

Sample Input

4
0 0
10 0
10 10
0 10
3
0 0
1 0
0 1
0

Output for the Sample Input

Case 1: 14.142135624
Case 2: 1.41421356

Solution in C++ (judge verdict: Wrong Answer)

#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1 
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;

class Point{
public:
  double x,y;

  Point(double x = 0,double y = 0): x(x),y(y){}

  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  Point operator * (Point a){ return Point(x * a.x - y * a.y, x * a.y + y * a.x); }

  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:y<p.y; }

  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }

};

struct Segment{
  Point p1,p2;
  Segment(Point p1 = Point(),Point p2 = Point()):p1(p1),p2(p2){}
  bool operator == (const Segment& p)const { return p.p1 == p1 && p.p2 == p2; }
};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;

ostream& operator << (ostream& os,const Point& a){ os << "(" << a.x << "," << a.y << ")"; }

ostream& operator << (ostream& os,const Segment& a){ os << "( " << a.p1 << " , " << a.p2 << " )"; }

double dot(Point a,Point b){ return a.x*b.x + a.y*b.y; }

double cross(Point a,Point b){ return a.x*b.y - a.y*b.x; }

double norm(Point a){ return a.x*a.x+a.y*a.y; }

double abs(Point a){ return sqrt(norm(a)); }

//rad は角度をラジアンで持たせること
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }

// 度をラジアンに変換
double toRad(double agl){ return agl*M_PI/180.0; }

// a => prev, b => cur, c=> next
// prev から cur へ行って next へ行く際の角度を求める
double getArg(Point a,Point b,Point c){
  double arg1 = atan2(b.y-a.y,b.x-a.x);
  double arg2 = atan2(c.y-b.y,c.x-b.x);
  double arg = fabs( arg1 - arg2 );
  while( arg > M_PI ) arg -= 2.0 * M_PI;
  return fabs(arg);
}

int ccw(Point p0,Point p1,Point p2){
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS)return CLOCKWISE;
  if(dot(a,b) < -EPS)return ONLINE_BACK;
  if(norm(a) < norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}

double cross3p(Point p,Point q,Point r){ return (r.x-q.x) * (p.y -q.y) - (r.y - q.y) * (p.x - q.x); }
  
bool collinear(Point p,Point q,Point r){ return fabs(cross3p(p,q,r)) < EPS; }
  
bool ccwtest(Point p,Point q,Point r) { return cross3p(p,q,r) > 0; }
 
bool onSegment(Point p,Point q,Point r){
  return collinear(p,q,r) && equals(sqrt(pow(p.x-r.x,2)+pow(p.y-r.y,2)) + sqrt(pow(r.x-q.x,2) + pow(r.y-q.y,2) ),sqrt(pow(p.x-q.x,2)+pow(p.y-q.y,2)) ) ;
}
  

bool intersectSS(Line s, Line t) {
  return ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2) <= 0 &&
         ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2) <= 0;
}

const int MAX_N = 200;
int N;
Point ps[MAX_N];

int main(){
  int CNT = 1;
  while( cin >> N, N ) {
    rep(i,N) cin >> ps[i].x >> ps[i].y;
    cout << "Case " << CNT++ << ": ";
    double maxi = 0;
    rep(i,N) REP(j,i+1,N) {
      Segment seg = Segment(ps[i],ps[j]);
      bool ok = true;
      rep(k,N) {
        if( onSegment(seg.p1,seg.p2,ps[k]) || onSegment(seg.p1,seg.p2,ps[(k+1)%N]) ) continue;
        if( intersectSS(seg,Segment(ps[k],ps[(k+1)%N])) ) { ok = false; break; }
      }
      if( ok ) maxi = max(maxi,abs(seg.p1-seg.p2));
    }
    printf("%.8lf\n",maxi);
  }
  return 0;
}