半平面交+数组模拟双端队列

人生第一次代码过两百行啊...加油加油

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iomanip> #define ld long double
using namespace std; const int maxn = 1e3;
const ld pi = acosl(-);
const ld eps = 1e-;//控制精度 int n;
int head, tail;
ld r, cost1, cost2; typedef struct Grid
{//棋盘
ld x,y;
Grid(double a = , double b = ){x = a, y = b;}//构造函数,结构体对象创建时执行
} point , Vector ;//point:类型为Grid的数据类型;Vector与point结构相同,数据类型名称不同 typedef struct Net
{
point a,b;
Net() {}//重载构造函数,目的是以形如line x;的方式定义直线,避免定义时确定参数的复杂性
Net(point i, point j){a = i, b = j;}
} line ; point node[maxn], p[maxn];
line l[maxn], L[maxn], q[maxn]; Vector operator - (point a, point b) // V需大写,避免与vector混淆
{
return Vector(b.x - a.x, b.y - a.y);
}//矢量定义 double operator * (Vector a, Vector b)
{
return (a.x * b.y - a.y * b.x);
}//叉乘 ld getangle(Vector t)
{
return atan2(t.y, t.x);//返回一个(-pi,pi]的角度
}//获得某个矢量的极角 ld getangle(line t)
{
return atan2(t.b.y - t.a.y, t.b.x - t.a.x);
}//获得某条直线的极角 bool cmp(line a, line b)
{
Vector v1 = (a.b - a.a), v2 = (b.b - b.a);
ld A = getangle(v1), B = getangle(v2);
if(fabs(A - B) < eps){
return (v1 * (b.b - a.a) >= );//靠左边的丢在后面,方便双端队列去重
}
return A < B;
}//决定根据极角排序的直线的优先级 bool check()
{
ld ans = ;
for(int i = ; i < n- ; i++){
ans += (node[i] - node[]) * (node[i+] - node[]);
}
if(ans < ) return false;
return true;
}//检查point输入顺序进行调整 true为逆时针 point getnode(line a, line b)//求两直线(线段)交点,一般式三参数暴力求解
{
ld a1 = a.b.y - a.a.y, b1 = a.a.x - a.b.x, c1 = a.b.x * a.a.y - a.a.x * a.b.y;
ld a2 = b.b.y - b.a.y, b2 = b.a.x - b.b.x, c2 = b.b.x * b.a.y - b.a.x * b.b.y;
ld D = a1 * b2 - a2 * b1;
//Dx/D,Dy/D,注意c1、c2移至右侧变号
return point((c2 * b1 - b2 * c1) / D, (c1 * a2 - a1 * c2) / D);
} bool on_right(line a, line b, line c)//观察a、b交点与c的关系
{
point n = getnode(a, b);
if((c.b - c.a) * (n - c.a) < ){//交点在右侧/下方
return true;
}
return false;
} line narrow_line(line x)//实现直线平移,勾画出圆心轨迹
{
ld dx = x.b.x - x.a.x, dy = x.b.y - x.a.y;
Vector turnv;//旋转矢量
turnv.x = -dy, turnv.y = dx; ld m = sqrtl(dx * dx + dy * dy);
turnv.x = turnv.x / m * r;
turnv.y = turnv.y / m * r;
//求对应坐标
x.b.x += turnv.x;
x.b.y += turnv.y;
x.a.x += turnv.x;
x.a.y += turnv.y;
return x;
} void narrow_polygon()//模拟圆心轨迹
{
for(int i = ; i <= n- ; i++){
L[i] = narrow_line(l[i]);
}
} bool HPI()
{
sort(L,L+n,cmp);//按极角排序
head = , tail = ;
int cnt = ;
for(int i = ; i < n- ; i++){
Vector v1 = L[i].b - L[i].a, v2 = L[i+].b - L[i+].a;//?
if(fabs(getangle(v1) - getangle(v2)) < eps){
continue;
}
L[cnt++] = L[i];
}
L[cnt++] = L[n-]; /////正片开始
for(int i = ; i < cnt ; i++){//注意下标
while(tail - head > && on_right(q[tail-], q[tail-], L[i])) tail--;//符合onright规则,删去上一条直线
while(tail - head > && on_right(q[head], q[head+], L[i])) head++;//头部同理
q[tail++] = L[i];
}
//换个角度看世界,最后检验q[head]以及q[tail-1],q[tail]实际为空
while(tail - head > && on_right(q[tail-], q[tail-], q[head])) tail--;
while(tail - head > && on_right(q[head], q[head+], q[tail-])) head++; if((tail - head) >= ) return true;
return false;
} ld get_S()//求初始面积
{
ld ans = ;
for(int i = ; i < n ; i++){
ans += fabs((node[i] - node[]) * (node[(i+)%n] - node[]));
}
return ans / ;
} ld dis(point a, point b)
{
ld dx = b.x - a.x, dy = b.y - a.y;
return sqrtl(dx * dx + dy * dy);
}//两点间距离 ld get_inS()//内部半平面交 面积
{
ld res = ;
int tot = ;
for(int i = head ; i < tail- ; i++){
p[tot++] = getnode(q[i], q[i+]);
}
p[tot++] = getnode(q[tail-], q[head]); for(int i = ; i < tot- ; i++){
res += fabs((p[i] - p[]) * (p[i+] - p[]));
}
res /= ; for(int i = ; i < tot- ; i++){
res += dis(p[i], p[i+]) * r;
}// c * r
res += dis(p[], p[tot - ]) * r; return res + r * r * pi;
} int main(){
//freopen("mow.in","r",stdin);
int T;cin >> T;
while( T-- )
{
cin >> n >> r >> cost1 >> cost2;
for(int i = n- ; i >= ; i--){
cin >> node[i].x >> node[i].y;
}//本题中为顺时针方向,因而逆序存点,以确保直线左侧为内侧 if(check()){//逆
for(int i = ; i < n- ; i++){//
l[i] = line(node[i], node[i+]);
}
l[n-] = line(node[n-], node[]);
}else{//顺
for(int i = ; i < n- ; i++){
l[i] = line(node[i+],node[i]);
}
l[n-] = line(node[], node[n-]);
}//0 ~ n-1 narrow_polygon(); ld s = get_S();//草坪面积
ld ans = s * cost1;//手动割草费用 if(HPI()){
ld mowable = get_inS();//机器割草面积
ans = min(ans, mowable * cost2 + (s - mowable) * cost1);
}
cout << fixed << setprecision() << ans << "\n"; } return ;
}
//实现直线平移,勾画出圆心轨迹

