All pastes #970760 Raw Edit

無名

public cpp v1 · immutable
·published 2008-04-04 07:57 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;	int damage;};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* b = new col[1600];	col* c = new col[64];	for (int i = 0; i < 1600; ++i) {		b[i].x1 = rand() % 640;		b[i].y1 = rand() % 480;		b[i].x2 = b[i].x1 + 16;		b[i].y2 = b[i].y1 + 16;		b[i].damage = 0;	}	for (int i = 0; i < 64; ++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;		c[i].damage = 0;	}	int hit = 0;	int start = timeGetTime();	for (int i = 0; i < 1600; ++i) {		for (int j = 0; j < 64; ++j) {			if(test(b[i], c[j])) {				hit++;				b[i].damage++;				c[j].damage++;				break;			}		}	}	int end = timeGetTime();	timeEndPeriod(timecaps.wPeriodMin);	for (int i = 0; i < 64; ++i) {		printf("(%3d,%3d)-(%3d,%3d) %d\n", c[i].x1, c[i].y1, c[i].x2, c[i].y2, c[i].damage);	}	printf("%dhit\n", hit);	printf("%dms\n", end - start);	return 0;}