栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1248 Video Surveillance

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1248 Video Surveillance

#include <queue>#include <stack>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <string>#include <algorithm>using namespace std;const int MAX = 105;struct point{ double x,y;};point p[MAX],s[MAX];const double eps = 1e-6;bool dy(double x,double y){return x > y + eps;}// x > y bool xy(double x,double y){return x < y - eps;}// x < y bool dyd(double x,double y){ return x > y - eps;}// x >= y bool xyd(double x,double y){return x < y + eps;} // x <= y bool dd(double x,double y) {return fabs( x - y ) < eps;}  // x == ydouble crossProduct(point a,point b,point c){return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y);}point l2l_inst_p(point u1,point u2,point v1,point v2){point ans = u1;double t = ((u1.x - v1.x)*(v1.y - v2.y) - (u1.y - v1.y)*(v1.x - v2.x))/((u1.x - u2.x)*(v1.y - v2.y) - (u1.y - u2.y)*(v1.x - v2.x));ans.x += (u2.x - u1.x)*t;ans.y += (u2.y - u1.y)*t;return ans;}void inst_hp(point p[],int n,point s[],int &len){point tp[MAX];p[n] = p[0];for(int i=0; i<=n; i++)tp[i] = p[i];int cp = n,tc;for(int i=0; i<n; i++){tc = 0;for(int k=0; k<cp; k++){if( dyd(crossProduct(p[i],p[i+1],tp[k]),0.0) )s[tc++] = tp[k];if( xy(crossProduct(p[i],p[i+1],tp[k])* crossProduct(p[i],p[i+1],tp[k+1]),0.0) )s[tc++] = l2l_inst_p(p[i],p[i+1],tp[k],tp[k+1]);}s[tc] = s[0];for(int k=0; k<=tc; k++)tp[k] = s[k];cp = tc;}len = cp;}int main(){int len,ncases,n,ind = 1;while( ~scanf("%d",&n) && n ){for(int i=0; i<n; i++)scanf("%lf%lf",&p[i].x,&p[i].y);inst_hp(p,n,s,len);printf("Floor #%dn",ind++);if( len )printf("Surveillance is possible.nn");elseprintf("Surveillance is impossible.nn");}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379559.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号