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 ...
随机推荐
- LeetCode278 第一个错误的版本
你是产品经理,目前正在带领一个团队开发新的产品.不幸的是,你的产品的最新版本没有通过质量检测.由于每个版本都是基于之前的版本开发的,所以错误的版本之后的所有版本都是错的. 假设你有 n 个版本 [1, ...
- .NET Core学习笔记(9)——Entity Framework Core之Code First
上篇我们介绍了怎么通过已有的SQLServer表来创建实体类,本篇我们改用Code First的方式,由C#代码书写的实体类来生成SQLServer表.并且通过简单的Console APP往SQLSe ...
- kubernets之Ingress资源
一 Ingress集中式的kubernets服务转发控制器 1.1 认识Ingress的工作原理 注意:图片来源于kubernets in action一书,如若觉得侵权,请第一时间联系博主进行删 ...
- 登陆到 SAP 系统后的用户出口
增强类型:smod 增强名称:SUSR0001 组件(退出功能模块):EXIT_SAPLSUSF_001 功能:用户每次登陆SAP系统后都会调用这个SUSR0001增强,可以在FUNCTION EXI ...
- PAT练习num3-跟奥巴马一起学编程
美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014 年底,为庆祝"计算机科学教育周"正式启动,奥巴马编写了很简单的计算机 ...
- Java 栈的使用
讲栈之前,要先讲一下Deque双端队列 既可以添加到队尾,也可以添加到队首 既可以从队首获取又可以从队尾获取 public interface Deque<E> extends Queue ...
- 微服务网关1-Spring Cloud Gateway简介
一.网关基本概念 1.API网关介绍 API 网关出现的原因是微服务架构的出现,不同的微服务一般会有不同的网络地址,而外部客户端可能需要调用多个服务的接口才能完成一个业务需求,如果让客户端直接与各 ...
- ModelForm的基本用法:
一.ModelForm的基本用法示例: from django import forms from app01 import models class BookModelForm(forms.Mode ...
- JavaScript中创建数组的方式!
JavaScript中创建数组的方式! 利用数组字面量 // 1 直接量 console.log(Array.prototype); var arr = [1, 2, 4, 87432]; // 注意 ...
- SQL Server 邮箱告警配置
目录 配置数据库邮件 * 手动启用数据库邮件功能 * 配置数据库邮件 * 测试数据库邮件 实现 JOB 任务运行状态的检测 * 定义操作员 * 新建死锁警报 * 设置 SQL Server 代理 创建 ...