Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
几个注意点+(2017-06-28为止代码长度榜第一的短代码)代码几个注意点: 1. 输入的线段(x1,x2,y)保证x1<x2 2. 输入的home一定在观光区上面 3. 输入的障碍物不一定在home和观光区之间 4. 如果输入的障碍物与home同y轴,不管重合与部分重合还是不重合,不算遮住。 5. 如果输入的障碍物与观光区重合,同理。 短短短代码:(2017-06-28为止代码长度榜第一的短代码) #include <cstdio> #include <algorithm> #include <cmath> #define max(a,b) ((a)>(b)?(a):(b)) using namespace std; const double Eps=1e-8; struct Line{ double x1,x2,y; }h,l,a[35],z; int n,n_; bool cmp(Line a,Line b){ return a.x1<b.x1; } int main(){ while (scanf("%lf%lf%lf",&h.x1,&h.x2,&h.y)&&(h.x1||h.x2||h.y)){ scanf("%lf%lf%lf%d",&l.x1,&l.x2,&l.y,&n),n_=0; for (int i=1;i<=n;i++){ scanf("%lf%lf%lf",&z.x1,&z.x2,&z.y),n_++; if (!(l.y-Eps<z.y&&z.y-Eps<h.y)||fabs(z.y-h.y)<Eps||fabs(z.y-l.y)<Eps) a[n_].x1=a[n_].x2=0; else a[n_].x1=z.x1-(h.x2-z.x1)*(z.y-l.y)/(h.y-z.y),a[n_].x2=z.x2-(h.x1-z.x2)*(z.y-l.y)/(h.y-z.y); if (a[n_].x1+Eps>a[n_].x2) n_--; } sort(a+1,a+n_+1,cmp); double ans=0,far=l.x1; for (int i=1;i<=n_;i++) ans=max(ans,a[i].x1-far),far=max(far,a[i].x2); ans=max(ans,l.x2-far); if (fabs(ans)<Eps) puts("No View"); else printf("%.2lf\n",ans); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator