QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346618#4778. Tracking RFIDsPetroTarnavskyi#AC ✓886ms15312kbC++203.0kb2024-03-08 19:12:572024-03-08 19:12:57

Judging History

你现在查看的是最新测评结果

  • [2024-03-08 19:12:57]
  • 评测
  • 测评结果:AC
  • 用时:886ms
  • 内存:15312kb
  • [2024-03-08 19:12:57]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

struct Pt
{
	int x, y;
	Pt operator-(const Pt& p) const
	{
		return {x - p.x, y - p.y};
	}
	bool operator<(const Pt& p) const
	{
		return x == p.x ? y < p.y : x < p.x;
	}
};

LL sq(const Pt& p)
{
	return (LL)p.x * p.x + (LL)p.y * p.y;
}

int sgn(LL x)
{
	return (0 < x) - (x < 0);
}

LL dot(const Pt& p, const Pt& q)
{
	return (LL)p.x * q.x + (LL)p.y * q.y;
}

LL cross(const Pt& p, const Pt& q)
{
	return (LL)p.x * q.y - (LL)p.y * q.x;
}

LL orient(const Pt& p, const Pt& q, const Pt& r)
{
	return cross(q - p, r - p);
}

bool inDisk(const Pt& a, const Pt& b, const Pt& p)
{
	return sgn(dot(a - p, b - p)) <= 0;
}

bool onSegment(const Pt& a, const Pt& b, const Pt& p)
{
	return sgn(orient(a, b, p)) == 0
		&& inDisk(a, b, p);
}

bool properInter(const Pt& a, const Pt& b, const Pt& c, const Pt& d)
{
	LL oa = orient(c, d, a);
	LL ob = orient(c, d, b);
	LL oc = orient(a, b, c);
	LL od = orient(a, b, d);
	return sgn(oa) * sgn(ob) == -1
		&& sgn(oc) * sgn(od) == -1;
}

/*bool inter(const Pt& a, const Pt& b, const Pt& c, const Pt& d)
{
	LL oa = orient(c, d, a);
	LL ob = orient(c, d, b);
	LL oc = orient(a, b, c);
	LL od = orient(a, b, d);
	if (sgn(oa) * sgn(ob) > 0)
		return false;
	if (sgn(oc) * sgn(od) > 0)
		return false;
	int minxab = min(a.x, b.x);
	int maxxab = max(a.x, b.x);
	int minyab = min(a.y, b.y);
	int maxyab = max(a.y, b.y);
	int minxcd = min(c.x, d.x);
	int maxxcd = max(c.x, d.x);
	int minycd = min(c.y, d.y);
	int maxycd = max(c.y, d.y);
	return minxcd <= maxxab && minxab <= maxxcd
		&& minycd <= maxyab && minyab <= maxycd;
}*/

void solve()
{
	int s, r, w, n;
	cin >> s >> r >> w >> n;
	set<Pt> sensors;
	FOR(i, 0, s)
	{
		Pt p;
		cin >> p.x >> p.y;
		sensors.insert(p);
	}
	vector<pair<Pt, Pt>> walls(w);
	for (auto& [p1, p2] : walls)
		cin >> p1.x >> p1.y >> p2.x >> p2.y;
	FOR(i, 0, n)
	{
		Pt p;
		cin >> p.x >> p.y;
		vector<Pt> ans;
		FOR(dx, -r, r + 1)
		{
			FOR(dy, -r, r + 1)
			{
				Pt sensor = {p.x + dx, p.y + dy};
				if (sensors.count(sensor))
				{
					int cntWalls = 0;
					for (auto [p1, p2] : walls)
					{
						if (properInter(sensor, p, p1, p2) || onSegment(sensor, p, p1) || onSegment(sensor, p, p2))
							cntWalls++;
					}
					if (r - cntWalls >= 0 && sq(sensor - p) <= (r - cntWalls) * (r - cntWalls))
					{
						ans.PB(sensor);
					}
				}
			}
		}
		cout << SZ(ans);
		for (Pt sensor : ans)
		{
			cout << " (" << sensor.x << "," << sensor.y << ")";
		}
		cout << "\n";
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3848kb

input:

1
4 3 4 7
0 0
-1 3
2 3
11 5
-4 -1 5 -1
3 5 6 1
11 4 11 3
12 5 12 8
1 1
0 -2
4 4
11 2
13 5
13 7
14 5

output:

3 (-1,3) (0,0) (2,3)
1 (0,0)
0
0
1 (11,5)
0
0

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 886ms
memory: 15312kb

input:

62
4 3 4 7
0 0
-1 3
2 3
11 5
-4 -1 5 -1
3 5 6 1
11 4 11 3
12 5 12 8
1 1
0 -2
4 4
11 2
13 5
13 7
14 5
3 5 0 5
0 0
5 0
8 4
0 5
2 3
2 4
3 4
5 0
3 1 0 15
-10 -42
-9 -42
-8 -42
-11 -41
-11 -42
-11 -43
-10 -41
-10 -42
-10 -43
-9 -41
-9 -42
-9 -43
-8 -41
-8 -42
-8 -43
-7 -41
-7 -42
-7 -43
5 3 0 7
0 0
-1 -3...

output:

3 (-1,3) (0,0) (2,3)
1 (0,0)
0
0
1 (11,5)
0
0
1 (0,0)
2 (0,0) (5,0)
2 (0,0) (5,0)
3 (0,0) (5,0) (8,4)
3 (0,0) (5,0) (8,4)
0
1 (-10,-42)
0
1 (-10,-42)
2 (-10,-42) (-9,-42)
1 (-10,-42)
1 (-9,-42)
3 (-10,-42) (-9,-42) (-8,-42)
1 (-9,-42)
1 (-8,-42)
2 (-9,-42) (-8,-42)
1 (-8,-42)
0
1 (-8,-42)
0
3 (-1,-3...

result:

ok 31312 lines