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

zoj 3534 Move the Mouse I

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

zoj 3534 Move the Mouse I

#include<iostream>#include<cmath>#include<cstring>#include<cstdio>#define eps 1e-8using namespace std;double w,h,a,b;struct g{double x,y;int t;}s,e;bool check(g d){double lx,ly,rx,ry,nowa,nowb;if(d.t==1){nowa=a;nowb=b;}else{nowa=b;nowb=a;}lx=d.x-0.5*nowa;ly=d.y-0.5*nowb;rx=d.x+0.5*nowa;ry=d.y+0.5*nowb;if(lx>-eps&&rx<w+eps&&ly>-eps&&ry<h+eps)return true;else return false;}int main(){int flag;double ans,c;while(scanf("%lf%lf%lf%lf",&w,&h,&a,&b)!=EOF){flag=1;scanf("%lf%lf%d%lf%lf%d",&s.x,&s.y,&s.t,&e.x,&e.y,&e.t);if(!check(s)||!check(e))flag=0;if(!flag){printf("-1n");continue;}if(s.t==e.t){ans=fabs(s.x-e.x)+fabs(s.y-e.y);printf("%.3lfn",ans);continue;}c=sqrt(a*a+b*b);if(c>w+eps||c>h+eps)flag=0;if(!flag){printf("-1n");continue;}ans=0;if(s.x<c*0.5){ans+=(0.5*c-s.x);s.x=0.5*c;}if(w-s.x<0.5*c){ans+=(s.x-w+0.5*c);s.x=w-0.5*c;}if(s.y<c*0.5){ans+=(0.5*c-s.y);s.y=0.5*c;}if(h-s.y<0.5*c){ans+=(s.y-h+0.5*c);s.y=h-0.5*c;}ans+=(fabs(s.x-e.x)+fabs(s.y-e.y));printf("%.3lfn",ans+eps);}}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371065.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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