允许c++11,那么用vector会非常简单...
查看原帖
允许c++11,那么用vector会非常简单...
381341
Request2fReQuentlY楼主2020/9/5 18:00
#include <vector>
#include <iostream>
struct Geometry
{
	int x;
	int y;
	int w;
	int h;
};

struct Coord
{
	int x;
	int y;
};

void blanket()
{
	int n = 0;
	std::cin >> n;
	std::vector<Geometry> vec;
	for (int i = 0; i < n; i++)
	{
		Geometry geo;
		std::cin >> geo.x >> geo.y >> geo.w >> geo.h;
		vec.push_back(geo);
	}
	Coord target;
	std::cin >> target.x >> target.y;
	int count = 0;
	int index = -1;
	for (int i = 0; i < n; i++)
	{
		if (vec[i].x <= target.x &&
			vec[i].y <= target.y &&
			vec[i].x + vec[i].w >= target.x &&
			vec[i].y + vec[i].h >= target.y)
			index = i + 1;
	}
	std::cout << index << std::endl;
}

int main()
{
    blanket();
    return 0;
}
2020/9/5 18:00
加载中...