hdu6755 Mow
半平面交+数组模拟双端队列
人生第一次代码过两百行啊...加油加油
#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的更多相关文章
- HDU 6762 Mow (2020 Multi-University Training Contest 1 1012) 半平面交
Mow 题目链接 分析 将多边形的边向内部缩 r 个单位长度,然后这些边所围成的内部区域,就是圆心的合法范围,该范围也是一个多边形,假设面积是\(a\),周长是\(b\),那么可以知道圆可以覆盖的面积 ...
- java中获取路径的几种基本的方法
package com.ygh.blog.realpath; import java.io.File; import java.io.IOException; import java.io.Input ...
- TPC-H生成.tbl文件导入postgresql数据库的坑
数据库project好好的不用主流的MySQL和Microsoft server而要求用听都没听过的postgresql (当然,可能你三个都没听过) 这里的坑主要是把生成的那八张.tbl的表导入pg ...
- js实现多张图片每隔一秒换一张图片
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlkAAAHWCAIAAADLlAuAAAAgAElEQVR4nOzd5XNc157w+/l7bt2n6t
- mysql触发器,答题记录表同步教学跟踪(用户列表)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVQAAAOOCAIAAABgEw4AAAAgAElEQVR4nOy92VcT27r/zX+xLtflvt
- java调用sqlldr导入csv文件数据到临时表
package cn.com.file;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File; ...
- CSS布局(二)
本节内容:position.float.clear.浮动布局例子.百分比宽度 position CSS中的position属性设置元素的位置.属性值:static.relative.fixed.abs ...
- 这些HTML、CSS知识点,面试和平时开发都需要 No5-No7
系列知识点汇总 这些HTML.CSS知识点,面试和平时开发都需要 No1-No4(知识点:HTML.CSS.盒子模型.内容布局) 这些HTML.CSS知识点,面试和平时开发都需要 No5-No7(知识 ...
- C#基础整理参数
基本概念 把数据传入方法中,可以使方法有多个返回值. 参数的传递 值参数,通过将实参的值复制到形参的方式传递数据.值参数的实参可以是变量或者是表达式
随机推荐
- No configuration file found and no output filename configured via Cli option.报错
webpack手动配置webpack.config.js文件,打包时出现的报错,可以试试这种解决方案 报错如下: No configuration file found and no output f ...
- ceph SSD HDD分离与openstack调用
本例子ceph L版本采用的是filestore,而不是bluestore. 一.查看class类型,只有一个hdd,.Luminous 为每个OSD添加了一个新的属性:设备类.默认情况下,OSD将根 ...
- Windows10系统下安装配置Tomcat 9.0.1
Tomcat9.0.1下载:https://tomcat.apache.org/download-90.cgi 配置jdk的环境变量(略) 在系统变量里新建变量名:CATALINA_BASE,变量值: ...
- postman不能启动的问题解决
1.postman启动不了,启动时提示“postman resolving transporter buffer”,不能正常启动 第一步,删除:在chrome-更多工具-扩展程序里面删除了postma ...
- 注册中心(Eureka/Consul)
基于SpringBoot1.5.4与SpringCloud(Dalston.SR2)的SpringCloud学习博客,转载请标明出处,O(∩_∩)O谢谢 - Spring Cloud简介 Spring ...
- .netcore项目codefirst时使用的配置文件是appsettings.json
.netcore项目创建完毕后,会发现项目中有好几个配置文件: appsettings.json appsettings.Development.json appsettings.Production ...
- SharePoint删除图片库文件
SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current. ...
- PDF无法复制/打印/编辑怎么办?
PDF的内容不能复制/打印/编辑,主要有两种原因: 1.PDF文件设置了权限保护 2.PDF内容是图片 第一种,PDF被设置了权限保护 这种的特点是可以选中PDF里的文字,但无法复制 PDF格式标准内 ...
- HotSpot的类模型(2)
在前一篇文章 HotSpot的二分模型中已经讲过,HotSpot采用了OOP-Klass模型描述Java的类和对象.Klass模型采用Klass类及相关子类来表示具体的Java类,可以理解这些类为Ja ...
- 轻松让HTML5可以显示桌面通知Notification非常实用
使用Notification的流程 1.检查浏览器是否支持Notification2.检查浏览器的通知权限3.如果权限不够则申请获取权限4.创建消息通知5.展示消息通知 Notification AP ...