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

请各位高手帮小弟看下,为啥总是WA~~ 晕啊~

Posted by gaoconan at 2006-01-15 23:09:32 on Problem 2352
   
#include "stdio.h"
#include "stdlib.h"

typedef struct {
	int x;
	int y;
} entry;


int comp_x(const void* e1, const void *e2) {
	entry *p1 = (entry*)e1;
	entry *p2 = (entry*)e2;

	if ( p1->x != p2->x ) {
		return ( p1->x - p2->x );
	}
	else {
		return ( p1->y - p2->y );
	}
}

int comp_i(const void *p, const void *q) {
	return (*((int*)p) - *((int*)q) );
}


int main() {

	int nCase;
	scanf("%d", &nCase);

	entry *entrys = (entry*)malloc( sizeof(entry) * nCase );


	int i;
	for ( i = 0; i < nCase; i++ ) {
		scanf("%d%d", &entrys[i].x, &entrys[i].y);
		entrys[i].y = i;
	}

	qsort(entrys, nCase, sizeof(entry), comp_x);

	int *res = (int*)malloc(sizeof(int) * nCase);
	for ( i = 0; i < nCase; i++ ) {
		if ( i < entrys[i].y ) {
			res[i] = i;
		}
		else {
			res[i] = entrys[i].y;
		}
	}

	qsort(res, nCase, sizeof(int), comp_i);

	int *prints = (int*)malloc(sizeof(int) * nCase);
	
	for ( i = 0; i < nCase; i++ ) {
		*(prints+i) = 0;
	}


	int lev = 0;
	int r = 0;
	i = 0;
	for ( ;; ) {
		for ( r = 0; i < nCase && res[i] == lev ; i++ ) r++;
		//printf("%d\n", r);
		prints[lev] = r;
		if ( i == nCase ) break;
		lev = res[i];
	}

	for ( i = 0; i < nCase; i++ ) {
		printf("%d\n", *(prints+i));
	}

	free(entrys);
	free(res);
	free(prints);

	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