HDU 5033---Building(单调栈)
2018-06-17 22:10:56来源:未知 阅读 ()
题目链接
Each test case begins with a number N(1<=N<=10^5), the number of buildings.
In the following N lines, each line contains two numbers, xi(1<=xi<=10^7) and hi(1<=hi<=10^7).
After that, there's a number Q(1<=Q<=10^5) for the number of queries.
In the following Q lines, each line contains one number qi, which is the position Matt was at.
Then for each query, you should output the angle range Matt could see the sky in degrees. The relative error of the answer should be no more than 10^(-4).
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; const int maxn=1e5+5; const double PI=acos(-1); struct Node{ double x; double y; int L,R,id; }a[2*maxn]; int top,s[maxn]; bool cmp(const Node s1,const Node s2) { return s1.x<s2.x; } bool cmp2(const Node s1,const Node s2) { return s1.id<s2.id; } double cal2(double x,double y) { //cout<<"H:"<<x<<" "<<y<<endl; return atan(y/x); } int main() { ///cout << "Hello world!" << endl; int T,Case=1; cin>>T; while(T--) { printf("Case #%d:\n",Case++); int N; scanf("%d",&N); for(int i=1;i<=N;i++) scanf("%lf%lf",&a[i].x,&a[i].y),a[i].id=i; int Q; scanf("%d",&Q); for(int i=N+1;i<=N+Q;i++) scanf("%lf",&a[i].x),a[i].y=0,a[i].id=i; sort(a+1,a+N+Q+1,cmp); ///for(int i=1;i<=N+Q;i++) cout<<a[i].id<<" "<<a[i].x<<" "<<a[i].y<<endl; top=0; s[0]=1; for(int i=2;i<=N+Q;i++) { while(1) { if(top<1) break; double x1=a[s[top]].x-a[s[top-1]].x; double y1=a[s[top]].y-a[s[top-1]].y; //double f1=cal(a[s[top-1]].x, a[s[top-1]].y, a[s[top]].x, a[s[top]].y); double x2=a[i].x-a[s[top]].x; double y2=a[i].y-a[s[top]].y; //double f2=cal(a[s[top]].x, a[s[top]].y, a[i].x, a[i].y); if(y1*x2>y2*x1) break; top--; } if(a[i].id>N) a[i].L=a[s[top]].id;//,cout<<"top1 "<<top<<" "<<s[top]<<" "<<a[s[top]].id<<endl; s[++top]=i; } top=0; s[0]=N+Q; for(int i=N+Q-1;i>=1;i--) { while(1) { if(top<1) break; double x1=a[s[top-1]].x-a[s[top]].x; double y1=a[s[top-1]].y-a[s[top]].y; //double f1=cal(a[s[top-1]].x, a[s[top-1]].y, a[s[top]].x, a[s[top]].y); double x2=a[s[top]].x-a[i].x; double y2=a[s[top]].y-a[i].y; //double f2=cal(a[s[top]].x, a[s[top]].y, a[i].x, a[i].y); if(y1*x2<y2*x1) break; top--; } if(a[i].id>N) a[i].R=a[s[top]].id;//,cout<<"top2 "<<top<<" "<<s[top]<<" "<<a[s[top]].id<<endl; s[++top]=i; } sort(a+1,a+N+Q+1,cmp2); for(int i=N+1;i<=N+Q;i++) { //cout<<"--->"<<a[i].L<<" "<<a[i].R<<endl; double ans=PI; int k=a[i].L; ans-=cal2(a[i].x-a[k].x,a[k].y); k=a[i].R; ans-=cal2(a[k].x-a[i].x,a[k].y); printf("%.10f\n",ans*180/PI); } } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 单调队列模板【附例题】 2020-05-05
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- 单调队列 2020-02-07
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash