BZOJ 1113 Wall ——计算几何
凸包第一题。
自己认为自己写的是Andrew
其实就是xjb写出来居然过掉了测试。
刚开始把pi定义成了int,调了半天
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)
#define eps 1e-10
#define ll long long
#define mp make_pair const double pi=acos(-1.0); struct Vector{
double x,y;
void print()
{
printf("Vector - > (%.3f,%.3f)\n",x,y);
}
};
struct Point{
double x,y;
void print()
{
printf("Point - > (%.3f,%.3f)\n",x,y);
}
}; double operator * (Vector a,Vector b)
{return a.x*b.y-a.y*b.x;} Vector operator + (Vector a,Vector b)
{Vector ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;} Vector operator - (Vector a,Vector b)
{Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;} Point operator + (Point a,Vector b)
{Point ret;ret.x=a.x+b.x;ret.y=a.y+b.y;return ret;} Vector operator * (Vector a,double b)
{Vector ret;ret.x=a.x*b;ret.y=a.y*b;return ret;} Vector operator - (Point a,Point b)
{Vector ret;ret.x=a.x-b.x;ret.y=a.y-b.y;return ret;} double dot (Vector a,Vector b)
{return a.x*b.x+a.y*b.y;} double len(Vector a)
{return sqrt(dot(a,a));} int n,l,top,sta[1005]; Point a[1005]; bool cmp(Point a,Point b)
{return fabs(a.x-b.x)<eps?a.y<b.y:a.x<b.x;} int main()
{
scanf("%d%d",&n,&l);
F(i,1,n) scanf("%lf%lf",&a[i].x,&a[i].y);
sort(a+1,a+n+1,cmp);
sta[++top]=1;
F(i,2,n)
{
while (top>=2&&((a[i]-a[sta[top]])*(a[sta[top]]-a[sta[top-1]]))<0) top--;
sta[++top]=i;
}
D(i,n-1,1)
{
while (top>=2&&((a[i]-a[sta[top]])*(a[sta[top]]-a[sta[top-1]]))<0) top--;
sta[++top]=i;
}
double ans=0;
F(i,2,top)
{
ans+=len(a[sta[i]]-a[sta[i-1]]);
// (a[sta[i]]-a[sta[i-1]]).print();
}
ans+=2.0*l*pi;
// printf("%.6f\n",pi);
// printf("%.6f\n",2.0*l*pi);
printf("%d\n",(int)(ans+0.5));
}
BZOJ 1113 Wall ——计算几何的更多相关文章
- POJ 1113 Wall(计算几何の凸包)
Description Once upon a time there was a greedy King who ordered his chief Architect to build a wall ...
- poj 1113:Wall(计算几何,求凸包周长)
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28462 Accepted: 9498 Description ...
- POJ 1113 Wall(思维 计算几何 数学)
题意 题目链接 给出平面上n个点的坐标.你需要建一个围墙,把所有的点围在里面,且围墙距所有点的距离不小于l.求围墙的最小长度. \(n \leqslant 10^5\) Sol 首先考虑如果没有l的限 ...
- 【POJ】1113 Wall(凸包)
http://poj.org/problem?id=1113 答案是凸包周长+半径为l的圆的周长... 证明?这是个坑.. #include <cstdio> #include <c ...
- POJ 1113 Wall 凸包求周长
Wall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26286 Accepted: 8760 Description ...
- ●POJ 1113 Wall
题链: http://poj.org/problem?id=1113 题解: 计算几何,凸包 题意:修一圈围墙把给出的点包围起来,且被包围的点距离围墙的距离不能小于L,求围墙最短为多少. 答案其实就是 ...
- 2018.07.04 POJ 1113 Wall(凸包)
Wall Time Limit: 1000MS Memory Limit: 10000K Description Once upon a time there was a greedy King wh ...
- POJ 1113 Wall【凸包周长】
题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- BZOJ 1113: [Poi2008]海报PLA
1113: [Poi2008]海报PLA Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1025 Solved: 679[Submit][Statu ...
随机推荐
- log日志应用 自定义的log
package com.kxd.utils; import java.util.Hashtable; import android.util.Log; /** * The class for prin ...
- vue分环境打包配置方法一
直接上代码配置: 首先是config下面的文件修改 dev.env.js 'use strict' const merge = require('webpack-merge') const prod ...
- POJ 3140 Contestants Division (树形DP,简单)
题意: 有n个城市,构成一棵树,每个城市有v个人,要求断开树上的一条边,使得两个连通分量中的人数之差最小.问差的绝对值.(注意本题的M是没有用的,因为所给的必定是一棵树,边数M必定是n-1) 思路: ...
- ABAP,Java, nodejs和go语言的web server编程
ABAP and Java see my blog. nodejs 用nodejs现成的express module,几行代码就能写个server出来: var express = require(' ...
- shell 简单脚本 2
#!/bin/bash source /etc/profile APPLICATIONS_HOME="/cpic/cpicapp/cpic_analy/jars" APPLICAT ...
- 二、pandas入门
import numpy as np import pandas as pd Series: #创建Series方法1 s1=pd.Series([1,2,3,4]) s1 # 0 1 # 1 2 # ...
- CPP-网络/通信:SOCKET
客户端实现代码: //引入头文件 #include <WinSock2.h> //客户端创建Socket////////////////////////////////////////// ...
- javase(14)_java基础增强
一.Eclipse的使用 1.在eclipse下Java程序的编写和run as,debug as,及java运行环境的配置. 2.快捷键的配置,常用快捷键: •内容提示:Alt + / •快速修复: ...
- http post get 同步异步
下面首先介绍一下一些基本的概念---同步请求,异步请求,GET请求,POST请求. 1.同步请求从因特网请求数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据完成,才可以进行下一步操作.也 ...
- java面试宝典第二弹
arraylist和linklist的区别,hashmap和hashset的区别,常用的集合有哪些 一.基础内容 容器就是一种装其他各种对象的器皿.java.util包 容器:Set, List, M ...