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

so easy a problem... but take me much time morose!!!

Posted by zsl2007 at 2006-01-10 22:28:50 on Problem 2695
It is my programme:

#include<stdio.h>
#include<math.h>
#define maxlong 101
double fsx,fsy,D;
int total,start;
typedef struct sit
 {
	 double x;
	 double y;
	 };
	 
sit sits[maxlong];
sit fs;
sit zero; 
sit tempvet;
int use[maxlong];	 
sit vert(sit m,sit n)
 {  
	 sit temp;
	 temp.x=m.x-n.x;
	 temp.y=m.y-n.y;
	 return temp;
	 }
	 
double angle(sit a,sit b)
 {
	 return a.x*b.x+a.y*b.y;
	 
	 }	
double dis(sit a,sit b)
{   return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
	
	}	  
	 
int main()
 {   
   int i,tempstart;
   double distance,maxdis; 
   sit temp;
   zero.x=0;zero.y=0; 
   while(1) 
   {
	 scanf("%lf%lf%d%d%lf",&fs.x,&fs.y,&total,&start,&D);
	  
		  if(total==0&&start==0&&D==0&&fs.x==0&&fs.y==0) return 0;
		   tempvet.x=0;tempvet.y=0;
		  for(i=1;i<=total;++i)
		    {scanf("%lf%lf",&sits[i].x,&sits[i].y);use[i]=0;}
		    tempstart=start;
		     printf("%d",start);
	l1:	        
		  use[start]=1;	 
          maxdis=0;  
		  for(i=1;i<=total;++i)
		   {    distance=dis(sits[i],sits[start]);
		        temp=vert(sits[i],sits[start]);
		     if(distance<=D&&angle(fs,temp)>=0&&use[i]==0&&angle(temp,tempvet)>=0)
		        { 
                   if(angle(fs,temp)/dis(temp,zero)>maxdis)
                     { maxdis=angle(fs,temp)/dis(temp,zero);tempstart=i;tempvet=vert(sits[i],sits[start]);}                                                                
                }   
		  }
		  
	    if(start!=tempstart)
	    {  start=tempstart;	printf(" %d",tempstart);goto l1;}
	    else printf("\n"); 
	  }  
	 
	 }


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