UVa 1303 - Wall
题目:有非常多点。修一座最短的围墙把素有点围起来,使得全部点到墙的距离不小于l。
分析:计算几何,凸包。
假设。没有距离l的限制。则答案就是凸包的周长了。有了距离限制事实上是添加了2*π*l。
证明:如上图。在凸包外做相应边的矩形;
多边形内角和 = 180*(n-2);
外角和 = 360*n - 内角和 = 180*n+360;
全部直角和为2*90*n;
所以,全部扇形的内角和为360;即围栏比凸多边形周长多2*π*l。
说明:坐标比較a3.x < b.x 写成 a.x < b.y 查了好久才发现。o(╯□╰)o
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath> using namespace std; typedef struct pnode
{
int x,y;
double d;
}point;
point P[1005]; //叉乘
int crossProduct(point a, point b, point c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
} //两点间距离
double dist(point a, point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+0.0);
} //坐标比較
int cmp1(point a, point b)
{
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
} //斜率比較
int cmp2(point a, point b)
{
int cp = crossProduct(P[0], a, b);
if (!cp) return a.d < b.d;
return cp > 0;
} //凸包
double Graham(int n)
{
sort(P+0, P+n, cmp1);
for (int i = 1 ; i < n ; ++ i)
P[i].d = dist(P[0], P[i]);
sort(P+1, P+n, cmp2); int top = 1;
for (int i = 2 ; i < n ; ++ i) {
while (top > 0 && crossProduct( P[top-1], P[top], P[i] ) < 0) -- top;
P[++ top] = P[i];
}
P[++ top] = P[0]; double L = 0.0;
for ( int i = 0 ; i < top ; ++ i )
L += dist(P[i], P[i+1]);
return L;
} int main()
{
int t,n,l;
while (~scanf("%d",&t))
while (t --) {
scanf("%d%d",&n,&l);
for (int i = 0 ; i < n ; ++ i)
scanf("%d%d",&P[i].x,&P[i].y); printf("%.0lf\n",Graham(n)+acos(-1.0)*2*l);
if (t) printf("\n");
}
return 0;
}
UVa 1303 - Wall的更多相关文章
- 【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall
UVa 10618 Fixing the Great Wall 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=361 ...
- UVa 10384 - The Wall Pushers
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 11040 (水题) Add bricks in the wall
题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...
- UVa 900 - Brick Wall Patterns
题目大意:用1*2的砖头建n*2的墙,问有多少种不同的砖头排列方式?与斐波那契序列相似. #include <cstdio> #define MAXN 60 #define N 50 un ...
- UVA 11040 Add bricks in the wall
https://vjudge.net/problem/UVA-11040 找规律 #include<cstdio> using namespace std; ][]; int main() ...
- UVA 11040 Add bricks in the wall(线性组合)
砖块上的数字最终都可以看作是最后一行的线性组合,独立变元最多9个. 这类题的一般做法,线性组合都可以列出方程然后高斯消元. 对于这道题,只要确定最后一行剩下的4个变量就好了,对于最后一行的j位置,它对 ...
- UVA - 1045 The Great Wall Game(二分图最佳完美匹配)
题目大意:给出棋盘上的N个点的位置.如今问将这些点排成一行或者一列.或者对角线的最小移动步数(每一个点都仅仅能上下左右移动.一次移动一个) 解题思路:暴力+二分图最佳完美匹配 #include < ...
- UVa 11040 Add bricks in the wall (水题递推)
题意:给定一个金字塔,除了最后一行,每个数都等于支撑它的两个数的和,现在给奇数行的左数奇数位置,求整个金字塔. 析:很容易看出来,从下往上奇数行等于 a[i][j] = (a[i-2][j-1] - ...
- UVa 1336 Fixing the Great Wall (区间DP)
题意:给定 n 个结点,表示要修复的点,然后机器人每秒以 v 的速度移动,初始位置在 x,然后修复结点时不花费时间,但是如果有的结点暂时没修复, 那么每秒它的费用都会增加 d,修复要花费 c,坐标是 ...
随机推荐
- 各种SSD SMART 信息 转
intel SSD Toolbox SMART信息 解释:03 – Spin Up Time (磁头加载时间)The average time it takes the spindle to spin ...
- 多进程多线程GDB调试 (转)
多进程多线程GDB调试 一.线程调试指南: 1. gdb attach pid 挂载到调试进程 2. gdb$ set scheduler-locking on 只执行当前选定线程的 ...
- Iptables 指南 1.1.19
Iptables 指南 1.1.19 Oskar Andreasson oan@frozentux.net Copyright © 2001-2003 by Oskar Andreasson 本文在符 ...
- Delphi-Cross-Socket
Delphi-Cross-Socket GITHUB:https://github.com/winddriver/Delphi-Cross-Socket # Delphi 跨平台 Socket 通讯库 ...
- android studio 引用aar
在:libs拷贝对应的文件 build.gradle repositories { flatDir { dirs 'libs' }}dependencies { // c ...
- windows下的Nginx+Squid+Tomcat+Memcached集群
- js自动补全实例
var oInputField ,oPopDiv , oColorsUl,aColors; //初始化变量 function initVars(modelId,divId,ulId){ oInputF ...
- FFMPEG视音频编解码零基础学习方法 【荐】
在CSDN上的这一段日子,接触到了很多同行业的人,尤其是使用FFMPEG进行视音频 编解码的人,有的已经是有多年经验的“大神”,有的是刚开始学习的初学者.在和大家探讨的过程中,我忽然发现了一个问题:在 ...
- Android.mk文件简单分析
Android.mk文件简单分析 一个Android.mk文件用来向编译系统描写叙述须要编译的源码.详细来说:该文件是GNUMakefile的一小部分.会被编译系统解析一次或多次. 能够在每个Andr ...
- Android布局优化之ViewStub、include、merge使用与源码分析
在开发中UI布局是我们都会遇到的问题,随着UI越来越多,布局的重复性.复杂度也会随之增长.Android官方给了几个优化的方法,但是网络上的资料基本上都是对官方资料的翻译,这些资料都特别的简单,经常会 ...