18 icpc焦作 D. Keiichi Tsuchiya the Drift King //计算几何

题目

题意

就这样一个小车车要漂移过弯,这个弯的弧度为 d d d,上边和圆心在同一直线上,求最小的 w w w

思路

发现答案只和左下角的那个点有关,发现左下角的那个点的轨迹就是以红线为半径的一个圆。
蓝黑色为界限,此时角度为 d d d,对于 > = d >=d >=d的情况,发现答案就是红线的长度。
对于 &lt; d &lt;d <d的情况,答案就是红色的 a n s ans ans

板子打错一个字符,调半小时
这计算几何不算难吧…

/*   Author : Rshs
 *   Data : 2019-09-13-13.42
 */
#include<bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
#define LL long long
#define MP make_pair
#define PII pair<int,int>
#define SZ(a) (int)a.size()
const double pi = acos(-1);
const double eps = 1e-10;
const LL mod = 1e9+7;
const int MX = 1e6+5;

struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x=_x,y=_y;
    }
    double len(){
        return hypot(x,y);
    }
    double operator ^(const Point &b)const {
        return x*b.y-y*b.x;
    }
    double operator *(const Point &b)const {
        return x*b.x+y*b.y;
    }
    Point operator -(const Point &b)const {
        return Point(x-b.x,y-b.y);
    }
    double rad(Point a,Point b){
        Point p=*this;
        return fabs( atan2(fabs( (a-p)^(b-p) ),(a-p)*(b-p) ) );
    }
    Point rotate(Point p,double angle){
        Point v=(*this)-p;
        double c=cos(angle),s=sin(angle);
        return Point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
    }
};

void Main(int avg){
    double a,b,r,d;
    int aa,bb,rr,dd;
    cin>>aa>>bb>>rr>>dd;
    a=aa,b=bb,r=rr,d=dd;
    Point ce=Point(0,0);
    Point ld=Point(-a-r,-b);
    double li=ce.rad(ld,Point(-1e10,0));
    d=d/180.0*pi;
    if(d>li){
        printf("%.12lf\n",ld.len()-r);
        return ;
    }
    else {
        Point now=ld.rotate(ce,-d);
        printf("%.12lf\n",-now.x-r);
    }
}
int main(){
    int cas;cin>>cas;for(int i=1;i<=cas;i++)Main(i);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值