题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5531

Problem Description
Archaeologists find ruins of Ancient ACM Civilization, and they want to rebuild it.

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.

 
Input
The first line contains an integer t indicating the total number of test cases. The following lines describe a test case.

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.

 
Output
If such answer doesn't exist, then print on a single line "IMPOSSIBLE" (without the quotes). Otherwise, in the first line print the minimum sum of base area, and then print n lines, the i-th of them should contain a number ri, rounded to 2 digits after the decimal point.

If there are several possible ways to produce the minimum sum of base area, you may output any of them.

 
Sample Input
3
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
 
Sample Output
988.82
3.75
7.25
12.75
9.25
157.08
6.00
1.00
2.00
3.00
0.00
IMPOSSIBLE
 
Source
 
Recommend
hujie
题解:对于题目分析可得一些性质:
1:一个圆的半径确定,其他的圆的半径也随之确定.
2:对于n,分奇偶讨论,奇数情况下化简可得:若有解必有唯一解,否则无解.偶数情况下构造二次函数有一变元,从而转换为二次函数的极值问题.
3:限制:半径必须都>=0
#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 (二次函数极值问题)的更多相关文章

  1. (转载)SVM-基础(五)

    作为支持向量机系列的基本篇的最后一篇文章,我在这里打算简单地介绍一下用于优化 dual 问题的 Sequential Minimal Optimization (SMO) 方法.确确实实只是简单介绍一 ...

  2. SVM个人学习总结

    SVM个人学习总结 如题,本文是对SVM学习总结,主要目的是梳理SVM推导过程,以及记录一些个人理解. 1.主要参考资料 [1]Corres C. Support vector networks[J] ...

  3. 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild

    Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  4. HDU 5531 Rebuild (2015长春现场赛,计算几何+三分法)

    Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  5. Visual Studio 中 Build 和 Rebuild 的区别

    因为之前写的程序比较小,编译起来比较快,所以一直都没有太在意 Build 和 Rebuild 之间的区别,后来发现两个还是有很大不同. Build 只针对在上次编译之后更改过的文件进行编译,在项目比较 ...

  6. 解决 node-gyp rebuild 卡住 的问题

    node-gyp在编译前会首先尝试下载node的headers文件,像这样: gyp http GET https://nodejs.org/download/release/v6.8.1/node- ...

  7. AndroidStudio中make Project、clean Project、Rebuild Project的区别

    1.Make Project:编译Project下所有Module,一般是自上次编译后Project下有更新的文件,不生成apk. 2.Make Selected Modules:编译指定的Modul ...

  8. Rebuild Instance 操作详解 - 每天5分钟玩转 OpenStack(37)

    上一节我们讨论了 snapshot,snapshot 的一个重要作用是对 instance 做备份. 如果 instance 损坏了,可以通过 snapshot 恢复,这个恢复的操作就是 Rebuil ...

  9. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

随机推荐

  1. [Mathematics][MIT 18.03] Detailed Explanation of the Frequency Problems in Second-Order Differential Equation of Oscillation System

    Well, to begin with, I'd like to say thank you to MIT open courses twice. It's their generosity that ...

  2. Dijkstra--The Captain

    *传送 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. 先给一段证明:给定三个x值,x1<x2<x ...

  3. php语言注意点

    PHP大小写问题 http://www.jb51.net/article/38579.htm 推荐大家始终坚持“大小写敏感”,遵循统一的代码规范.1. 变量名区分大小写 2. 函数名.方法名.类名不区 ...

  4. POJ1200 A - Crazy Search(哈希)

    A - Crazy Search Many people like to solve hard puzzles some of which may lead them to madness. One ...

  5. SpringMVC_执行原理

    什么是SpringMVC 概述 Spring MVC是Spring Framework的一部分,是基于Java实现MVC的轻量级Web框架. 查看官方文档:https://docs.spring.io ...

  6. Java查漏补缺(3)(面向对象相关)

    Java查漏补缺(3) 继承·抽象类·接口·静态·权限 相关 this与super关键字 this的作用: 调用成员变量(可以用来区分局部变量和成员变量) 调用本类其他成员方法 调用构造方法(需要在方 ...

  7. Integer和int的区别

    1.Integer是int的包装类,int则是java的一种基本数据类型 2.Integer变量必须实例化后才能使用,而int变量不需要 3.Integer实际是对象的引用,当new一个Integer ...

  8. POJ 1469:COURSES

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19458   Accepted: 7658 Descript ...

  9. 一个简单的“将ball个球放到box各盒子中,每个盒子不多于m个,并且满足limit条件的状态”的函数

    前段时间,做了一个某游戏的辅助计算工具,其中遇到一个排列组合问题.抽象出来就是 将ball个球放到box各盒子中,每个盒子不多于m个,并且满足limit条件, 请给出所有的这些状态. 随意找了下没有现 ...

  10. 学会拒绝,是一种智慧——OO电梯章节优化框架的思考

    在本章的三次作业里,每次作业我都有一个主题,分别是:托盘型共享数据.单步电梯运行优化.多部电梯运行优化,因而电梯优化实际是第二.三次作业.虽然后两次作业从性能分上看做得还不错,但阅读其他大佬博客,我深 ...