题目:点击查看题目

思路:这道题的解决思路是极角扫描法。极角扫描法的思想主要是先选择一个点作为基准点,然后求出各点对于该点的相对坐标,同时求出该坐标系下的极角,按照极角对点进行排序。然后选取点与基准点形成的线对点进行扫描,基准线为遍历选取,扫描线扫过的点,减去基准线扫过的点即为所要求的点的数量。同时注意到我们要求的是线两边的两种点的数量,于是一种点比如黑点可以旋转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 极角扫描法的更多相关文章

  1. UVa 1606 Amphiphilic Carbon Molecules (扫描法+极角排序)

    题意:平面上有 n 个点,每个点不是黑的就是白的,现在要放一个隔板,把它们分成两部分,使得一侧的白点数加上另一侧的黑点数最多. 析:这个题很容易想到的就是暴力,不妨假设隔板至少经过两个点,即使不经过也 ...

  2. UVA - 1606 Amphiphilic Carbon Molecules (计算几何,扫描法)

    平面上给你一些具有黑或白颜色的点,让你设置一个隔板,使得隔板一侧的黑点加上另一侧的白点数最多.隔板上的点可视作任意一侧. 易知一定存在一个隔板穿过两个点且最优,因此可以先固定以一个点为原点,将其他点中 ...

  3. 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)

    Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of ...

  4. uva 1606 amphiphilic carbon molecules【把缩写写出来,有惊喜】(滑动窗口)——yhx

    Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new classof ...

  5. UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)

    任意线可以贪心移动到两点上.直接枚举O(n^3),会TLE. 所以采取扫描法,选基准点,然后根据极角或者两两做叉积比较进行排排序,然后扫一遍就好了.旋转的时候在O(1)时间推出下一种情况,总复杂度为O ...

  6. UVA - 1606 Amphiphilic Carbon Molecules(两亲性分子)(扫描法)

    题意:平面上有n(n <= 1000)个点,每个点为白点或者黑点.现在需放置一条隔板,使得隔板一侧的白点数加上另一侧的黑点数总数最大.隔板上的点可以看做是在任意一侧. 分析:枚举每个基准点i,将 ...

  7. UVa 1606 - Amphiphilic Carbon Molecules

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. 【UVa】1606 Amphiphilic Carbon Molecules(计算几何)

    题目 题目 分析 跟着lrj学的,理解了,然而不是很熟,还是发上来供以后复习 代码 #include <bits/stdc++.h> using namespace std; ; stru ...

  9. POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线

    从TLE的暴力枚举 到 13313MS的扫描线  再到 1297MS的简化后的扫描线,简直感觉要爽翻啦.然后满怀欣喜的去HDU交了一下,直接又回到了TLE.....泪流满面 虽说HDU的时限是2000 ...

随机推荐

  1. 2017软件测试_HW1_最近遇到的编程问题

     最近遇到的错误:我对着网页源代码编写了一段爬虫语句,运行没有提示有错误,而且 可以抓取到全部的数据,但是不能按照要求将这些数据分到制定的位置. 发现问题原因:我把抓取到的字段对着网页源码看了一下,发 ...

  2. pip 安装下载好的tensorflow

    pip --default-timeout=100 install C:\Users\Administrator\Downloads\tensorflow-1.12.0-cp37-cp37m-win_ ...

  3. 如何在ubuntu上安装virtualbox的driver module vboxdrv

    干净的ubuntu安装完毕之后是没有vboxdrv这个driver module的. 新建一个folder jerry_virtualbox: 使用wget下载virtualbox安装包:https: ...

  4. CSS 替换元素和非替换元素 行内非替换元素

    html元素也可以分为替换元素和非替换元素 1.替换元素 替换元素是由浏览器根据表示的元素和属性决定显示的内容. 例如:<img src="./image.jpg" /> ...

  5. C语言 条件编译(if )

    #include <stdio.h> #define NUM -1 int main(int argc, const char * argv[]) { #if NUM > 0 pri ...

  6. 线程概念的外延 Threading Terminology-What Are Threads

    https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Multithreading/AboutThrea ...

  7. Fiddler拦截并动态修改网页内容简易教程

    Fiddler默认可以拦截全局http请求,再加上它具备的脚本功能,可以很简单的达到动态修改网页内容的目的. 1.启动Fiddler 2.打开Rules->Customize Rules..., ...

  8. Mac上传文件到Linux服务器

    1. 打开 终端,选择 2.选择安全文件传输,输入连接主机IP 3.输入主机名 4.输入yes,然后输入主机密码,按回车结束 确认连接 输入远程主机密码 5.连接成功,上传文件 put 本地文件路径 ...

  9. Android学习笔记_30_常用控件使用

    一.状态栏通知(Notification): 如果需要查看消息,可以拖动状态栏到屏幕下方即可查看消息.发送消息的代码如下: public void sendNotice(View v){ int ic ...

  10. SqlSugar批量添加修改问题

    直接InsertRange空集合会报错,如果我们是同时执行多个添加或修改,不要共用一个上下文,最好是在方法里面声明上下文进行区分,不然容易报错 //如果同时执行多个添加,更新 操作不要共用一个上下文, ...