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

C

Posted by 20132430213 at 2015-04-29 22:52:27 on Problem 1723
#include <stdio.h>
#include <stdlib.h>
int get_abs(int a)
{
    return a>0?a:-a;
}
int comp(const void *a,const void *b)
{
    return (*(int *)a-*(int *)b);
}
int main()
{
    int x[10000],y[10000];
    int n;
    int i;
   long  int sum=0;
    int std;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d",x+i,y+i);
    }
    qsort(x,n,sizeof(int),comp);
    for(i=0;i<n;i++)
    x[i]-=i;
    qsort(x,n,sizeof(int),comp);
    std=x[n/2];
    for(i=0;i<n;i++)
    sum+=get_abs(x[i]-std);
    qsort(y,n,sizeof(int),comp);
    std=y[n/2];
    for(i=0;i<n;i++)
    sum+=get_abs(y[i]-std);
    printf("%ld\n",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