【HDOJ】1264 Counting Squares
说这道题目是hash,但是我是暴力解的。
1 #include <stdio.h> 2 #include <string.h> 3 4 #define MAXNUM 101 5 #define ALLEQU(x1,y1,x2,y2) x1==y1 && y1==x2 && x2==y2 6 7 int array[MAXNUM][MAXNUM]; 8 9 int main() { 10 int x1, y1, x2, y2; 11 int begx, endx, begy, endy; 12 int i, j, cnt=0; 13 14 memset(array, 0, sizeof(array)); 15 16 while (scanf("%d%d%d%d",&x1,&y1,&x2,&y2) != EOF) { 17 if ( ALLEQU(x1,y1,x2,y2) ) { 18 if (y2==-1 || y2==-2) { 19 cnt = 0; 20 for (i=0; i<MAXNUM; ++i) 21 for (j=0; j<MAXNUM; ++j) 22 if (array[i][j]) 23 cnt++; 24 printf("%d\n", cnt); 25 if (y2==-1) { 26 memset(array, 0, sizeof(array)); 27 continue; 28 } else { 29 break; 30 } 31 } 32 } 33 begx = (x1<x2) ? x1:x2; 34 endx = x1+x2 - begx; 35 begy = (y1<y2) ? y1:y2; 36 endy = y1+y2 - begy; 37 for (i=begx; i<endx; ++i) 38 for (j=begy; j<endy; ++j) 39 array[i][j] = 1; 40 } 41 42 return 0; 43 }