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

把我害惨了 原来是排序正错了 要把e从大到小如果相等则s从小到大

Posted by 20081727 at 2010-06-17 12:57:43 on Problem 2481
#include<iostream>
#include<algorithm>

using namespace std;
const int M = 100010;
struct dist
{
	int x,y;
	int pos;
};

dist cow[M];
int Max,c[M];
int result[200010];

int cmp(const void *a,const void *b)
{
	dist *p1 = (dist *)a;
	dist *p2 = (dist *)b;
	
	if(p1->y != p2->y)
	{
		 return(p2->y - p1->y);
	}
	return(p1->x - p2->x);
}


inline int lowbit(int x)
{
	return(x & (-x));
}

void update(int pos)
{
	while(pos <= Max + 1)
	{
		++c[pos];
        pos += lowbit(pos);
	}
}


int sum(int pos)
{
	int i,s = 0;
	for(i = pos; i > 0; i -= lowbit(i))
	{
		s += c[i];
	}
	return(s);
}



int main()
{
	 int i,j,iN;
	 while(scanf("%d",&iN) && iN)
	 {
		 memset(c,0,sizeof(c));
		 memset(result,0,sizeof(result));
		 
		 Max = 0;
		 for(i = 0; i < iN; ++i)
		 {
			 scanf("%d%d",&cow[i].x,&cow[i].y);
			 if(Max < cow[i].x)
			 {
				  Max = cow[i].x;
			 }
			 cow[i].pos = i;
		 }
         qsort(cow,iN,sizeof(cow[0]),cmp);
		 update(cow[0].x + 1);
		 result[cow[0].pos] = 0;
		 for(i = 1; i < iN; ++i)
		 {
		       if(cow[i].x != cow[i -1].x || cow[i].y != cow[i - 1].y )  //不相等
			   {
				   result[cow[i].pos] = sum(cow[i].x + 1);
			   }
			   else
			   {
				   result[cow[i].pos] = result[cow[i-1].pos];
			   }
			   update(cow[i].x + 1);
		 }

		  for(i = 0; i < iN; ++i)
		  {
		      printf("%d ",result[i]);
		  }
		 printf("\n");
	 }
	 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