2018年全国多校算法寒假训练营练习比赛(第三场)H 向左走【极角排序】
2018-02-07 23:54
489 查看
题目链接:H 向左走
分析:
起点题目已给,每次左拐的角度最小就是最右,我用斜率判拐角wa了数次(肯定错呀),,,极角排序模板题.
不过你预处理出两个点,建立一个新的x轴,去暴力下一个点,再把之前的两个点更新,依次迭代应该也是可行的…
分析:
起点题目已给,每次左拐的角度最小就是最右,我用斜率判拐角wa了数次(肯定错呀),,,极角排序模板题.
不过你预处理出两个点,建立一个新的x轴,去暴力下一个点,再把之前的两个点更新,依次迭代应该也是可行的…
#include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long LL; const int MAXN = 1e3 + 10; int n, num; struct Point { int id; double x, y; }s[MAXN]; int cross(int x1, int y1, int x2, int y2) { //叉积判断方向 return (x1 * y2 - x2 * y1); } int dis(Point a, Point b) { return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int compare(Point a, Point b, Point c) { return cross((b.x - a.x), (b.y - a.y), (c.x - a.x), (c.y - a.y)); } bool cmp(Point a, Point b) { if(compare(s[num], a, b) == 0) { return dis(s[num], a) < dis(s[num], b); } return compare(s[num], a, b) > 0; } int main() { while(scanf("%d", &n) != EOF) { for(int i = 1; i <= n; i++) { scanf("%d %lf %lf", &s[i].id, &s[i].x, &s[i].y); if(i != 1 && s[i].y <= s[1].y) { if(s[i].y == s[1].y && s[i].x < s[1].x) swap(s[i], s[1]); if(s[i].y < s[1].y) { swap(s[i], s[1]); } } } num = 1; for(int i = 2; i <= n; i++) { sort(s + i, s + n + 1, cmp); num++; } for(int i = 1; i < n; i++) { printf("%d ", s[i].id); } printf("%d\n", s .id); } return 0; }
相关文章推荐
- 2018年全国多校算法寒假训练营练习比赛(第三场)-H-向左走(极角排序)
- 【2018年全国多校算法寒假训练营练习比赛(第三场)】
- 2018年全国多校算法寒假训练营练习比赛(第三场)E
- 2018年全国多校算法寒假训练营练习比赛(第三场)-(A,E)
- 2018年全国多校算法寒假训练营练习比赛(第三场)大水题
- 牛客网NowCoder 2018年全国多校算法寒假训练营练习比赛(第三场)A.不凡的夫夫(斯特林公式) D.小牛vs小客 E.进击吧!阶乘(大数Java) G.大水题(数学)
- 2018年全国多校算法寒假训练营练习比赛(第三场)A-斯特林公式
- 2018年全国多校算法寒假训练营练习比赛(第三场) B 一个小问题【CRT 扩展中国剩余定理 板子题】
- 2018年全国多校算法寒假训练营练习比赛(第三场)F
- 2018年全国多校算法寒假训练营练习比赛(第三场)---E---题(大数阶乘(模板题)c++/java/py)
- 2018年全国多校算法寒假训练营练习比赛(第三场)- I - 三角形(皮克定理)
- nowcoder 2018年全国多校算法寒假训练营练习比赛(第三场)- 小牛vs小客
- 斯特林公式-Stirling公式(取N阶乘近似值)-HDU1018-Big Number 牛客网NowCoder 2018年全国多校算法寒假训练营练习比赛(第三场)A.不凡的夫夫
- 2018年全国多校算法寒假训练营练习比赛(第三场)G
- 2018年全国多校算法寒假训练营练习比赛(第三场)---F---题(博弈)
- 2018年全国多校算法寒假训练营练习比赛(第三场)- A - 不凡的夫夫(斯特林公式)
- 2018年全国多校算法寒假训练营练习比赛题解(第三场)E进击吧!阶乘(大数运算)
- 2018年全国多校算法寒假训练营练习比赛(第三场)小牛vs小客
- 2018年全国多校算法寒假训练营练习比赛(第三场)A 不凡的夫夫【斯特林公式】
- A-不凡的夫夫——2018年全国多校算法寒假训练营练习比赛(第三场)