zoj 3534 Move the Mouse I

zoj 3534 Move the Mouse I,第1张

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);}}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4906212.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存