黑龙江快乐十分

BZOJ 1007, 水平可见直线

2/10/2017来源:ASP.NET技巧人气:17196

oblem

chuansongmen

Mean

canjiantimumiaoshu。

Analysis

黑龙江快乐十分jiangzhixiananxielvpaixu,ranhoucongxiaodaodayiciruzhan,ruzhanshijisuangaizhixianyuzhandingyuansujiaodian。 ruogaijiaodianzaizhandingyuansuyuzhandingxiayigeyuansujiaodiandezuoce(huozhonghe),zezhandingyuansubeiwanzhengzhedang,chuzhan。 fanfubijiao,quanbucaozuowanbihouzhanzhongyuansujiweikejianshuipingzhixian。

Code

#include<cstdio> #include<cmath> #include<algorithm> using namespace std; const double EPS=1e-10; const int N=50005; int n,top,s[N]; bool f[N]; struct Line{ int id; double a,b; bool tor < (const Line &B) const { if(fabs(a-B.a)<EPS) return b<B.b; return a<B.a; } }l[N]; double Cross(Line A,Line B){return (B.b-A.b)/(A.a-B.a);} int main(){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%lf%lf",&l[i].a,&l[i].b); l[i].id=i; } sort(l,l+n); for(int i=0;i<n;i++){ while(top){ if(fabs(l[s[top]].a-l[i].a)<EPS) top--; else if(top>1 && Cross(l[s[top]],l[i])<=Cross(l[s[top-1]],l[s[top]])) top--; else break; } s[++top]=i; } for(int i=1;i<=top;i++) f[l[s[i]].id]=1; for(int i=0;i<n;i++) if(f[i]) printf("%d ",i+1); return 0; }

优质网站模板

  • 1
  • 2
  • 3