首页 > 其他 > 详细

HLG 1400 汽车比赛

时间:2014-03-12 23:42:23      阅读:574      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1400

结构体排序+树状数组模板..

bubuko.com,布布扣
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int c[100009];
struct point
{
    int x;
    int v;
} p[100000];
bool cmp(point p1,point p2)
{

    if(p1.x !=p2.x)
        return p1.x>p2.x;
    else
        return p1.v<p2.v;
}
int lowbit(int x)
{
    return x & (-x);
}
void update(int i,int val)
{
    while(i<=100000)
    {
        c[i]+=val;
        i+=lowbit(i);
    }

}
int Sum(int i)
{
    int s=0;
    while(i>0)
    {
        s += c[i];
        i -= lowbit(i);
    }
    return s;
}
int main()
{
    //freopen("input.txt","r",stdin);
    int i,n;
    while(scanf("%d",&n)!=EOF)
    {

        memset(c,0,sizeof(c));
        long long int ans = 0;
        for(i=0; i<n; i++)
            scanf("%d%d",&p[i].x,&p[i].v);
        sort(p,p+n,cmp);
        for(i=0; i<n; i++)
        {
            ans += Sum(p[i].v);
            update(p[i].v+1,1);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
bubuko.com,布布扣

HLG 1400 汽车比赛,布布扣,bubuko.com

HLG 1400 汽车比赛

原文:http://www.cnblogs.com/man1304010109/p/3597220.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!