POJ1113凸包
来源:互联网 发布:json格式转换工具 编辑:程序博客网 时间:2024/05/21 15:49
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() , r = in.nextInt() ; P[] p = new P[n] ; for(int i = 0 ; i < n ; i++) p[i] = new P(in.nextInt() , in.nextInt()) ; out.printf("%.0f", new Task().solve(p , r) ) ; out.flush() ; }}class Task{ public double solve(P[] p , int r){ double res = 0 ; P[] qs = convexHull(p) ; for(int i = 0 , n = qs.length ; i < n ; i++){ res += qs[i].dist(qs[(i + 1) % n]) ; } res += 2.0 * Math.PI * r ; return 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{ 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.sqrt( 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
- POJ1113(凸包)
- poj1113 凸包
- POJ1113 Wall 凸包
- poj1113 凸包
- poj1113 凸包
- poj1113--Wall(凸包)
- POJ1113凸包
- poj1113 Wall 凸包
- poj1113 Wall --凸包
- poj1113(凸包)
- poj1113 Wall【凸包】
- poj1113--凸包
- poj1113 Wall 凸包
- 【凸包_Graham】Wall POJ1113
- POJ1113 wall 简单凸包
- POJ1113 凸包周长计算
- kyeremal-poj1113-Wall-凸包
- 凸包初学(POJ1113)
- 黑马程序员--2015.6.29java基础笔记---GUI总结
- java学习之旅46--面向对象_19_多态_内存分析
- iOS 在一个UILabel里显示不同的颜色,给文字加下划线
- 【网易公开日】《梦幻西游》手游服务器如何实现200万玩家同时在线?(技术篇)
- CSS hack
- POJ1113凸包
- Handler实现与机制 && Blocking Queue && IdleHandler使用
- iOS-协议
- sync、fsync、fdatasync、fflush函数
- 导入Opencv自带Sample项目 face-detection 报错
- windows下编译安装wireshark出现的问题及解决方法
- 【java0005】 多线程-线程的状态图
- android中handler用法总结
- HSV颜色空间颜色阈值