[Luo Gu P4385] [COCI2009] Dvapravca (Gugu Gu)

Subject to the effect: a long time ago to do title

answer:

Card points:

 

C++ Code:

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <random> 
#include <cstdio>
#include <cstdlib>
#include <ctime>
#define maxn 1010
#define long
const long double eps = 1e-8;
inline long double abs(long double x) { return x < 0 ? -x : x; }

struct Point {
	int x, y;
	bool isR;
	long double b;
	Point() { }
	Point(int __x, int __y, bool __isR) : x(__x), y(__y), isR(__isR), b(__x) { }
	inline bool operator == (const Point &rhs) const {
		return abs(b - rhs.b) < eps;
	}
} P[maxn];
inline long double slope(const Point &lhs, const Point &rhs) {
	return (lhs.y - rhs.y) / static_cast<long double> (lhs.x - rhs.x);
}
inline bool cmp(int a, int b) { return P[a].b < P[b].b; }
inline int sign(long double x) { return x < -eps ? -1 : x > eps; }

std::mt19937 rd(time(0));
int n, totR, totB;
int R[maxn], B[maxn], rnk[maxn];
int ans;

void calc() {
	std::sort(rnk + 1, rnk + n + 1, cmp);
	for (int l = 1, r, cnt[2], res = 0; l <= n; l = r) {
		r = l;
		cnt[0] = cnt[1] = 0;
		while (r <= n && P[rnk[l]] == P[rnk[r]]) 
			++cnt[P[rnk[r]].isR], ++r;
		res += cnt[1];
		ans = std::max(ans, res);
		if (cnt[0]) res = cnt[1];
	}
}
void solve() {
	int __B = rd() % totB, __R = rd() % totR;
	Point _R = P[R[__R]], _B = P[B[__B]];
	if (_R.x == _B.x) return ;
	const long double k = slope(_R, _B), b = _R.y - _R.x * k;
	for (register int i = 1; i <= n; ++i) P[i].b = P[i].y - P[i].x * k;
	long double min = 1e20, max = -1e20;
	for (int *i = B; i != B + totB; ++i) {
		int __s = sign(P[*i].b - b);
		if (__s) {
			if (__s == 1) min = std::min(min, P[*i].b);
			else max = std::max(max, P[*i].b);
		}
	}
	int resm = 1, resM = 1;
	for (int *i = R; i != R + totR; ++i) {
		int __s = sign(P[*i].b - b);
		if (__s) {
			if (__s == 1) resM += (P[*i].b <= min + eps);

		for(int i = 1; i <= 10; ++i) solve();

  

Guess you like

Origin www.cnblogs.com/Memory-of-winter/p/11402347.html
Recommended