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).给定两个数组,编写一个函数来计算它们的交集.例如: 输入: ...
随机推荐
- codevs——T1814 最长链
http://codevs.cn/problem/1814/ 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 De ...
- HDU 3625
有点置换群的味道. 当撞开一个门后,能打开一连串的门,即是可以排成一个圈.求的是种数,于是,可以使用第一类斯特林数,求出撞了0~K次的种数. 但是,注意,当第一个门为独自一个圈时,是不可行的,因为这代 ...
- POJ 1306
其实求的这个数的式子化简一下,就是C(N,M)..... #include <iostream> #include <algorithm> #include <cstdi ...
- aliyun Ubuntu 14.04 64bit OpenJDK Tomcat7 install
my work environment: aliyun Ubuntu 14.04 64位 first phase:apt-get update (it is very important,oth ...
- sqlite学习笔记11:C语言中使用sqlite之删除记录
最后一节,这里记录下怎样删除数据. 前面全部的代码都继承在这里了,在Ubuntu14.04和Mac10.9上亲測通过. #include <stdio.h> #include <st ...
- WCF 无法激活服务,由于它不支持 ASP.NET 兼容性。已为此应用程序启用了 ASP.NET 兼容性
作者:jiankunking 出处:http://blog.csdn.net/jiankunking 错误信息: 无法激活服务.由于它不支持 ASP.NET 兼容性.已为此应用程序启用了 ASP.NE ...
- RAC IP 地址修改
RAC 修改IP: 版本信息: REDHAT AS5 ORACLE 11G R2, 两个节点. 修改如下: 1.修改/etc/host(rac1,rac2) 192.168.3.205 rac-s ...
- [luogu P2123] 皇后游戏 解题报告(贪心)
题目链接:https://www.luogu.org/problemnew/show/P2123 题目大意: 给定a数组和b数组,要求最小化c数组中的最大值 题解: 考虑微扰法,推一波式子先 设$x= ...
- python中各项目文件含义(新手可看)
其他不用多说,这里主要阐述三个概念,包.模块.类 包我们可以看作一个包含__init__.py 和一系列.py 文件的文件夹,包含__init__.py这样做的目的是为了区别包和普通字符串,读者可以试 ...
- Mysqldump逻辑备份与恢复
文档结构: mysqldump备份影响性能,可能会把内存里面的热数据给冲刷掉,5.7后,新增一个参数,innodb_buffer_pool_dump_pct,控制每个innodb_buffer中转存活 ...