bzoj 1007 : [HNOI2008]水平可见直线 计算几何
生活随笔
收集整理的這篇文章主要介紹了
bzoj 1007 : [HNOI2008]水平可见直线 计算几何
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目鏈接
給出n條直線, 問(wèn)從y軸上方向下看, 能看到哪些直線, 輸出這些直線的編號(hào)。
?
首先我們按斜率排序, 然后依次加入一個(gè)棧里面, 如果剛加入的直線, 和之前的那條直線斜率相等, 那么顯然之前的會(huì)被覆蓋。
假設(shè)棧頂直線為st[top], 新加入的直線為tmp, 那么如果tmp和st[top-1]這條直線的交點(diǎn)在st[top]和st[top-1]交點(diǎn)的左邊, 那么顯然st[top]這條直線會(huì)被覆蓋。
?
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e9+7; const int inf = 1061109567; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; struct node {double x, y;int id;bool operator < (node a) const{if(fabs(x-a.x)<eps)return y<a.y;return x<a.x;} }a[50005], st[50005]; int top, ans[50005]; double cross(node a, node b) {return (b.y-a.y)/(a.x-b.x); } void add(node tmp) {while(top) {if(fabs(tmp.x-st[top].x)<eps)top--;else if(top>1 && cross(tmp, st[top-1])<=cross(st[top], st[top-1]))top--;elsebreak;}st[++top] = tmp; } int main() {int n;cin>>n;for(int i = 0; i<n; i++) {scanf("%lf%lf", &a[i].x, &a[i].y);a[i].id = i;}sort(a, a+n);for(int i = 0; i<n; i++) {add(a[i]);}for(int i = 1; i<=top; i++) {ans[st[i].id] = 1;}for(int i = 0; i<n; i++)if(ans[i])printf("%d ", i+1);cout<<endl;return 0; }?
轉(zhuǎn)載于:https://www.cnblogs.com/yohaha/p/5221079.html
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的bzoj 1007 : [HNOI2008]水平可见直线 计算几何的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Duilib vlc c++ 字符编码
- 下一篇: PHP文件操作常用函数总结