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 ...
随机推荐
- 7.prometheus之查询API
一.格式概述 二.表达式查询 2.1 Instant queries(即时查询) 2.2 范围查询 三.查询元数据 3.1 通过标签匹配器找到度量指标列表 3.2 获取标签名 3.3 查询标签值 四. ...
- Linux学习笔记 | 配置ssh
目录: SSH的必要性 将默认镜像源修改为清华镜像源 Linux安装ssh软件 使用putty软件实现ssh连接 Windows下安装winscp SSH的必要性 一般服务器都位于远程而非本地,或者及 ...
- requests顺序执行实现
多步请求封装,执行完一个用例 def requests(self,step_info): request_type =step_info['请求方式'] if request_type==" ...
- (二)数据源处理5-excel数据转换实战(上)
把excel_oper02.py 里面实现的:通过字典的方式获取所有excel数据.放进utils: ️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️ utils: def get_al ...
- Pycharm同时执行多个脚本文件
Pycharm同时执行多个脚本文件 设置Pycharm使它可以同时执行多个程序 打开Pycharm 找到Run,点击确认 点击Edit Configurations 右上角Allow parallel ...
- 在项目中应该使用Boolean还是使用boolean?
起因 在公司看代码时,看到了使用Boolean对象来完成业务逻辑判断的操作.和我的习惯不一致,于是引起了一些反思. boolean和Boolean的差别咱就不说了,我们仅探讨使用boolean与Boo ...
- 【Oracle】查询执行慢的sql
查询执行最慢的sql select * from (select sa.SQL_TEXT, sa.SQL_FULLTEXT, sa.EXECUTIONS "执行次数", round ...
- 通过logmnr找到被修改前的存储过程
1.找到存储过程被修改时的归档日志 SELECT NAME FROM V$ARCHIVED_LOG WHERE FIRST_TIME BETWEEN TO_DATE('20191118080000', ...
- [MRCTF2020]你传你🐎呢之.htaccess
前言 最近,也是遇到了文件上传的文件,自己搭的靶场都不能用,今天,在这里又遇到了这个题.简单总结下,内容来自互联网,若有侵权,联系我. .htaccess简介 .htaccess文件(分布式配置文件) ...
- linux系统图形化管理工具
webmin是一个非常好的图形化管理工具,提供了系统管理员对于linux系统的运维效率.对于那些记不住命令,新入门的新手真的是一个很好的工具呀,上图吧. 这是系统管理的首页,可以看到,CPU,内存.虚 ...