UVA - 1606 Amphiphilic Carbon Molecules 极角扫描法
题目:点击查看题目
思路:这道题的解决思路是极角扫描法。极角扫描法的思想主要是先选择一个点作为基准点,然后求出各点对于该点的相对坐标,同时求出该坐标系下的极角,按照极角对点进行排序。然后选取点与基准点形成的线对点进行扫描,基准线为遍历选取,扫描线扫过的点,减去基准线扫过的点即为所要求的点的数量。同时注意到我们要求的是线两边的两种点的数量,于是一种点比如黑点可以旋转180度,然后之考察这180度内的百点数量即可。本题的基准点选取复杂度为O(n),极角排序复杂度O(nlogn),扫描复杂度O(n),复杂度为O(N2logN + N2),可视为O(N2logN)
AC代码:
#include <iostream>
#include <cmath>
#include <algorithm> using namespace std; const int maxn = + ; struct point{
int x, y, color;
double angle;
bool operator < (const point& temp) const {
return angle < temp.angle;
}
}point[maxn], cpoint[maxn]; bool judge(struct point& A, struct point& B) {
return A.x*B.y - A.y*B.x >= ;
} int solve(int n) {
if(n <= ) return n; int ans = ;
for(int i = ; i < n; i++) {
int index = ;
for(int j = ; j < n; j++) {
if(j == i) continue;
cpoint[index].x = point[j].x - point[i].x;
cpoint[index].y = point[j].y - point[i].y;
if(point[j].color) {
cpoint[index].x = -cpoint[index].x;
cpoint[index].y = -cpoint[index].y;
}
cpoint[index].angle = atan2(cpoint[index].y, cpoint[index].x);
index++;
}
sort(cpoint, cpoint+index); int st = , ed = , cnt = ;
while(st < index) {
if(st == ed) {
ed = (ed + )%index;
cnt++;
}
while(st != ed && judge(cpoint[st], cpoint[ed])) {
ed = (ed + )%index;
cnt++;
} cnt--;
st++; ans = max(ans, cnt);
}
}
return ans;
} int main()
{
int n;
while(cin >> n && n) {
for(int i = ; i < n; i++) {
cin >> point[i].x >> point[i].y >> point[i].color;
}
cout << solve(n) << endl;
}
return ;
}
UVA - 1606 Amphiphilic Carbon Molecules 极角扫描法的更多相关文章
- UVa 1606 Amphiphilic Carbon Molecules (扫描法+极角排序)
题意:平面上有 n 个点,每个点不是黑的就是白的,现在要放一个隔板,把它们分成两部分,使得一侧的白点数加上另一侧的黑点数最多. 析:这个题很容易想到的就是暴力,不妨假设隔板至少经过两个点,即使不经过也 ...
- UVA - 1606 Amphiphilic Carbon Molecules (计算几何,扫描法)
平面上给你一些具有黑或白颜色的点,让你设置一个隔板,使得隔板一侧的黑点加上另一侧的白点数最多.隔板上的点可视作任意一侧. 易知一定存在一个隔板穿过两个点且最优,因此可以先固定以一个点为原点,将其他点中 ...
- 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)
Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of ...
- uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx
Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new classof ...
- UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)
任意线可以贪心移动到两点上.直接枚举O(n^3),会TLE. 所以采取扫描法,选基准点,然后根据极角或者两两做叉积比较进行排排序,然后扫一遍就好了.旋转的时候在O(1)时间推出下一种情况,总复杂度为O ...
- UVA - 1606 Amphiphilic Carbon Molecules(两亲性分子)(扫描法)
题意:平面上有n(n <= 1000)个点,每个点为白点或者黑点.现在需放置一条隔板,使得隔板一侧的白点数加上另一侧的黑点数总数最大.隔板上的点可以看做是在任意一侧. 分析:枚举每个基准点i,将 ...
- UVa 1606 - Amphiphilic Carbon Molecules
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 【UVa】1606 Amphiphilic Carbon Molecules(计算几何)
题目 题目 分析 跟着lrj学的,理解了,然而不是很熟,还是发上来供以后复习 代码 #include <bits/stdc++.h> using namespace std; ; stru ...
- POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线
从TLE的暴力枚举 到 13313MS的扫描线 再到 1297MS的简化后的扫描线,简直感觉要爽翻啦.然后满怀欣喜的去HDU交了一下,直接又回到了TLE.....泪流满面 虽说HDU的时限是2000 ...
随机推荐
- apache poi根据模板导出excel
需要预先新建编辑好一个excel文件,设置好样式. 编辑好输出的数据,根据excel坐标一一对应. 支持列表数据输出,列表中列合并. 代码如下: package com.icourt.util; im ...
- ZT 父子进程共享文件描述符
转贴自倒霉熊的博客 [linux学习笔记-2]父子进程共享文件描述符 (2009-03-02 23:03:17) 转载▼ 标签: 学习 linux 子进程 文件描述符 杂谈 分类: 学习 #inclu ...
- *92. Reverse Linked List II (follow up questions)
Reverse a linked list from position m to n. Do it in one-pass and in-place Note: 1 ≤ m ≤ n ≤ length ...
- python入门4 python查看数据类型及类型转换
查看数据类型:type() 类型转换:int(),float(),char(),ord(),str(),bool() #coding:utf-8 #/usr/bin/python "&quo ...
- 【转载】#446 - Deciding Between an Abstract Class and an Interface
An abstract class is a base class that may have some members not implemented in the base class, but ...
- 贪心,Gene Assembly,ZOJ(1076)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=76 解题报告: 1.类似活动安排问题. 2.输出格式要注意. #inc ...
- mac 上安装lua
mac 安装lua google了好个看起来都不怎么好操作,这个是在命令行下操作的很简单. http://www.lua.org/download.html curl -R -O http://www ...
- HDU 1160(两个值的LIS,需dfs输出路径)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1160 FatMouse's Speed Time Limit: 2000/1000 MS (Java/ ...
- hbase 数据拷贝
由于运营数据太大,另外避免影响正常访问,所以需要临时拷贝部分数据到临时表中. bin/hbase org.apache.hadoop.hbase.mapreduce.CopyTable [--star ...
- asp.net mvc Post上传文件大小限制 (转载)
最近发现在项目中使用jQuery.form插件上传比较大的文件时,上传不了,于是改了下web.config的上传文件最大限制. <configuration> <system.web ...