E - Rebuild UVALive - 7187 (二次函数极值问题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5531
The ruins form a closed path on an x-y plane, which has n endpoints. The endpoints locate on (x1,y1), (x2,y2), …,(xn,yn) respectively. Endpoint i and endpoint i−1 are adjacent for 1<i≤n, also endpoint 1 and endpoint n are adjacent. Distances between any two adjacent endpoints are positive integers.
To rebuild, they need to build one cylindrical pillar at each endpoint, the radius of the pillar of endpoint i is ri. All the pillars perpendicular to the x-y plane, and the corresponding endpoint is on the centerline of it. We call two pillars are adjacent if and only if two corresponding endpoints are adjacent. For any two adjacent pillars, one must be tangent externally to another, otherwise it will violate the aesthetics of Ancient ACM Civilization. If two pillars are not adjacent, then there are no constraints, even if they overlap each other.
Note that ri must not be less than 0 since we cannot build a pillar with negative radius and pillars with zero radius are acceptable since those kind of pillars still exist in their neighbors.
You are given the coordinates of n endpoints. Your task is to find r1,r2,…,rn which makes sum of base area of all pillars as minimum as possible.

For example, if the endpoints are at (0,0), (11,0), (27,12), (5,12), we can choose (r1, r2, r3, r4)=(3.75, 7.25, 12.75, 9.25). The sum of base area equals to 3.752π+7.252π+12.752π+9.252π=988.816…. Note that we count the area of the overlapping parts multiple times.
If there are several possible to produce the minimum sum of base area, you may output any of them.
The first line of each case contains one positive integer n, the size of the closed path. Next n lines, each line consists of two integers (xi,yi) indicate the coordinate of the i-th endpoint.
1≤t≤100
3≤n≤104
|xi|,|yi|≤104
Distances between any two adjacent endpoints are positive integers.
If there are several possible ways to produce the minimum sum of base area, you may output any of them.
4
0 0
11 0
27 12
5 12
5
0 0
7 0
7 3
3 6
0 6
5
0 0
1 0
6 12
3 16
0 12
3.75
7.25
12.75
9.25
157.08
6.00
1.00
2.00
3.00
0.00
IMPOSSIBLE
#include <bits/stdc++.h>
#define met(a, b) memset(a, b, sizeof(a))
#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int>P;
const int maxn=;
const double eps=1e-;
const double pi=acos(-);
P p[maxn];
double d[maxn],f[maxn];
double dist(P a,P b)
{
return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}
int main()
{
int T;
cin>>T;
while(T--){
int n;
cin>>n;
for(int i=;i<=n;i++)cin>>p[i].first>>p[i].second;
for(int i=;i<=n;i++){
if(i==n)d[i]=dist(p[i],p[]);
else d[i]=dist(p[i],p[i+]);
}
double maxx=0x3f3f3f3f,minn=;//极值上下限
f[]=;
for(int i = ; i <=n ; i++)
{
f[i] = d[i-] - f[i-];
if(i%== && f[i] < maxx)//若为偶数点,则该圆的半径只能减小这么多(即第一个圆的半径只能增大这么多),更新最大值下限
{
maxx = f[i];
}
if(i%== && (-f[i]) > minn)//若为奇数点,且此时f[i]小与0,则必须第一个圆的半径更新为该值,更新最小值上限
{
minn = -f[i];
}
}
if(minn >= maxx + eps )//无解
{
printf("IMPOSSIBLE\n");
continue;
}
if(n%==){//奇数个点,有解则必有唯一解,否则无解
double x=;//第一个圆的半径x=(d1-d2+d3-d4...)/2,唯一解.
for(int i=;i<=n;i++){
if(i%==)x+=d[i];
else x-=d[i];
}
x/=;
if(x<=minn-eps||x>=maxx+eps){
cout<<"IMPOSSIBLE"<<endl;
continue;
}
double area=;
for(int i=;i<=n;i++){
if(i%==)area+=(f[i]+x)*(f[i]+x);
else area+=(f[i]-x)*(f[i]-x);
}
area*=pi;
printf("%.2f\n",area);
for(int i=;i<=n;i++){
if(i%==)printf("%.2f\n",f[i]+x);
else printf("%.2f\n",f[i]-x);
}
}
else{//偶数情况构造二次函数,y=a*x*x+b*x+c
double now=;
for(int i=;i<=n;i++){
if(i%==)now+=d[i];
else now-=d[i];
}
if(fabs(now)>eps||minn-maxx>eps){
cout<<"IMPOSSIBLE"<<endl;
continue;
}
double a=n;
double b=,c=;
for(int i=;i<=n;i++){
if(i%==){
b+=*f[i];
}
else{
b-=*f[i];
}
c+=f[i]*f[i];
}
double x=-b/(*a);
if(x<minn+eps)x=minn;
if(x>maxx-eps)x=maxx;
double area=a*x*x+b*x+c;
area*=pi;
printf("%.2f\n",area);
for(int i=;i<=n;i++){
if(i%==)printf("%.2f\n",f[i]+x);
else printf("%.2f\n",f[i]-x);
}
}
}
return ;
}
E - Rebuild UVALive - 7187 (二次函数极值问题)的更多相关文章
- (转载)SVM-基础(五)
作为支持向量机系列的基本篇的最后一篇文章,我在这里打算简单地介绍一下用于优化 dual 问题的 Sequential Minimal Optimization (SMO) 方法.确确实实只是简单介绍一 ...
- SVM个人学习总结
SVM个人学习总结 如题,本文是对SVM学习总结,主要目的是梳理SVM推导过程,以及记录一些个人理解. 1.主要参考资料 [1]Corres C. Support vector networks[J] ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- HDU 5531 Rebuild (2015长春现场赛,计算几何+三分法)
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- Visual Studio 中 Build 和 Rebuild 的区别
因为之前写的程序比较小,编译起来比较快,所以一直都没有太在意 Build 和 Rebuild 之间的区别,后来发现两个还是有很大不同. Build 只针对在上次编译之后更改过的文件进行编译,在项目比较 ...
- 解决 node-gyp rebuild 卡住 的问题
node-gyp在编译前会首先尝试下载node的headers文件,像这样: gyp http GET https://nodejs.org/download/release/v6.8.1/node- ...
- AndroidStudio中make Project、clean Project、Rebuild Project的区别
1.Make Project:编译Project下所有Module,一般是自上次编译后Project下有更新的文件,不生成apk. 2.Make Selected Modules:编译指定的Modul ...
- Rebuild Instance 操作详解 - 每天5分钟玩转 OpenStack(37)
上一节我们讨论了 snapshot,snapshot 的一个重要作用是对 instance 做备份. 如果 instance 损坏了,可以通过 snapshot 恢复,这个恢复的操作就是 Rebuil ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
随机推荐
- 国内OLED产业与三星到底是差之千里还是近在咫尺?
此前,市面上几乎大部分智能手机搭载的刘海屏,都是来自三星的AMOLED屏幕.虽然三星总是被诟病为中国手机厂商提供的是"次品",不过没办法,OLED屏幕的核心技术.产能等都掌握在三星 ...
- 目标检测评价标准(mAP, 精准度(Precision), 召回率(Recall), 准确率(Accuracy),交除并(IoU))
1. TP , FP , TN , FN定义 TP(True Positive)是正样本预测为正样本的数量,即与Ground truth区域的IoU>=threshold的预测框 FP(Fals ...
- MAT工具在MacBook的安装
当Java应用出现内存溢出的问题的时候,需要拿工具分析dump文件的.JDK自带的jvisualvm和jhat都可以使用,另外还有一个工具是 Memory Analyzer Tool ,支持独立运行和 ...
- PowerDesigner 破解版,汉化包!
链接:https://pan.baidu.com/s/1R_6g6keo2Y4_V0c1ImeFbA 密码:ncju
- 专题复习--背包问题+例题(HDU 2602 、POJ 2063、 POJ 1787、 UVA 674 、UVA 147)
*注 虽然没什么人看我的博客但我还是要认认真真写给自己看 背包问题应用场景给定 n 种物品和一个背包.物品 i 的重量是 w i ,其价值为 v i ,背包的容量为C.应该如何选择装入背包中的物品,使 ...
- UML-线程标示法
继续前一章<缓存策略>,既然用缓存,那如何保证数据同步呢?即:缓存里的数据和DB里的数据一致. 解决:LocalProducts每隔N分钟查询并更新它的缓存(定时器) 如果LocalPro ...
- HTTP协议(二):作用
前言 上一节我们简单介绍了一下TCP/IP协议族的基本情况,知道了四大层的职责,也了解到我们这一族的家族成员以及他们的能力. 无良作者把我这个主角变成了配角,让我很不爽,好在我打了作者一顿,没错,这次 ...
- SpringCloud学习之Config分布式配置中心(八)
统一配置中心概述 如果微服务架构中没有使用统一配置中心时,所存在的问题: 配置文件分散在各个项目里,不方便维护 配置内容安全与权限,实际开发中,开发人员是不知道线上环境的配置的 更新配置后,项目需要重 ...
- EOJ Monthly 2020.1 E. 数的变幻
题目链接:https://acm.ecnu.edu.cn/contest/247/problem/E/ 这道题是cf原题: Codeforces Round #608 (Div. 2) E. Comm ...
- POJ 3013 SPFA算法,邻接表的使用
Big Christmas Tree Time Limit: 3000MS Memory Limit: 131072K Total Submissions: 19029 Accepted: 4 ...