洛谷新手村前幾題好多模擬,難度也是漸漸上來了。先是一維陣列,再是二維,二維座標時還要注意端點處是否取到
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int n, m, x, y, i, j, k, x1, y1, x2, y2;
scanf("%d %d %d %d", &n, &m, &x, &y);
int sign[n + 1][m + 1], import[y][2], sigh[n + 1][m + 1]; //sigh記錄轟炸的輪數
for ( i = 0; i < n + 1; i++)
for ( j = 0; j < m + 1; j++)
sign[i][j] = 0;
for ( k = 1; k <= x; k++){
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
for ( i = x1; i <= x2; i++)
for ( j = y1; j <= y2; j++){
sign[i][j]++;
sigh[i][j] = k;
}
}
for ( i = 0; i < y; i++)
scanf("%d %d", &import[i][0], &import[i][1]);
for ( i = 0; i < y; i++){
if (sign[import[i][0]][import[i][1]] != 0){
printf("Y %d %d\n", sign[import[i][0]][import[i][1]], sigh[import[i][0]][import[i][1]]);
}
else
printf("N\n");
}
return 0;
}