两亲性分子(Amphiphilic Carbon Molecules,Uva 1606)
2016-01-06 20:18
423 查看
原题链接
分析:假设隔板一定经过两点,则可以根据两点的枚举进行统计。首先可以枚举一个基准点,再根据枚举的另一个点进行隔板的枚举对点数进行统计。在进行枚举之前算出其余点基于基准点的极角进行升序排列,之后再进行枚举统计。
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<string> #include<map> #include<cmath> #include<sstream> #include<queue> #include<cctype> using namespace std; typedef long long ll; const int Max = 100000 + 5; struct Node { double rad; int x,y; bool operator < (const Node &rhs) { return rad < rhs.rad; } }p[Max],op[Max]; int n,color[Max]; int Left(Node a,Node b) { return (a.x * b.y - a.y * b.x) >= 0; } int solve() { if(n <= 2) return 2; int ans = 0; // 枚举基准点 for(int i=0;i<n;i++) { int k = 0; for(int j=0;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++; } sort(p,p+k); int cnt = 2; int L = 0,R = 0; // 枚举隔板 while(L < k) { if(L == R) { R = (R + 1) % k; cnt++; } // 进行条件统计 while(L != R && Left(p[L],p[R])) { R = (R + 1) % k; cnt++; } cnt--; L++; ans = max(cnt,ans); } } return ans; } int main(){ while(~scanf("%d", &n) && 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; }
相关文章推荐
- 对高效管理时间的个人观点分享
- 将博客搬至CSDN
- 【LeetCode】LeetCode——第3题: Longest Substring Without Repeating Characters
- Python项目小结
- Jenkins--持续集成变成可能
- POJ 3614 Sunscreen(贪心+优先队列)
- iOS NSURLSession网络请求(get/post/下载)
- oracle如何写一个函数
- Robot Framework与Web界面自动化测试学习笔记:简单例子
- 2015 读书笔记--告诉我你怎样去生活
- liunx常用命令
- mysql删除重复记录语句的方法
- js ajax 分页
- mysql索引之二:数据结构及算法原理
- 【转】【已解决】Android中ActionBar中不显示overflow(就是三个点的那个按钮)--不错
- HTTP协议的报文结构
- Unity3D 的物理渲染和光照模型
- Day3
- PXE网络装机
- NYOJ448寻找最大数(贪心)