标签:
题目描述:http://acm.swust.edu.cn/problem/0695/
AC代码:
#include<stdio.h> struct point { int x,y; }; struct point p[10020]; void sort(int a,int b) { int i,j; for(i=a+1;i<b;i++){ struct point temp=p[i]; j=i-1; while(temp.y<p[j].y&&j>=0) p[j+1]=p[j--]; if(j!=i-1) p[j+1]=temp; } } int main() { int n; scanf("%d",&n); int i; for(i=0;i<n;i++) scanf("%d%d",&p[i].x,&p[i].y); sort(0,n); int sum=0; int head=0,tail=n-1; while(head<tail) sum+=(p[tail--].y-p[head++].y); printf("%d\n",sum); return 0; }
标签:
原文地址:http://www.cnblogs.com/yanglingwell/p/4190203.html