hdu6755 Mow的更多相关文章

  1. HDU 6762 Mow (2020 Multi-University Training Contest 1 1012) 半平面交

    Mow 题目链接 分析 将多边形的边向内部缩 r 个单位长度,然后这些边所围成的内部区域,就是圆心的合法范围,该范围也是一个多边形,假设面积是\(a\),周长是\(b\),那么可以知道圆可以覆盖的面积 ...

  2. java中获取路径的几种基本的方法

    package com.ygh.blog.realpath; import java.io.File; import java.io.IOException; import java.io.Input ...

  3. TPC-H生成.tbl文件导入postgresql数据库的坑

    数据库project好好的不用主流的MySQL和Microsoft server而要求用听都没听过的postgresql (当然,可能你三个都没听过) 这里的坑主要是把生成的那八张.tbl的表导入pg ...

  4. js实现多张图片每隔一秒换一张图片

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlkAAAHWCAIAAADLlAuAAAAgAElEQVR4nOzd5XNc157w+/l7bt2n6t

  5. mysql触发器,答题记录表同步教学跟踪(用户列表)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVQAAAOOCAIAAABgEw4AAAAgAElEQVR4nOy92VcT27r/zX+xLtflvt

  6. java调用sqlldr导入csv文件数据到临时表

    package cn.com.file;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File; ...

  7. CSS布局(二)

    本节内容:position.float.clear.浮动布局例子.百分比宽度 position CSS中的position属性设置元素的位置.属性值:static.relative.fixed.abs ...

  8. 这些HTML、CSS知识点,面试和平时开发都需要 No5-No7

    系列知识点汇总 这些HTML.CSS知识点,面试和平时开发都需要 No1-No4(知识点:HTML.CSS.盒子模型.内容布局) 这些HTML.CSS知识点,面试和平时开发都需要 No5-No7(知识 ...

  9. C#基础整理参数

    基本概念 把数据传入方法中,可以使方法有多个返回值. 参数的传递 值参数,通过将实参的值复制到形参的方式传递数据.值参数的实参可以是变量或者是表达式

随机推荐

  1. 深度学习“四大名著”发布!Python、TensorFlow、机器学习、深度学习四件套!

    Python 程序员深度学习的"四大名著": 这四本书着实很不错!我们都知道现在机器学习.深度学习的资料太多了,面对海量资源,往往陷入到"无从下手"的困惑出境. ...

  2. jQuery处理默认配置参数(将一个或多个对象的内容合并到目标对象)

    问题 我们在封装一个函数时, 需要别人传递一个json对象作为参数, 而用户可能只传入部分参数, 这是就可以利用$extend()来与合并到默认JSON参数合并. // 程序需要的参数 var def ...

  3. 【数位dp】CF 55D Beautiful numbers

    题目 Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer n ...

  4. idea2020.1.2破解,亲测可行,激活至2089年!

    一.下载最新版IDEA2020安装包 官网:https://www.jetbrains.com/idea/download/ 旧版:https://www.jetbrains.com/idea/dow ...

  5. 重学 Java 设计模式:实战状态模式「模拟系统营销活动,状态流程审核发布上线场景」

    作者:小傅哥 博客:https://bugstack.cn - 原创系列专题文章 沉淀.分享.成长,让自己和他人都能有所收获! @ 目录 一.前言 二.开发环境 三.状态模式介绍 四.案例场景模拟 1 ...

  6. 创建新用户后无法切换 su: failed to execute /bin/bash: Permission denied

    创建新用户后无法切换 su: failed to execute /bin/bash: Permission denied   当使用 su username 从root切换用户时显示 su: fai ...

  7. c++随机生成树

    分析 当我们写完一道题,自认为它是正解,但是交上去却WA的时候,我们该怎么办呢 当我们已经想出了一道的暴力解法,又想出了一种比较优秀的解法,但不知道这种解法对错与否,我们该怎么办呢 答案显然是对拍 对 ...

  8. 配置类需要标注@Configuration却不知原因?那这次就不能给你涨薪喽

    专注Java领域分享.成长,拒绝浅尝辄止.关注公众号[BAT的乌托邦]开启专栏式学习,拒绝浅尝辄止.本文 https://www.yourbatman.cn 已收录,里面一并有Spring技术栈.My ...

  9. Window - 安装 Jenkins

    安装方式 war 包放 Tomcat 下 直接安装 jenkins.msi 环境准备 安装 jdk.tomcat,参考:https://www.cnblogs.com/poloyy/p/1326781 ...

  10. day77 作业

    目录 一.完成todolist案例 二.商品页面 一.完成todolist案例 <!DOCTYPE html> <html lang="en"> <h ...