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

求大神帮忙看一下哪里出错了?谢谢谢谢

Posted by 20142430112 at 2016-04-06 23:53:28 on Problem 1723
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
    int a,b,n,p,sum,u;
    int i,j,temp,i1,j1,temp1;
    scanf("%d",&n);
    int *x;
    int *y;
    char *c;
    x=(int*)malloc(n*sizeof(int));
    y=(int*)malloc(n*sizeof(int));
    c=(char*)malloc(n*sizeof(char));
    for(p=0;p<n;p++)
    {
      scanf("%d",&x[p]);
      scanf("%c",&c[p]);
      scanf("%d",&y[p]);             
                    }
    for(i1=0;i1<=n-1;i1++)
    {
	   for(j1=0;j1<n-i1-1;j1++)
       {
          if(x[j1]>x[j1+1])
          {
             temp1=x[j1];
             x[j1]=x[j1+1];
             x[j1+1]=temp1;            
                         }                 
                           }               
                      }
    

    for(i1=0;i1<n;i1++)
    x[i1]=x[i1]-i1+1;
	 for(i1=0;i1<=n-1;i1++)
    {
	   for(j1=0;j1<n-i1-1;j1++)
       {
          if(x[j1]>x[j1+1])
          {
             temp1=x[j1];
             x[j1]=x[j1+1];
             x[j1+1]=temp1;            
                         }                 
                           }               
                      }   
        if(n%2==0)
    a=x[n/2]+x[(n/2)+1];
    else a=x[(n/2)+1];                
                    
                    
                    
                    
                    
                  
for(i=0;i<=n-1;i++)
    {
	   for(j=0;j<n-i-1;j++)
       {
          if(y[j]>y[j+1])
          {
             temp=y[j];
             y[j]=y[j+1];
             y[j+1]=temp;            
                         }                 
                           }               
                      }
    if(n%2==0)
    b=y[n/2]+y[(n/2)+1];
    else b= y[(n/2)+1];

	sum=0;  
    for(u=0;u<n;u++)
    {
         sum=sum+abs(y[u]-b)+abs(x[u]-a);
}
     printf("%d",sum);
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