HDU5531-Rebuild(平面几何+数学)
来源:互联网 发布:win10网络红叉 编辑:程序博客网 时间:2024/05/01 04:54
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5531
思路
感觉就一数学题,把公式推出来,然后求出最小面积即可,主要是IMPOSSIBLE的判断感觉有点麻烦,IMPOSSIBLE的判断大概有这几点需要注意一下:
1. 区分n是奇数还是偶数
2. 对于每个点的半径r都必须>=0
代码
#include <iostream>#include <cstring>#include <stack>#include <vector>#include <set>#include <map>#include <cmath>#include <queue>#include <sstream>#include <iomanip>#include <fstream>#include <cstdio>#include <cstdlib>#include <climits>#include <deque>#include <bitset>#include <algorithm>using namespace std;#define PI acos(-1.0)#define LL long long#define PII pair<int, int>#define PLL pair<LL, LL>#define mp make_pair#define IN freopen("in.txt", "r", stdin)#define OUT freopen("out.txt", "wb", stdout)#define scan(x) scanf("%d", &x)#define scan2(x, y) scanf("%d%d", &x, &y)#define scan3(x, y, z) scanf("%d%d%d", &x, &y, &z)#define sqr(x) (x) * (x)#define pr(x) cout << #x << " = " << x << endl#define lc o << 1#define rc o << 1 | 1#define pl() cout << endlconst int maxn = 10000 + 5;const double eps = 1e-6;double x[maxn], y[maxn], l[maxn], a[maxn];int n;double dist(double x1, double y1, double x2, double y2) { return sqrt(sqr(x1 - x2) + sqr(y1 - y2));}int main() { int T; scan(T); while (T--) { scan(n); a[0] = l[0] = x[0] = y[0] = 0.0; double suma = 0.0; double suma2 = 0.0; double flag = 1.0; double _min = 0.0, _max = 10005.0; bool tot_flag = false; for (int i = 1; i <= n; i++) scanf("%lf %lf", &x[i], &y[i]); for (int i = 1; i <= n; i++) { if (i != n) l[i] = dist(x[i], y[i], x[i + 1], y[i + 1]); else l[i] = dist(x[1], y[1], x[n], y[n]); a[i] = -a[i - 1] + l[i - 1]; if (a[i] < 0 && flag > 0) _min = max(_min, -a[i]); if (flag < 0 && a[i] > 0) _max = min(_max, a[i]); if (flag < 0 && a[i] < 0) tot_flag = true; suma += (flag * a[i]); suma2 += sqr(a[i]); flag = -flag; } double minr; if (_min > _max || tot_flag) { puts("IMPOSSIBLE"); continue; } if (!(n & 1)) { if (a[n] != l[n]) { puts("IMPOSSIBLE"); continue; } minr = -suma / double(n); if (minr < _min) minr = _min; else if (minr > _max) minr = _max; } else { minr = (l[n] - a[n]) / 2.0; if (minr < _min || minr > _max) { puts("IMPOSSIBLE"); continue; } } if (minr < 0) { puts("IMPOSSIBLE"); continue; } double ans = n * sqr(minr) + 2 * suma * minr + suma2; flag = 1.0; printf("%.2lf\n", PI * ans); for (int i = 1; i <= n; i++) { printf("%.2lf\n", a[i] + flag * minr); flag = -flag; } } return 0;}
0 0
- HDU5531-Rebuild(平面几何+数学)
- HDU5531 Rebuild 【几何+数学】
- hdu5531 Rebuild
- hdu5531 Rebuild
- HDU5531(三分)
- 组合数学(UESTC 488,Rebuild the Sequence)
- 物理方法解决数学问题(一):从一个简单的平面几何题谈起
- 学数学秋季赛平面几何的解答
- 平面几何
- uva 10387 Billiard(平面几何)
- 一道数学平面几何题:1572. Yekaterinozavodsk Great Well
- Elasticsearch索引重建(Rebuild)
- hdu 5531 Rebuild(三分)
- hdu 5531 Rebuild(三分)
- Elasticsearch索引重建(Rebuild)
- elasticsearch 索引重建(Rebuild)
- Delphi图像处理 -- 平面几何变换(上)
- Delphi图像处理 -- 平面几何变换(下)
- 微服务基础设施之服务注册中心: Spring Cloud Eureka
- OFBiz调用SAP
- java面试总结
- 理解DICOM在放射科的使用
- Flex 布局教程:语法篇
- HDU5531-Rebuild(平面几何+数学)
- 一个在开发道路上迷茫的姑娘
- OFBiz前端界面认知分级
- poj 3259 Wormholes SPFA判断 负权值环
- Java Servlet完全教程
- Hibernate与JPA的DAO注解的全解和例子
- C语言toupper()函数:将小写字母转换为大写字母
- CSDN-markdown 文字样式设置(字体, 大小, 颜色, 高亮底色)
- 在html中引入CSS的方法