All pastes #970731 Raw Edit

無題

public cpp v1 · immutable
·published 2008-04-04 07:23 UTC
rendered paste body
#include <windows.h>#include <mmsystem.h>#include <stdio.h>#include <stdlib.h>#include <time.h>struct col {	int x1, y1, x2, y2;};bool test(col const & c1, col const & c2) {	if (c1.x1 > c2.x2 || c1.y1 > c2.y2 || c1.x2 < c2.x1 || c1.y2 < c2.y1)	    return false;	return true;}int main () {	TIMECAPS timecaps;	timeGetDevCaps( &timecaps, sizeof(TIMECAPS) );  	timeBeginPeriod(1);	srand(time(NULL));	col* c = new col[1600];	for (int i = 0; i < 1600; ++i) {		c[i].x1 = rand() % 640;		c[i].y1 = rand() % 480;		c[i].x2 = c[i].x1 + 32;		c[i].y2 = c[i].y1 + 32;	}	int hit = 0;	int start = timeGetTime();	for (int i = 0; i < 1600-1; ++i) {		for (int j = i+1; j < 1600; ++j) {			if(test(c[i], c[j]))				hit++;		}	}	int end = timeGetTime();	timeEndPeriod(timecaps.wPeriodMin);	printf("%dhit\n", hit);	printf("%dms\n", end - start);	return 0;}