QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#114858#5320. Triangles and QuadranglePetroTarnavskyi#AC ✓1ms3572kbC++174.1kb2023-06-23 19:15:022023-06-23 19:15:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-23 19:15:04]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3572kb
  • [2023-06-23 19:15:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

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

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

const double EPS = 1e-3;

struct point
{
	int x, y;
	
	point (): x(0), y(0) {}
	point (int _x, int _y): x(_x), y(_y) {}
	
	int getl(point p)
	{
		int dx = x - p.x; 
		int dy = y - p.y; 
		return dx * dx + dy * dy;
	}
	
	point operator -(const point& p) const
	{
		return point(x - p.x, y - p.y);
	}
};

vector<int> len(vector<point> t, bool s = true)
{
	vector<int> res;
	FOR (i, 0, SZ(t))
	{
		res.PB(t[i].getl(t[(i + 1) % SZ(t)]));
	}
	if (s)
		sort(ALL(res));
	return res;
}

vector<point> t1, t2, sq;

int area(point a, point b, point c)
{
	a = a - c;
	b = b - c;
	return a.x * b.y - a.y * b.x;
}

bool check()
{
	VI d1 = len(t1);
	VI d2 = len(t2);
	
	FOR (t, 0, 2)
	{
		VI ds1 = len({sq[t], sq[t + 1], sq[t + 2]});
		VI ds2 = len({sq[t + 2], sq[(t + 3) % 4], sq[(t + 4) % 4]});
		
		if (d1 == ds1 && d2 == ds2)
			return 1;
		if (d1 == ds2 && d2 == ds1)
			return 1;
	}
	return 0;
}

bool eq(__int128 c, __int128 d, __int128 y)
{
	if (y < c + d) return 0;
	__int128 L3 = (y - c - d) * (y - c - d);
	
	return 4 * c * d == L3;
}

bool check2()
{
	vector<point> t3;
	FOR (i, 0, 4)
	{
		if (abs(area(sq[i], sq[(i + 1) % 4], sq[(i + 2) % 4])) > 0)
			t3.PB(sq[(i + 1) % 4]);
	}
	if (SZ(t3) != 3) return 0;
	
	int a1 = abs(area(t1[0], t1[1], t1[2]));
	int a2 = abs(area(t2[0], t2[1], t2[2]));
	int a3 = abs(area(t3[0], t3[1], t3[2]));
	
	if (a3 != a1 + a2) return false;
	
	VI d1 = len(t1);
	VI d2 = len(t2);
	VI d3 = len(t3);
	
	VI idx1(3), idx2(3), idx3(3);
	iota(ALL(idx1), 0);
	iota(ALL(idx2), 0);
	iota(ALL(idx3), 0);
	
	
	bool ok = false;
	
	do
	{
		do
		{
			do
			{
				if (d1[idx1[0]] != d2[idx2[0]])
					continue;
				if (d1[idx1[1]] != d3[idx3[0]])
					continue;
				if (d2[idx2[1]] != d3[idx3[1]])
					continue;
				
				__int128 a = d1[idx1[1]];
				__int128 b = d2[idx2[1]];
				__int128 x = d1[idx1[0]];
				__int128 d = d1[idx1[2]];
				__int128 c = d2[idx2[2]];
				__int128 e = d3[idx3[2]];
				
				__int128 L1 = (a - x - d) * (a - x - d);
				__int128 L2 = (x + c - b) * (x + c - b);
				
				L1 *= d2[idx2[2]];
				L2 *= d1[idx1[2]];
				
				
				
				if (L1 == L2 && eq(c, d, e))
					ok = true;
				
			} while (next_permutation(ALL(idx3)));
			sort(ALL(idx3));
		} while (next_permutation(ALL(idx2)));
		sort(ALL(idx2));
	} while (next_permutation(ALL(idx1)));
	
	
	return ok;
}

bool check3()
{
	FOR (t, 0, 2)
	{
		swap(t1, t2);
		VI d1 = len(t1);
		VI d2 = len(t2);
		VI d3 = len(sq, false);
		
		FOR (i, 0, 4)
		{
			VI idx1(3), idx2(3);
			iota(ALL(idx1), 0);
			iota(ALL(idx2), 0);
			do
			{
				do
				{
					bool ok = true;
					ok &= d3[i] == d1[idx1[0]];
					ok &= d3[(i + 2) % 4] == d2[idx2[0]];
					ok &= eq(d1[idx1[2]], d2[idx2[2]], d3[(i + 3) % 4]);
					ok &= eq(d3[(i + 1) % 4], d2[idx2[1]], d1[idx1[1]]);
					if (ok) return true;
					
				} while (next_permutation(ALL(idx2)));
				sort(ALL(idx2));
			} while (next_permutation(ALL(idx1)));
		}
		
		
		
	}
	return false;
}

void solve()
{
	t1.resize(3);
	t2.resize(3);
	sq.resize(4);
	
	FOR (i, 0, 3) cin >> t1[i].x >> t1[i].y;
	FOR (i, 0, 3) cin >> t2[i].x >> t2[i].y;
	FOR (i, 0, 4) cin >> sq[i].x >> sq[i].y;
	
	int a1 = abs(area(t1[0], t1[1], t1[2]));
	int a2 = abs(area(t2[0], t2[1], t2[2]));
	int a3 = 0;
	FOR(i, 0, 3)
	{
		a3 += area(sq[i], sq[i + 1], sq[0]);
	}
	
	a3 = abs(a3);
		
	if ((a3 == a1 + a2) && (check() || check2() || check3()))
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}
	t1.clear();
	t2.clear();
	sq.clear();
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int t;
	cin >> t;
	FOR (tt, 0, t)
	{
		cout << "Case #" << tt + 1 << ": "; 
		solve();
	}
	
	return 0;
}


詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3572kb

input:

500
-1363 3930
-1342 3930
-1355 3934
2730 -560
2709 -560
2722 -556
-2484 -2677
-2476 -2673
-2484 -2669
-2497 -2673
-1810 2709
-1831 2709
-1818 2705
-4735 -3180
-4743 -3184
-4722 -3184
4271 -1177
4267 -1169
4263 -1177
4267 -1190
3800 -3033
3821 -3033
3808 -3029
-3242 224
-3234 228
-3255 228
-3847 170...

output:

Case #1: Yes
Case #2: Yes
Case #3: No
Case #4: No
Case #5: Yes
Case #6: Yes
Case #7: Yes
Case #8: Yes
Case #9: Yes
Case #10: Yes
Case #11: Yes
Case #12: Yes
Case #13: Yes
Case #14: Yes
Case #15: Yes
Case #16: Yes
Case #17: Yes
Case #18: Yes
Case #19: Yes
Case #20: Yes
Case #21: Yes
Case #22: Yes
Cas...

result:

ok 500 lines