POJ3384 Feng Shui
嘟嘟嘟
昨天我看到的这道题,今天终于A了。
写这道题的时间其实并不长,主要是我为这题现学了一个半平面相交(虽然是\(O(n ^ 2)\)的……)
思路说难也不难,关键是第一步的转化得想到。
首先可以肯定的是两圆要离得尽量远。
把每一条边向内移动\(r\)的距离,得到一个新的比原来小的凸包,那么这个凸包表示的是两个圆的圆心可以到达的地方。于是就转化成了求最远点对了。
向内移动\(r\)的距离我是用向量做的:对于边\(AB\),得到旋转\(90\)度后的向量\(\overrightarrow{AB'}\),那么端点\(A\)旋转后的点\(A' = A + \overrightarrow{AB'} * ( \frac{r}{| \overrightarrow{AB'}|})\);\(B\)同理。
然后对于新的边\(A'B'\),搞一次半平面相交即可。
然后最远点对就是套路了:跑一边凸包后搞一遍旋转卡壳,完事了。
坑点就是这题\(spj\)估计是小学生写的,一是取最大值的时候,如果当前值\(\geqslant\)最大值也得更新;二是横坐标小的点得先输出……
还有就是求最远点对其实暴力就够了……
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-10;
const int maxn = 1e3 + 5;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
int n, cnt;
db r;
struct Point
{
db x, y;
Point operator - (const Point& oth)const
{
return (Point){x - oth.x, y - oth.y};
}
db operator * (const Point& oth)const
{
return x * oth.y - oth.x * y;
}
Point operator * (const db& d)const
{
return (Point){x * d, y * d};
}
friend inline Point rot(const Point& A)
{
return (Point){-A.y, A.x};
}
friend inline db dis(const Point& A)
{
return A.x * A.x + A.y * A.y;
}
}p[maxn], a[maxn];
Point calc(Point N, Point A, Point B)
{
Point AB = rot(B - A);
return N - (AB * (-r / sqrt(dis(A - B))));
}
int tot = 0;
Point b[maxn];
db cross(Point C, Point A, Point B)
{
return (B - A) * (C - A);
}
void addCross(Point A, Point B, Point C, Point D)
{
db s1 = (C - A) * (D - A), s2 = (D - B) * (C - B);
b[++tot] = A - (A - B) * (s1 / (s1 + s2));
}
void Cut(Point A, Point B)
{
tot = 0;
a[cnt + 1] = a[1];
for(int i = 1; i <= cnt; ++i)
{
if(cross(a[i], A, B) < eps)
{
b[++tot] = a[i];
if(cross(a[i + 1], A, B) > eps) addCross(A, B, a[i], a[i + 1]);
}
else if(cross(a[i + 1], A, B) < -eps) addCross(A, B, a[i], a[i + 1]);
}
for(int i = 1; i <= tot; ++i) a[i] = b[i];
cnt = tot;
}
Point S;
int st[maxn], top = 0;
bool cmp(Point A, Point B)
{
db s = (A - S) * (B - S);
if(fabs(s) > eps) return s > eps;
return dis(A - S) < dis(B - S) - eps;
}
void Graham()
{
int id = 1; top = 0;
for(int i = 2; i <= cnt; ++i)
if(a[i].x < a[id].x - eps || (fabs(a[i].x - a[id].x) < eps && a[i].y < a[id].y - eps)) id = i;
if(id != 1) swap(a[1].x, a[id].x), swap(a[1].y, a[id].y);
S.x = a[1].x; S.y = a[1].y;
sort(a + 2, a + cnt + 1, cmp);
st[++top] = 1;
for(int i = 2; i <= cnt; ++i)
{
while(top > 1 && (a[st[top]] - a[st[top - 1]]) * (a[i] - a[st[top - 1]]) < eps) top--;
st[++top] = i;
}
}
Point Ans1, Ans2;
int nxt(int x)
{
if(++x > top) x = 1;
return x;
}
db area(Point A, Point B, Point C)
{
return fabs((B - A) * (C - A));
}
void rota()
{
db Max = 0;
for(int i = 1, j = 3; i <= top; ++i)
{
while(nxt(j) != i && area(a[st[i]], a[st[i + 1]], a[st[j]]) < area(a[st[i]], a[st[i + 1]], a[st[nxt(j)]]) + eps) j = nxt(j);
if(Max < dis(a[st[i]] - a[st[j]]) + eps)
{
Max = dis(a[st[i]] - a[st[j]]);
Ans1 = a[st[i]], Ans2 = a[st[j]];
}
if(Max < dis(a[st[i + 1]] - a[st[j]]) + eps)
{
Max = dis(a[st[i + 1]] - a[st[j]]);
Ans1 = a[st[i + 1]], Ans2 = a[st[j]];
}
}
}
int main()
{
while(scanf("%d%lf", &n, &r) != EOF)
{
cnt = n;
for(int i = 1; i <= n; ++i) p[i].x = read(), p[i].y = read();
for(int i = 1; i <= n; ++i) a[i] = p[i];
p[n + 1] = p[1];
for(int i = 1; i <= n; ++i)
{
Point A = calc(p[i], p[i + 1], p[i]), B = calc(p[i + 1], p[i + 1], p[i]);
Cut(A, B);
}
Graham(); st[top + 1] = st[1];
rota();
if(Ans1.x > Ans2.x + eps) swap(Ans1.x, Ans2.x), swap(Ans1.y, Ans2.y);
printf("%.4f %.4f %.4f %.4f\n", Ans1.x, Ans1.y, Ans2.x, Ans2.y);
}
return 0;
}
POJ3384 Feng Shui的更多相关文章
- POJ 3384 Feng Shui (半平面交)
Feng Shui Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3743 Accepted: 1150 Speci ...
- POJ 3384 Feng Shui 半平面交
题目大意:一个人很信"Feng Shui",他要在房间里放两个圆形的地毯. 这两个地毯之间可以重叠,可是不能折叠,也不能伸到房间的外面.求这两个地毯可以覆盖的最大范围.并输出这两个 ...
- POJ 3384 Feng Shui(计算几何の半平面交+最远点对)
Description Feng shui is the ancient Chinese practice of placement and arrangement of space to achie ...
- poj 3384 Feng Shui (Half Plane Intersection)
3384 -- Feng Shui 构造半平面交,然后求凸包上最远点对. 这题的题意是给出一个凸多边形区域,要求在其中放置两个半径为r的圆(不能超出凸多边形区域),要求求出两个圆心,使得多边形中没有被 ...
- POJ3384:Feng Shui——题解
http://poj.org/problem?id=3384 题目大意:给一个顺时针序的多边形,求在里面放半径为r的两个圆使得两圆覆盖的面积最大,求出这样的圆的坐标. ———————————————— ...
- POJ 3384 Feng Shui --直线切平面
题意:房间是一个凸多边形,要在里面铺设两条半径为r的圆形地毯,可以重叠,现在要求分别铺设到哪,使地毯所占的地面面积最大. 解法:要使圆形地毯所占面积最大,圆形地毯一定是与边相切的,这样才能使尽量不重叠 ...
- POJ 3384 Feng Shui(半平面交向内推进求最远点对)
题目链接 题意 : 两个圆能够覆盖的最大多边形面积的时候两个圆圆心的坐标是多少,两个圆必须在多边形内. 思路 : 向内推进r,然后求多边形最远的两个点就是能覆盖的最大面积. #include < ...
- POJ 3384 Feng Shui
http://poj.org/problem?id=3384 题意:给一个凸包,求往里面放两个圆(可重叠)的最大面积时的两个圆心坐标. 思路:先把凸包边往内推R,做半平面交,然后做旋转卡壳,此时得到最 ...
- POJ 3384 Feng Shui 凸包直径 + 半平面交
G++一直没有过了 换成 C++果断A掉了...It's time to bet RP. 题意:给一个多边形,然后放进去两个圆,让两个圆的覆盖面积尽量最大,输出两个圆心的坐标. 思路:将多边形的边向里 ...
随机推荐
- [转] .NET出现频率非常高的笔试题
又到了金三银四的跳槽季,许多朋友又开始跳槽了,这里我简单整理了一些出现频率比较高的.NET笔试题,希望对广大求职者有所帮助. 一..net基础 1. a=10,b=15,请在不使用第三方变量的情况下 ...
- android 加载图片框架--Glide使用详解
一.简介 Glide,一个被google所推荐的图片加载库,作者是bumptech.这个库被广泛运用在google的开源项目中,包括2014年的google I/O大会上发布的官方app.(PS:众所 ...
- 【SSH网上商城项目实战18】过滤器实现购物登录功能的判断
转自:https://blog.csdn.net/eson_15/article/details/51425010 上一节我们做完了购物车的基本操作,但是有个问题是:当用户点击结算时,我们应该做一个登 ...
- Spring与Web
一.定义页面及Servlet 在jsp页面加入以下,避免乱码 <meta charset="utf-8"> <body> <form action=& ...
- hdu 1159(DP+字符串最长公共序列)
http://blog.csdn.net/a_eagle/article/details/7213236 公共序列可以用一个二维数组dp[i][j]保存每个点时的最大数字,本质就是一个双向比较. dp ...
- sql: MySQL and Microsoft SQL Server Stored Procedures IN, OUT using csharp code
MySQL存储过程: #插入一条返回值涂聚文注 DELIMITER $$ DROP PROCEDURE IF EXISTS `geovindu`.`proc_Insert_BookKindOut` $ ...
- 创建一个Dribbble的作品展示
Most designers on dribbble have a personal portfolio website that usually consists of a name and a b ...
- Windows server 2008 Tips
Tips for remote server in domain. Some Definition user [user] group workgroup domain Local account d ...
- volley5--Request<T>类的介绍
源码: /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, V ...
- 关于 <mvc:argument-resolvers> 的一次使用记录
使用场景: 项目里面在做一个请求时候发现,不同的请求,有些请求会跳转到 spring mvc的自定义方法中,有些却不进去.自定义的方法: <mvc:annotation-driven > ...