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

Re:WA到死 大家帮下忙好么?

Posted by wudired at 2009-07-30 16:04:39 on Problem 3067
In Reply To:WA到死 大家帮下忙好么? Posted by:wudired at 2009-07-30 16:04:33
/* 
 * File:   main.cpp
 * Author: wudired
 *
 * Created on 2009年7月30日, 下午12:19
 */

#include <stdlib.h>
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int  i,j,k,n,m,z,t;
long long  sub,c[2002];
struct data
{
	int x,y;
}d[2001];
int lowbit (int x)
{
    return x&(-x);
}
void add(int i,int v)
{
    while (i<=1000)
    {
        c[i]=c[i]+v;
        i+=lowbit(i);
    }
}
long long  sum(int i)
{
    long long  s=0;
    while (i>0)
    {
        s+=c[i];
        i-=lowbit(i);
    }
    return s;
}
bool cmp(const data &a,const data &b)
{
    if (a.y==b.y)
     return a.x>b.x;
    return a.y>b.y;
}
int main(int argc, char** argv)
{
    scanf("%d",&t);
    for (i=1;i<=t;i++)
    {
        memset(d,0,sizeof(d));
        scanf("%d%d%d",&n,&m,&k);
        for (j=1;j<=k;j++)
            scanf("%d%d",&d[j].x,&d[j].y);
        memset(c,0,sizeof(c));
        sort(d+1,d+1+k,cmp);
        z=0;

        sub=0;
        for (j=1;j<=k;j++)
        {
           sub+=sum(d[j].x-1);
           add(d[j].x,1);
        }

        printf("Test case %d: %lld\n",i,sub);
    }
    return (EXIT_SUCCESS);
}


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