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

分析:枚举每个基准点i,将一条直线绕这个点旋转,每当扫过一个点,就可以动态修改两侧的点数。

对于--sum,

1、如果while循环是因为s==j退出的,则其减的是if(s == j)时暂且多加上去的一个sum,这种情况是,所有的点都在基准线的左边。

2、如果while循环是因为!left(vec[j], vec[s])退出的,则其减的是因为基准线移动,上一个与基准点相连的点已不在基准线左边的情况,这种情况同样适用于旋转基准线但是没有新增点,所有sum自然会减少。

3、本题技巧是将黑点旋转180°,这样就可以化统计一侧白点和一侧黑点为统计一侧点的数量的问题。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
using namespace std;
int n;
struct Point{
int x, y, color;
double angle;
void read(){
scanf("%d%d%d", &x, &y, &color);
}
void Set(int xx, int yy, int cc){
x = xx;
y = yy;
if(cc){//如果为黑点,则相对于基准点旋转180°
x = -x;
y = -y;
}
angle = atan2(y, x);
}
bool operator<(const Point& rhs)const{
return dcmp(angle, rhs.angle) == -1;
}
}p[MAXN], vec[MAXN];
bool left(Point A, Point B){
return A.x * B.y - B.x * A.y >= 0;//叉乘
}
int solve(){
if(n <= 3) return n;
int ans = 0;
for(int i = 0; i < n; ++i){//基准点i
int cnt = 0;
for(int j = 0; j < n; ++j){
if(i != j){
vec[cnt++].Set(p[j].x - p[i].x, p[j].y - p[i].y, p[j].color);//点j相对于基准点i的相对坐标
}
}
sort(vec, vec + cnt);
int sum = 2;
int s = 0;//扫描射线
for(int j = 0; j < cnt; ++j){//以基准点为原点,枚举所有经过除基准点之外的点的射线
if(s == j){
(s += 1) %= cnt;
++sum;
}
while(s != j && left(vec[j], vec[s])){
(s += 1) %= cnt;
++sum;
}
--sum;
ans = Max(ans, sum);
}
}
return ans;
}
int main(){
while(scanf("%d", &n) == 1){
if(!n) return 0;
for(int i = 0; i < n; ++i){
p[i].read();
}
printf("%d\n", solve());
}
return 0;
}

UVA - 1606 Amphiphilic Carbon Molecules(两亲性分子)(扫描法)的更多相关文章

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

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

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

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

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

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

  4. UVA - 1606 Amphiphilic Carbon Molecules 极角扫描法

    题目:点击查看题目 思路:这道题的解决思路是极角扫描法.极角扫描法的思想主要是先选择一个点作为基准点,然后求出各点对于该点的相对坐标,同时求出该坐标系下的极角,按照极角对点进行排序.然后选取点与基准点 ...

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

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

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

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

  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. UVa 1606 (极角排序) Amphiphilic Carbon Molecules

    如果,没有紫书上的翻译的话,我觉得我可能读不懂这道题.=_=|| 题意: 平面上有n个点,不是白点就是黑点.现在要放一条直线,使得直线一侧的白点与另一侧的黑点加起来数目最多.直线上的点可以看作位于直线 ...

随机推荐

  1. Java的clone方法效率问题

    在Java中,经常会需要新建一个对象,很多情况下,需要这个新建的对象和现有的某个对象保持属性一致. 那么,就有两种方式来实现这个对象的构造: ①通过新建一个对象,为这个对象的属性根据原有对象的属性来进 ...

  2. [排错] VO对象和POJO对象的关系

    这或许是一个很蠢的笔记吧...... 这次项目中, 作为一个新人, 没少被这两个概念虐得死去活来的, 现在特别做一次记录, 关于它们二者之间在项目中的应用. 在这里呢, 就不再赘述 VO(view o ...

  3. java#keytool#生成私钥证书库、公钥证书库

    原文,向作者致敬

  4. oracle数据库的完整性约束规则详解

    CSDN日报20170303--<百亿互金平台救火故事> 程序员2月书讯 社区有奖问答--一起舞动酷炫的iOS动画 基于Spark的分布式深度学习和认知计算 oracle数据库的完 ...

  5. Lamda简单使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. SciPy 输入输出

    章节 SciPy 介绍 SciPy 安装 SciPy 基础功能 SciPy 特殊函数 SciPy k均值聚类 SciPy 常量 SciPy fftpack(傅里叶变换) SciPy 积分 SciPy ...

  7. Window Server 2019 配置篇(8)- 利用MDT定制自动加入域的脚本

    我们要更改我们的镜像文件,使得自动安装完成后,计算机已经自动在域中 删除在WDS-server上做的自动部署,我们在上面安装一下MDT和ADK文件,这两个文件如果需要的话可以评论,我会在随后上传 之后 ...

  8. springboot 中单机 redis 实现分布式锁

    在微服务中经常需要使用分布式锁,来执行一些任务.例如定期删除过期数据,在多个服务中只需要一个去执行即可. 以下说明非严格意义的分布式锁,因为 redis 实现严格意义的分布式锁还是比较复杂的,对于日常 ...

  9. 005.Delphi插件之QPlugins,IQNotify通知

    演示的界面如下,拖动滚动条,百分比圆和进度条也是会跟着动的 主程序的代码如下 unit Frm_Main; interface uses Winapi.Windows, Winapi.Messages ...

  10. SQL添加列、非空、默认值

    use MarcoBarcode go alter table [dbo].[WorkOrderRepairSheet] ADD needRepair int go ALTER TABLE [dbo] ...