HDU 1348 && POJ 1113 Wall(凸包)
2016-07-27 14:34
405 查看
题目链接:
HDU :http://acm.hdu.edu.cn/showproblem.php?pid=1348POJ :http://poj.org/problem?id=1113
题解:
求出凸包后,算出凸包的周长,再加上以l为半径的圆的周长就好了,最后输出要一个整数并且四舍五入,HDU上还会卡一手输出,最后一个t不要再输出一行空格。AC代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int maxn = 1050; const double PI = acos(-1.0); struct node { int x, y; }e[maxn], tubao[maxn]; int cmp(const node& a , const node& b) { if(a.x == b.x) return a.y < b.y; return a.x < b.x; } int cross(node a, node b, node c) { return (a.x - b.x) * (c.y - b.y) - (a.y - b.y) * (c.x - b.x); } int convex(int n) { sort(e, e+n, cmp); int m = 0; for(int i = 0; i < n; i++) { while(m > 1 && cross(tubao[m-1], tubao[m-2], e[i]) <= 0) m--; tubao[m++] = e[i]; } int k = m; for(int i = n-2; i >= 0; i--) { while(m > k && cross(tubao[m-1], tubao[m-2], e[i]) <= 0) m--; tubao[m++] = e[i]; } if(n > 1)m--; return m; } double dis(const node &a, const node &b)//一定要double { return sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int main() { int t,m,l; cin >> t; while(t--) { scanf("%d%d", &m, &l); for(int i = 0; i < m; i++) scanf("%d%d", &e[i].x, &e[i].y); int num = convex(m); double ans = 0; for(int i = 1; i < num; i++) { ans += dis(tubao[i], tubao[i-1]); } ans += dis(tubao[num-1], tubao[0]); ans += PI * l * 2; printf("%.0f\n", ans);//这样写才不会WA if(t) cout << endl; } return 0; }
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- ACM程序设计大赛题目分类
- 2015年acm国内排名
- 计算字符串最后一个单词长度
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002