UVA1606AmphiphilicCarbonMolecules

来源:互联网 发布:俄罗斯现状 知乎 编辑:程序博客网 时间:2024/06/08 11:00
//UVA1606AmphiphilicCarbonMolecules #include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int MAXN = 1000 + 10;struct Node{int x, y;double rad;bool operator < (const Node& rhs) const {    return rad < rhs.rad;}} op[MAXN], p[MAXN];bool color[MAXN];bool Left(const struct Node& a, const struct Node& b) {return a.x * b.y - a.y * b.x >= 0;}int n;int solve() {int ans = 0;for(int i = 0; i < n; i++) {//穷举所有的中心点 int k = 0;for(int j = 0; j < n; j++) {if(j != i) {//相对于中心点的坐标变换和极角转换 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++;}}sort(p, p + k);//按照极角大小进行排序int L = 0, R = 0, cnt = 2;while(L < k) {if(L == R) {R = (R + 1) % k; cnt++;//当每次L与R相遇时,弥补下面cnt--带来的损失 }while(L != R && Left(p[L], p[R])) {R = (R + 1) % k; cnt++;}cnt--;L++;ans = max(ans, cnt);} }return ans;}int main() {while(scanf("%d", &n) == 1 && n) {for(int i = 0; i < n; i++) scanf("%d%d%d", &op[i].x, &op[i].y, &color[i]);printf("%d\n", solve());}return 0;} /*30 0 00 1 02 2 140 0 00 4 04 0 01 2 17-1 0 01 2 12 3 02 1 10 3 11 4 0-1 2 00*/

原创粉丝点击