poj_2187凸包,暴力解法
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
struct Point{
int x,y;
Point(int x=0,int y=0):x(x),y(y){}
};
typedef Point Vector;
bool cmp(const Point &p,const Point &q)
{
if(p.x!=q.x) return p.x<q.x;
return p.y<q.y;
}
Vector operator -(Point A,Point B){return Vector(A.x-B.x,A.y-B.y);}
Point p[50010],ch[50010];
int Cross(Vector A,Vector B){return A.x*B.y-A.y*B.x;}
int ConvexHull(Point *p,int n,Point *ch)
{
sort(p,p+n,cmp);
int m=0;
for(int i=0;i<n;i++){
while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;
ch[m++]=p[i];}
int k=m;
for(int i=n-2;i>=0;i--)
{
while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;
ch[m++]=p[i];
}
if(n>1)
m--;
return m;
}
int Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}
int Length(Vector A){return Dot(A,A);}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
int x=ConvexHull(p,n,ch);
int ans=0;
for(int i=0;i<x-1;i++)
for(int j=i+1;j<x;j++)
if(Length(ch[i]-ch[j])>ans)
ans=Length(ch[i]-ch[j]);
printf("%d\n",ans);
}
return 0;
}
poj_2187凸包,暴力解法的更多相关文章
- dsu on tree ——附带buff的暴力解法
这篇博客只是简单叙述思想(因为ML太弱了),具体例题请转其他博客. dsu on tree,许多OI将其归于启发式合并,当然如果你能理解更好,这只是一个理解方式罢了. 思想简述 顾名思义,这个算法是处 ...
- poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)
链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...
- P1162_填涂颜色(JAVA语言)(速看!全洛谷最暴力解法!QAQ)
思路:看了看数据n<=30,于是我们可以暴力求解(主要是BFS学的不咋地~2333).枚举每个0的位置,看上下左右四个方向上是否都有1.都有1的话说明被1包围,即在闭合圈的内部,开个数组标记一下 ...
- Convert Sorted List to Binary Search Tree&&Convert Sorted Array to Binary Search Tree——暴力解法
Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in as ...
- 51nod 2020 排序相减(暴力解法)
题目: 代码: #include <bits\stdc++.h> using namespace std; int trim(int x){ ]; ;i < ; i++){ a[i] ...
- [ACM_暴力] ZOJ 3710 [Friends 共同认识 最终认识 暴力]
Alice lives in the country where people like to make friends. The friendship is bidirectional and if ...
- 多种解法解决n皇后问题
多种解法解决n皇后问题 0x1 目的 深入掌握栈应用的算法和设计 0x2 内容 编写一个程序exp3-8.cpp求解n皇后问题. 0x3 问题描述 即在n×n的方格棋盘上,放置n个皇后,要求每 ...
- LeetCode算法题-Valid Perfect Square(Java实现-四种解法)
这是悦乐书的第209次更新,第221篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第77题(顺位题号是367).给定正整数num,写一个函数,如果num是一个完美的正方形 ...
- LeetCode算法题-Intersection of Two Arrays(Java实现-四种解法)
这是悦乐书的第207次更新,第219篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第75题(顺位题号是349).给定两个数组,编写一个函数来计算它们的交集.例如: 输入: ...
随机推荐
- MyBatis学习总结(6)——调用存储过程
一.提出需求 查询得到男性或女性的数量, 如果传入的是0就女性否则是男性 二.准备数据库表和存储过程 create table p_user( id int primary key auto_incr ...
- hdu 5077 NAND(打表)2014 Asia regional 鞍山站 H题
题目链接:点击打开链接 题意:就是一个按位运算的一个函数.问最少经过多少步运算能够得到给定数. 思路:不是我投机取巧想打表.是特么这题仅仅能打表.. .打表思想用能够得到的数的集合表示状态bfs:最后 ...
- Swift基础--定位
// // ViewController.swift // JieCoreLocation // // Created by jiezhang on 14-10-4. // Copyright (c) ...
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第6章节--在SharePoint2013中开发、集成和构建应用程序 总结
BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第6章节--在SharePoint2013中开发.集成和构建应用程序 总结 SharePoint开发已经 ...
- 宿主机mac os无法连接到虚拟机centos
宿主机: Mac OS 10.9.2 虚拟机: [root@localhost ~]# cat /etc/redhat-release CentOS release 6.4 (Final) [root ...
- How to Hide Zip Files Inside a Picture Without any Extra Software in Windows
http://www.howtogeek.com/119365/how-to-hide-zip-files-inside-a-picture-without-any-extra-software/ c ...
- TSNE——目前最好的降维方法
转自:http://blog.csdn.net/u012162613/article/details/45920827 1.流形学习的概念 流形学习方法(Manifold Learning),简称流形 ...
- MYSQL binlog 日志内容查看
记录mysql数据库真正执行更改的所有操作(DML语句),不包含那些没有修改任何数据的语句,不会记录select和show这样的语句. 二进制日志的作用: 1. 可以完成主从复制的功能 2. 进行恢复 ...
- mybatis的sql中字段两种映射(映射到实体)方式
mybatis的xml配置文件中,字段映射的两种方式: 1.resultMap标签中将数据库的字段与实体类中的字段对应: <resultMap id="BaseResultMap&qu ...
- svn创建分支的做法
作者:朱金灿 来源:http://blog.csdn.net/clever101 1. 首先选择你要创建分支的工作目录,如下图: 2.选择要创建分支的路径.注释以及版本,选择HEADrevision ...