2015ACM-ICPC长春E题(hdu5531)题解
一、题意
No response.T_T
二、思路
分$n$为奇数或者偶数讨论。
如果$n$是奇数,列出不等式组:$r_1+r_2=d_{1},r_2+r_3=d_{2},r_3+r_4=d_{3},\cdots,r_{n-1}+r_n=d_{n-1},r_n+r_1=d_n$,可以解出,$r_1=\frac{d_{1}+d_{3}+d_{5}+\cdots-d_{2}-d_{4}-\cdots}{2}$,然后再用上述式子依次算出$r_2$至$r_n$。最后判断$r_1$至$r_n$中是否存在负数即可。
如果$n$是偶数。如果奇数起点的边之和$s_1=d_1+d_3+d_5+\cdots+d_{n-1}$不等于$s_2=d_2+d_4+d_6+\cdots+d_n$,说明无解,否则,一定可以三分枚举出$r_1$,然后推出其他半径。要注意的是,三分的下界和上界需要处理出来。否则,面积关于$r_1$的二次函数在$[low,high]$区间内不一定只有一个极小值。最后判断是否所有半径都大于$0$。
三、代码
#include<bits/stdc++.h> using namespace std; ); struct point { double x, y; } p[]; ], ansr[]; int n; inline bool eq(double x, double y) { ); } inline double dis(point a, point b) { return hypot(a.x - b.x, a.y - b.y); } double calc(double r1) { ansr[] = r1; double sum = PI * r1 * r1, nr; ; i <= n; ++i) { ansr[i] = d[i - ] - ansr[i - ]; sum += PI * ansr[i] * ansr[i]; } return sum; } int main() { // freopen("e.in", "r", stdin); int T; for(scanf("%d", &T); T--;) { ; scanf("%d", &n); ; i <= n; ++i)scanf("%lf %lf", &p[i].x, &p[i].y); ; i <= n; ++i)d[i] = dis(p[i], i < n ? p[i + ] : p[]); ) { ; ; i <= n; i++) { )fz += d[i]; else fz -= d[i]; } ansr[] = fz / ; ; i <= n; ++i)ansr[i] = d[i - ] - ansr[i - ]; ] + ansr[n], d[n]))imp = ; } else { , t2 = ; ; i <= n; ++i) { )t1 += d[i]; else t2 += d[i]; } ; else { , high = min(d[], d[n]), lmid, rmid, s1, s2, sum = ; ; i <= n; ++i) { )sum += d[i], high = min(high, sum); else sum -= d[i], low = max(low, sum); } ; while(ttt--) { lmid = (low + high) / ; rmid = (lmid + high) / ; s1 = calc(lmid), s2 = calc(rmid); if(s1 < s2)high = rmid; else low = lmid; } double r1; if(calc(low) < calc(high))r1 = low; else r1 = high; calc(r1); } } ; i <= n; ++i) { )imp = ; } if(imp) puts("IMPOSSIBLE"); else { ; ; i <= n; ++i)ans += ansr[i] * ansr[i]; ans *= PI; printf("%.2f\n", ans); ; i <= n; ++i)printf("%.2f\n", ansr[i]); } } ; }
2015ACM-ICPC长春E题(hdu5531)题解的更多相关文章
- 2015ACM/ICPC亚洲区沈阳站 部分题解
链接在这:http://bak.vjudge.net/contest/132442#overview. A题,给出a,b和n,初始的集合中有a和b,每次都可以从集合中选择不同的两个,相加或者相减,得到 ...
- 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building
House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b
Count a * b Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tot ...
- (HDU 5558) 2015ACM/ICPC亚洲区合肥站---Alice's Classified Message(后缀数组)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5558 Problem Description Alice wants to send a classi ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
随机推荐
- 【其他】msb-lsb-intel-motorola大小端问题
MSB(Most Significant Bit) 最高有效位: LSB(Least Significant Bit) 最低有效位 intel格式:低字节在前 Motorola格式:高字节在前 参考1 ...
- HttpWebRequest.Connection的问题
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/");request.Co ...
- 使用slot编写弹窗组件
具体slot用法详见http://www.cnblogs.com/keepfool/p/5637834.html html: <!--测试弹窗--> <dialog-test v-i ...
- C语言面试题3
编程题 1.读文件file1.txt的内容(例如): 123456 输出到file2.txt: 563412 #include <stdio.h> #include <stdlib. ...
- ThinkPHP5 API 文档
ThinkPHP5 API 文档 有了这个还是相当的方便,可以快速查找每个组件的方法和接口. https://yangweijie.github.io/thinkphp-lts/index.html# ...
- PHP 中的对象传递
<?php class A { public $age = 0; public $username = ""; public $obj = null; } $a = new ...
- RAC5——11gR2以后GI进程的变化
参考文档: 11gR2 Clusterware and Grid Home - What You Need to Know (Doc ID 1053147.1)诊断 Grid Infrastructu ...
- yii2 笔记(1)
1.js文件加载顺序问题 在视图中引用js文件的时候,使用到jquery会报错,因为自定义的js文件在jquery之前被引入了. 由于jquery,bootstrap是在AppAsset中全局引入的, ...
- bzoj 4025 二分图——线段树分治+LCT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4025 线段树分治,用 LCT 维护链的长度即可.不过很慢. 正常(更快)的方法应该是线段树分 ...
- UOJ 188 【UR #13】Sanrd——min_25筛
题目:http://uoj.ac/problem/188 令 \( s(n,j)=\sum\limits_{i=1}^{n}[min_i>=p_j]f(j) \) ,其中 \( min_i \) ...