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

自己调试吧,这比过了sample还WA的程序好弄多了.

Posted by xfxyjwf at 2005-06-08 16:19:07 on Problem 1971
In Reply To:为什么第一个sample出的结果正确,第二个却错了 Posted by:19830729 at 2005-06-08 14:37:15
> 为什么第一个sample出的结果正确,第二个却错了,附上程序请高手指点
> #include"stdio.h"
> #include"math.h"
> #define M 10000
> #define N 7
> 
> float lean(int a,int b,int c,int d)
> {
>  float k;
>   if(a-b!=0)
>    k=(float)(c-d)/(a-b);
>   else
>    k=M;
>   return k;
> }
> 
> int distant(int a,int b,int c,int d)
> {
>  int dist;
>  dist=(a-b)*(a-b)+(c-d)*(c-d);
>  return dist;
> }
> 
> main()
> {
>  int x[N]={-2,8,5,1,4,2,9},y[N]={-1,9,7,1,8,0,8};
>  float k[N][N];
>  int d[N][N];
>  int i,j,m,n;
>  int flag=0; clrscr();
> 
>  for(i=0;i<N;i++)
>   for(j=0;j<N;j++)
>   if(j!=i){
>    {
>      d[i][j]=distant(x[i],x[j],y[i],y[j]);
>      k[i][j]=lean(x[i],x[j],y[i],y[j]);
>      printf("%d\t",d[i][j]);
>      printf("%f\n",k[i][j]);
>      printf("%d,%d\n",i,j);  
> 
> 	for(m=0;m<N;m++)
>         if(m!=i&&m!=j){
>          {
> 	  for(n=0;n<N;n++)
>            if(n!=m&&n!=i&&n!=j){
> 	    {
>              d[m][n]=distant(x[m],x[n],y[m],y[n]);
> 	    /* printf("%d\n",d[m][n]); */
> 		if(d[m][n]==d[i][j])
> 		  { k[m][n]=lean(x[m],x[n],y[m],y[n]);
> 		   /*  printf("%f\n",k[m][n]);
> 		     printf("%d,%d,%d,%d\n",i,j,m,n);*/
> 			if(k[m][n]==k[i][j])
> 			  {
> 			    k[m][i]=lean(x[m],x[i],y[m],y[i]);
>                             k[m][j]=lean(x[m],x[j],y[m],y[j]);
> 		            k[n][i]=lean(x[n],x[i],y[n],y[i]);
> 		            k[n][j]=lean(x[n],x[j],y[n],y[j]);
> 
>                            if(k[m][i]==k[m][j]&&k[m][j]==k[n][i]&&k[n][i]==k[n][j]&&k[n][j]==k[m][i])
> 			     printf("The four points are in a line!\n");
> 			   else
> 			     flag++;
> 			  }
> 		  }
>             }
>           }}}}
>    }
>    printf("\n");
>    printf("%d\n",flag);
>    getchar();
> }

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