码迷,mamicode.com
首页 > 其他好文 > 详细

Pipeline(swust oj 0695)

时间:2014-12-28 18:07:00      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

题目描述: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;
}

 

Pipeline(swust oj 0695)

标签:

原文地址:http://www.cnblogs.com/yanglingwell/p/4190203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!