UVALive
来源:互联网 发布:宇宙追缉令 知乎 编辑:程序博客网 时间:2024/06/04 18:37
题目链接
分析:
题目要求通过1和
需要注意的是叉积会爆int
代码:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cstdlib>#include <vector>#include <queue>#include <deque>#include <stack>#include <set>#include <cmath>using namespace std;struct Point { int x, y; Point (int x = 0, int y = 0) : x(x), y(y) {} bool operator <(const Point &rhs) const { if (rhs.x == x) return y < rhs.y; return x < rhs.x; }};typedef Point Vector;Vector operator +(Vector A, Vector B) { return Vector(A.x + B.x, A.y + B.y);}Vector operator -(Point A, Point B) { return Vector(A.x - B.x, A.y - B.y);}long long Cross(Vector A, Vector B) { return 1ll * A.x * B.y - 1ll * A.y * B.x;}int ConvexHull(Point *p, int n, Point *ch) { sort(p, p + n); int m = 0; for (int i = 0; i < n; i ++) { while (m > 1 && Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2]) <= 0) m --; ch[m ++] = p[i]; } int k = m; for (int i = n - 2; i >= 0; i --) { while (m > k && Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2]) <= 0) m --; ch[m ++] = p[i]; } if (n > 1) m --; return m;}const int maxn = 1e4 + 5;Point node[maxn], hull[maxn];long long resa, resb;void work(const Point &a, const Point &b) { int minv = min(abs(a.x - b.x), abs(a.y - b.y)); int maxv = max(abs(a.x - b.x), abs(a.y - b.y)); resb += 1ll * minv; resa += 1ll * (maxv - minv);}int main() { int N; while (~scanf("%d", &N) && N) { resa = 0, resb = 0; for (int i = 0; i < N; i++) scanf("%d%d", &node[i].x, &node[i].y); int len = ConvexHull(node, N, hull); for (int i = 1; i < len; i ++) {// cout<<hull[i - 1].x<<" "<<hull[i - 1].y<<" "<<hull[i].x<<" "<<hull[i].y<<endl; work(hull[i - 1], hull[i]); } work(hull[0], hull[len - 1]); printf("%lld %lld\n", resa, resb); } return 0;}
0 0
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 解疑 Numpy 中的 transpose
- 缓存Ehcache、Memcached、Redis的统一接口实现
- 【机器人学:运动规划】快速搜索随机树(RRT---Rapidly-exploring Random Trees)入门及在Matlab中演示
- 查看网络状态命令
- js调用API学习
- UVALive
- MySQL、SQLServer、Oracle添加、修改、删除字段总结
- 五大主流浏览器内核的源起以及国内各大浏览器内核总结
- Java oop04接口
- windows下查找端口占用问题
- Java enum的用法详解
- D
- 机器学习总结(十):常用聚类算法(Kmeans、密度聚类、层次聚类)及常见问题
- 解决Select下拉列表的高度