UVa1606 UVaLive3259 FZU1309 HDU1661 POJ2280 ZOJ2390 Amphiphilic Carbon Molecules

时间:2023-03-10 05:31:41
UVa1606 UVaLive3259 FZU1309 HDU1661 POJ2280 ZOJ2390 Amphiphilic Carbon Molecules

填坑系列

考虑所有经过两个点的直线,一定有最优解。

再考虑确定一个点,按极角顺序枚举所有直线,从而O(1)转移信息。

还有代码实现技巧

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream> const int N = + ; typedef const struct Point& CP;
struct Point {
int x, y;
double rad;
bool operator < (CP rhs) const {
return rad < rhs.rad;
}
}op[N], p[N]; int n, color[N]; bool Left(CP a, CP b) {
return a.x * b.y - a.y * b.x >= ;
} #include<cmath>
int solve() {
if(n <= ) return n;
int ans = ; for(int i = ; i < n; i++) {
int k = ;
for(int j = ; j < n; j++) if(i ^ j) {
p[k].x = op[j].x - op[i].x;
p[k].y = op[j].y - op[i].y;
if(color[j]) {
p[k].x = -p[k].x;
p[k].y = -p[k].y;
}
p[k].rad = atan2(p[k].y, p[k].x);
k++;
}
std::sort(p, p + k); int L = , R = , cnt = ;
while(L < k) {
if(R == L) {
++R %= k;
cnt++;
}
while(R != L && Left(p[L], p[R])) {
++R %= k;
cnt++;
}
ans = std::max(ans, cnt);
L++, cnt--;
}
}
return ans;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif while(scanf("%d", &n) == && n) {
for(int i = ; i < n; i++) {
scanf("%d%d%d", &op[i].x, &op[i].y, color + i);
}
printf("%d\n", solve());
} return ;
}