解题思路:
用bool型 来表示星空,1为存在星星;
注意事项:
参考代码:
#include<iostream> using namespace std; int main() { bool locat[1001][1001]; //bool型 节省空间 for (int i = 0; i < 1001; i++) //初始化 for (int j = 0; j < 1001; j++) locat[i][j] = 0; int n = 0; cin >> n; //星星数量 while (n--) { //星星位置 int x = 0, y = 0; cin >> x >> y; locat[x][y] = 1; } int m = 0; cin >> m;//m个问题 while (m--) { int sum = 0; int x1, y1, x2, y2; // (x1,y1)左上点 (x2,y2)右下点 cin >> x1 >> y1 >> x2 >> y2; for (int i = x1; i <= x2; i++) { for (int j = y1; j <= y2; j++) { if (locat[i][j]) sum++; } } cout << sum << endl; } return 0; }
0.0分
0 人评分