LzzzOnly


私信TA

用户名:uq_62513724447

访问量:467

签 名:

等  级
排  名 805
经  验 3557
参赛次数 0
文章发表 5
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:
                用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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区