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

网上的一段代码……请教大牛

Posted by killua_hzl at 2008-08-19 15:19:31 on Problem 2352
#include<stdio.h>

#define SIZE1 32000
#define SIZE2 15000
int c[SIZE1];
int a[SIZE1];
int out[SIZE2];
int n;
int lowbit(int k)
{
 return k&(k^(k-1));
}

int sum(int k)
{
 int ret=0;
 while(k>0)
 {
  ret+=c[k];
  k-=lowbit(k);
 }
 return ret;
}
void change(int pos,int delt)
{
 
 while(pos<=SIZE1)
 {
  c[pos]+=delt;
  pos+=lowbit(pos);
 }
}

void init()
{
 int i;
 int x,y;
 for(i=0;i<n;i++)
 {
  scanf("%d%d",&x,&y);
  x++;  
  out[sum(x-1)+a[x]]++;  ////////这句话是什么意思……
  change(x,1);
  a[x]++;
  
 }
}
int main()
{
 int i;
 scanf("%d",&n);
 init();
 for(i=0;i<n;i++)
 {
  printf("%d\n",out[i]);
 }
}

他貌似只考虑了x都没考虑y,是我理解错了,还是数据的问题??

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