hdu5531 Rebuild
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 181 Accepted Submission(s): 42
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
endpointi−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 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.
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.
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<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<bitset>
#pragma comment(linker, "/STACK:1024000000,1024000000")
template <class T>
bool scanff(T &ret){ //Faster Input
char c; int sgn; T bit=0.1;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
if(c==' '||c=='\n'){ ret*=sgn; return 1; }
while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
ret*=sgn;
return 1;
}
#define inf 1073741823
#define llinf 4611686018427387903LL
#define PI acos(-1.0)
#define lth (th<<1)
#define rth (th<<1|1)
#define rep(i,a,b) for(int i=int(a);i<=int(b);i++)
#define drep(i,a,b) for(int i=int(a);i>=int(b);i--)
#define gson(i,root) for(int i=ptx[root];~i;i=ed[i].next)
#define tdata int testnum;scanff(testnum);for(int cas=1;cas<=testnum;cas++)
#define mem(x,val) memset(x,val,sizeof(x))
#define mkp(a,b) make_pair(a,b)
#define findx(x) lower_bound(b+1,b+1+bn,x)-b
#define pb(x) push_back(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define NN 100100
struct node{
double x,y;
}a[NN];
int n;
double len[NN];
double r[NN];
double caldis(int x,int y){
return sqrt((a[x].x-a[y].x)*(a[x].x-a[y].x)+(a[x].y-a[y].y)*(a[x].y-a[y].y));
}
double cal(int idx,double lx){
double temp=lx;
double s=0.0;
rep(i,1,n){
s+=lx*lx;
r[idx]=lx;
if(lx<0.0||lx>len[idx]||lx>len[idx==1?n:idx-1])return -1.0;
lx=len[idx]-lx;
idx++;
if(idx>n)idx=1;
}
if(fabs(temp-lx)>1e-7)return -1.0;
return s;
}
int main(){
tdata{
scanff(n);
rep(i,1,n){
scanf("%lf%lf",&a[i].x,&a[i].y);
}
rep(i,1,n){
if(i!=n)len[i]=caldis(i,i+1);
else len[i]=caldis(i,1);
}
int idx;
if(n&1){
double lenx=0.0;
idx=1;
rep(i,1,n){
if(i&1)lenx+=len[idx];
else lenx-=len[idx];
idx++;
if(idx>n)idx=1;
}
lenx/=2.0;
double ans=cal(1,lenx);
if(ans>=0.0){
printf("%.2f\n",ans*PI);
rep(i,1,n){
printf("%.2f\n",r[i]);
}
}
else printf("IMPOSSIBLE\n");
}
else{
double lx=0.0,rx=len[1],t=0.0;
idx=1;
rep(i,1,n){
t=len[idx]-t;
if(i&1)rx=min(rx,t);
else lx=max(lx,-t);
idx++;
if(idx>n)idx=1;
}
if(lx>rx){
printf("IMPOSSIBLE\n");
continue;
}
rep(i,1,250){
/*
double d=(rx-lx)/3.0;
double d1=lx+d;
double d2=rx-d;
*/
double d1=(lx*2+rx)/3.0;
double d2=(lx+rx*2)/3.0;
if(cal(1,d1)<cal(1,d2))rx=d2;
else lx=d1;
}
double ans=cal(1,lx);
if(ans<0.0){
printf("IMPOSSIBLE\n");
continue;
}
printf("%.2f\n",ans*PI);
rep(i,1,n){
printf("%.2f\n",r[i]);
}
}
}
return 0;
}
hdu5531 Rebuild的更多相关文章
- 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 ...
- Xcode7 *** does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)
*** does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE ...
- rebuild new environment for DW step
Steps to rebuild PPE environment: (CTS) 1, Disable both CTS Daily Job (Daily) and CTS Daily Job (Sta ...
- node-gyp rebuild 卡住?
最近 npm install 时候经常遇到在 node-gyp rebuild 那里卡很久的情况(大于十分钟),于是研究了一下输出的错误日志解决了这个问题,在这里分享一下. 首先,请检查 node-g ...
- Andriod Studio Clear Project或Rebuild Project出错
以前在Eclipse中出现过类似的错误:在编译工程时,提示无法删除bin目录下的某个jar. 想不到Android Studio中也会有. Clear Project或Rebuild Project, ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
随机推荐
- 阿里面试官:什么是MySQL索引,为什么要有索引?
一.什么是索引? 索引就好比字典的目录一样 我们通常都会先去目录查找关键偏旁或者字母再去查找 要比直接翻查字典查询要快很多 二.为什么要有索引? 然而我们在使用mysql数据库的时候也像字典一样有索引 ...
- Android事件分发机制一:事件是如何到达activity的?
事件分发,真的一定从Activity开始吗? 前言 很高兴遇见你~ 事件分发,android中一个老生常谈的话题了.基本的流程我们也都知道是从Activity开始分发,但有一个关键问题是:事件是如何到 ...
- ruby+watir安装指南
安装ruby+watir一共需要下面几个步骤 1. 安装ruby: 2. 升级Rubygems:Rubygems(简称 gems)是一个用于对 Ruby组件进行打包的 Ruby 打包系统. 它提供一个 ...
- 【Java】Java注释 - 单行、块、文档注释
简单记录,Java 核心技术卷I 基础知识(原书第10 版) 注释 我们在编写程序时,经常需要添加一些注释,用来描述某段代码的作用,提高Java源程序代码的可读性,使得Java程序条理清晰. 写代码的 ...
- js reduce数组转对象
借鉴:https://juejin.im/post/5cfcaa7ae51d45109b01b161#comment这位大佬的处理方法很妙,但是我一眼看过去没有明白,细细琢磨了下,终于明白了 1 co ...
- java 利用异或^进行加密
package com.zcj.eg001; import java.nio.charset.Charset; import org.junit.Test; public class Encrypti ...
- LoadRunner监控Centos和Ubuntu资源之服务器配置
Centos 我用的版本是Centos6.8 首先更新源以及基础操作我就不说了,直接上步骤: Step 1 安装相关程序 执行命令:yum install inetd,这一步是为了安装rstatd ...
- 通俗易懂的解释:什么是API
API 全称 Application Programming Interface,即应用程序编程接口. 看到这里,急性子的小白同学马上就憋不住了:这不管是英文还是中文我每个字都懂啊,只是凑一块就不知道 ...
- 通过Joomla的两次RCE漏洞看session反序列化
关于Session的前置知识: session 对数据的序列化方式一共有三种: 默认是 php 处理器:session.serialize_handler = php 效果如图: 通过|分割数据,|前 ...
- Language Guide (proto3) | proto3 语言指南(一)定义消息类型
定义消息类型 首先让我们看一个非常简单的例子.假设您想定义一个搜索请求消息格式,其中每个搜索请求都有一个查询字符串.您感兴趣的特定结果页以及每页的结果数.下面是用于定义.proto消息类型的文件. s ...