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

穷举所有的N个点吗?然后算出其他的点和它的角度,按角度排序,我还是超时……(代码在内,如何进一步优化)

Posted by zerocool_08 at 2006-03-24 18:41:43 on Problem 2737
In Reply To:极角排序,O(n^2lgn) Posted by:frkstyc at 2006-03-24 17:05:23
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#define INF 1000000
int x[1000],y[1000],n;
double agr[1000];
int cmp(const void *p1,const void *p2){
    if(*(double *)p1 > *(double *)p2)
        return 1;
    return -1;
}
int dfs(int k){
     int i,j,now,max;
     double val;
     for(i=0,j=0;i<n;i++){
         if(i!=k){
            if(x[i]==x[k])
               agr[j++]=INF;
            else
               agr[j++]=(double)(y[k]-y[i])/(x[k]-x[i]);
         }
     }
     qsort(agr,n-1,sizeof(double),cmp);
     now=1,max=0,val=agr[0];
     for( i=1;i<n-1;i++){
         if(fabs(val-agr[i])<0.000001)
             now++;
         else{
             max=max>now? max:now;
             now=1;
             val=agr[i];
         }
     }
	 if(max<now) max=now;
     return max;
}
     
            
int main(void)
{
    int  cs=1,i,max,now;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    while( scanf("%d",&n)==1&&n){
           for(i=0;i<n;i++)
              scanf("%d %d",&x[i],&y[i]);
         
           for(i=0,max=0;i<n;i++){
                now=dfs(i);
                max=max>now? max:now;
           }
           max++;
           if(max<4) max=0;
           printf("Photo %d: %d points eliminated\n",cs++,max);
    }
	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