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

zoj 3226 Mobile Positioning

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

zoj 3226 Mobile Positioning

#include<cstdio>  #include<math.h>  #include<iostream>  #include<algorithm>  #include<cstring>  using namespace std;  #define rep(i,n) for(int (i)=0;(i)<(n);(i)++)  #define sf scanf  #define pf printf  #define dbg(x) cerr << __LINE__ << " : " << #x << " : " << (x) << endl  typedef double D;  D const eps = 1.0e-6;  D const pi = acos(-1.0);  int inline dcmp(D x) {      if(x>=-eps && x<=eps) return 0;      return x > 0 ? 1 : -1;  }  D inline sqr(D x) { return x*x; }  struct P {      D x,y;      P() {};      P(D x,D y):x(x),y(y){};      P operator + (P u) {return P(x+u.x,y+u.y);}       P operator - (P u) {return P(x-u.x,y-u.y);}      P operator * (D k) {return P(x*k, y*k);}      P operator / (D k) {return P(x/k,y/k);}      D operator * (P u) {return x*u.y-y*u.x;}      D operator ^ (P u) {return x*u.x+y*u.y;}      bool operator < (const P& u) const{if(dcmp(x-u.x) == 0) return dcmp(y-u.y) < 0;          return dcmp(x-u.x) < 0;      }      bool operator == (const P& u) {          return dcmp(x-u.x)==0 && dcmp(y-u.y)==0;      }      void read() { sf("%lf%lf",&x,&y); }      void out() {if(x<0 && -x < 0.005) x=0;          if(y<0 && -y < 0.005) y=0;          pf("%.2lf %.2lfn",x,y);      }      D len() { return sqrt(x*x+y*y); }      P unit() { P ret(x,y);if(dcmp(ret.len())) ret=ret/ret.len();return ret;}      P rotate(D s) {return P(x*cos(s) - y*sin(s),        x*sin(s) + y*cos(s));      }   };  struct C {      P u;      D r;      C() {};      C(P u,D r):u(u),r(r){};  };  int intersection(C a,C b,P& p1,P& p2) {      if(dcmp(a.r)==0) {          p1 = a.u;          return 1;      }      if(dcmp(b.r)==0) {          p1 = b.u;          return 1;      }      D d = (a.u-b.u).len();      if(dcmp(d)==0 && dcmp(a.r-b.r)==0) return -1;      if(dcmp(d-(a.r+b.r))>0) return 0;      if(dcmp(d-fabs(a.r-b.r))<0) return 0;      P dir = b.u-a.u;      D s = acos((sqr(dir.len())+sqr(a.r)-sqr(b.r))/2.0/a.r/dir.len());      dir = dir.unit();      p1 = dir.rotate(s)*a.r + a.u;      p2 = dir.rotate(-s)*a.r + a.u;      if(p1 == p2) return 1;      return 2;  }   D t1,t2,t3,t4,v;  P B[2];  P P1,P2;  P ans[10];  int vis[10];  void work(){      int num = 0;      C c1(P1,t2*v),c2(P2,t3*v);      if(dcmp(t1+t2)==0) {          pf("1n");          P1.out();          return ;      }      if(dcmp(t3+t4)==0) {          pf("-1n");          return ;      }      D t = (t3+t4)/(t1+t2);      int k = intersection(c1,c2,B[0],B[1]);      if(k==-1) {          pf("-1n");          return ;      }      for(int i=0;i<k;i++) {          c1 = C(P1,t1*v);          c2 = C(B[i]*((1+t)/t)-P2/t,t4*v/t);          int k1=intersection(c1,c2,ans[num],ans[num+1]);          if(k1==-1) {   pf("-1n");   return ;          }          num += k1;      }      memset(vis,0,sizeof(vis));      int cnt = 0;      P tmp[10];      for(int i=0;i<num;i++) if(!vis[i]){          for(int j=i+1;j<num;j++) if(ans[i]==ans[j]){   vis[j]=1;          }          tmp[cnt++]=ans[i];      }      sort(tmp,tmp+cnt);      pf("%dn",cnt);      for(int i=0;i<cnt;i++) tmp[i].out();  }  int main(){       while(~sf("%lf%lf",&P1.x,&P1.y)){          P2.read();          sf("%lf%lf%lf%lf%lf",&t1,&t2,&t3,&t4,&v);          work();      }      return 0;  }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/378534.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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