POJ2187凸包
来源:互联网 发布:javlib最新域名获取 编辑:程序博客网 时间:2024/06/04 17:46
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.PrintWriter;import java.io.StreamTokenizer;import java.math.BigInteger;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.Comparator;import java.util.Scanner;import java.util.Stack;import java.util.StringTokenizer;public class Main{ public static void main(String[] args) throws IOException{ InputReader in = new InputReader(System.in) ; StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt() ; P[] p = new P[n] ; for(int i = 0 ; i < n ; i++) p[i] = new P(in.nextInt() , in.nextInt()) ; out.println( new Task().solve(p) ) ; out.flush() ; }}class Task{ public long solve(P[] p){ double res = 0 ; P[] qs = convexHull(p) ; for(int i = 0 , n = qs.length ; i < n ; i++){ for(int j = 0 ; j < i ; j++){ res = Math.max(res, qs[i].dist(qs[j])) ; } } return (long)res ; } public P[] convexHull(P[] ps){ int n = ps.length , k = 0 ; if(n <= 0) return ps ; Arrays.sort(ps , new Psort()); P[] qs = new P[n+2] ; for(int i = 0 ; i < n ; i++){ while(k > 1 && qs[k-1].sub(qs[k-2]).det(ps[i].sub(qs[k-1])) <= 0) k-- ; qs[k++] = ps[i] ; } for(int i = n - 2 , t = k ; i >= 0 ; i--){ while(k > t && qs[k-1].sub(qs[k-2]).det(ps[i].sub(qs[k-1])) <= 0) k-- ; qs[k++] = ps[i] ; } P[] res = new P[k-1] ; System.arraycopy(qs , 0 , res , 0 , k-1) ; return res ; } }class P{ public int x , y ; public P(){ } public P(int x , int y){ this.x = x ; this.y = y ; } public P sub(P o){ return new P(x - o.x , y - o.y) ; } public double dot(P o){ return x * o.x + y * o.y ; } public double det(P o){ return x * o.y - y * o.x ; } public double dist(P o){ return Math.pow(x - o.x, 2) + Math.pow(y - o.y, 2) ; }}class Psort implements Comparator<P>{ public int compare(P o1, P o2) { if(o1.x != o2.x) return o1.x - o2.x ; return o1.y - o2.y ; } }class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); }}
0 0
- poj2187 凸包问题
- poj2187 凸包
- poj2187凸包
- POJ2187凸包
- POJ2187->凸包
- poj2187(凸包)
- poj2187(凸包)
- poj2187(凸包)
- POJ2187--凸包--Beauty Contest
- poj2187 凸包直径模板
- poj2187 Beauty Contest 凸包
- POJ2187 Beauty Contest 凸包+旋转卡壳
- poj2187 Beauty Contest 凸包+旋转卡壳
- POJ2187 Andrew凸包+旋转卡壳
- poj2187 Beauty Contest 凸包 Graham扫描
- 【POJ2187】Beauty Contest-凸包+旋转卡壳
- Poj2187(最远点对距离)凸包+旋转卡壳
- poj2187 凸包+graham+旋转卡壳+最远点对
- Linux Log Files Location And How Do I View Logs Files on Linux?
- 欢迎使用CSDN-markdown编辑器
- 由not($(this)).animate(styles)引发的记录
- 如何使用vector的reserve和resize方法
- LeetCode_Construct Binary Tree from Inorder and Postorder Traversal
- POJ2187凸包
- 事务---Java事务
- ubuntu14.04交叉编译vlc2.1.5源码,编译出在win32下运行的程序
- java中Collections.sort() 排序函数的用法
- 虚拟机中的Linux系统无法识别U盘
- 以太网 ip udp数据分析
- TCP/UDP常见端口参考
- linux内核I2C子系统学习
- 可视区域操作