QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#497653#3846. Link-Cut TreePetroTarnavskyi#WA 0ms3656kbC++201.6kb2024-07-29 15:33:522024-07-29 15:33:53

Judging History

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

  • [2024-07-29 15:33:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-07-29 15:33:52]
  • 提交

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};
	}
};

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;
}

bool half(const Pt& p)
{
	assert(sgn(p.x) != 0 || sgn(p.y) != 0);
	return sgn(p.y) == -1 ||
		(sgn(p.y) == 0 && sgn(p.x) == -1);
}

void polarSortAround(const Pt& o, vector<Pt>& v)
{
	sort(ALL(v), [o](Pt p, Pt q)
	{
		p = p - o;
		q = q - o;
		bool hp = half(p), hq = half(q);
		if (hp != hq)
			return hp < hq;
		int s = sgn(cross(p, q));
		if (s != 0)
			return s == 1;
		return sq(p) < sq(q);
	});
}

void solve()
{
	int n;
	cin >> n;
	vector<Pt> v(n);
	for (Pt& p : v)
		cin >> p.x >> p.y;
	polarSortAround({0, 0}, v);
	int ptr = 0;
	int ans = n;
	FOR(i, 0, n)
	{
		while (ptr <= i + n && (ptr <= i || cross(v[i], v[ptr % n]) > 0))
			ptr++;
		
		ans = min(ans, ptr - i - 1);
	}
	cout << ans << "\n";
}

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

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3656kb

input:

2
6 8
1 2
2 3
5 6
3 4
2 5
5 4
5 1
4 2
4 2
1 2
4 3

output:

0
0

result:

wrong answer 1st lines differ - expected: '2 4 5 6', found: '0'