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

排序规则究竟应该是什么样的?x升序y升序可以,x降序y降序也可以,x降序y升序就不行

Posted by jiajiawang at 2016-08-08 20:39:09 on Problem 3067
x升序y升序可以,x降序y降序也可以,y降序x升序就不行,有没有哪位理解的,解释一下?
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
const int MAX=1000+5;
typedef long long LL;
struct node
{
    int x,y;
    bool  operator <(const node & a) const
    {
        return y>a.y||(y==a.y&&x<a.x);
    }
};
node a[MAX*MAX];
int bit[MAX];
int N,M;
LL sum(int x)
{
    LL s=0;
    while(x>0)
    {
        s=s+bit[x];
        x-=(x&(-x));
    }
    return s;
}
void add(int x)
{
    while(x<=N)
    {
        bit[x]++;
        x+=(x&(-x));
    }
}
int main()
{
    ios::sync_with_stdio(false);
    int T;
    scanf("%d",&T);
    for(int tcase=1;tcase<=T;tcase++)
    {
        int k;
        scanf("%d%d%d",&N,&M,&k);
        memset(bit,0,sizeof(bit));
        for(int i=0;i<k;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
        }
        sort(a,a+k);
        LL ans=0;
        for(int i=0;i<k;i++)
        {
            ans=ans+sum(a[i].x-1);
            add(a[i].x);
        }
        printf("Test case %d: ",tcase);
        cout<<ans<<endl;
    }
    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