简单几何(极角排序) POJ 2007 Scrambled Polygon
题意:裸的对原点的极角排序,凸包貌似不行。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | /************************************************ * Author :Running_Time * Created Time :2015/11/3 星期二 14:46:47 * File Name :POJ_2007.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int N = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = acos (-1.0); int dcmp( double x) { if ( fabs (x) < EPS) return 0; else return x < 0 ? -1 : 1; } struct Point { double x, y; Point () {} Point ( double x, double y) : x (x), y (y) {} Point operator - ( const Point &r) const { //向量减法 return Point (x - r.x, y - r.y); } bool operator == ( const Point &r) const { //判断同一个点 return dcmp (x - r.x) == 0 && dcmp (y - r.y) == 0; } bool operator < ( const Point &r) const { return x < r.x || (dcmp (x - r.x) == 0 && y < r.y); } }; typedef Point Vector; Point read_point( void ) { double x, y; scanf ( "%lf%lf" , &x, &y); return Point (x, y); } double polar_angle(Vector A) { return atan2 (A.y, A.x); } double dot(Vector A, Vector B) { return A.x * B.x + A.y * B.y; } double cross(Vector A, Vector B) { return A.x * B.y - A.y * B.x; } bool cmp(Point a, Point b) { return cross (a - Point (0, 0), b - Point (0, 0)) > 0; } int main( void ) { vector<Point> ps; double x, y; while ( scanf ( "%lf%lf" , &x, &y) == 2) { ps.push_back (Point (x, y)); } sort (ps.begin ()+1, ps.end (), cmp); for ( int i=0; i<ps.size (); ++i) { printf ( "(%.0f,%.0f)\n" , ps[i].x, ps[i].y); } //cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; } |
编译人生,运行世界!
分类:
/* 圣人不死 AC不止!*/
, 数学
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)