[ZOJ3728] Collision && 暴力解方程

设出时间t 解方程

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstring>
#include<cmath>
#define SF scanf
#define PF printf
using namespace std;
typedef long long LL;
const double PI = acos(-1.0);
struct Vector {
	int x, y;
	Vector() {}
	Vector(double xx, double yy) { x = xx; y = yy; }
	Vector(double rad) { x = cos(rad); y = sin(rad); }
	double len() const { return sqrt(x*x + y*y); }
	
	Vector operator + (const Vector &b) const {
		return Vector(x + b.x, y + b.y);
	}
	Vector operator - (const Vector &b) const {
		return Vector(x - b.x, y - b.y);
	}
	Vector operator * (const Vector &b) const {
		return Vector(x - b.x, y - b.y);
	}
	Vector operator * (const double &b) const {
		return Vector(x*b, y*b);
	}
	Vector operator / (const double &b) const {
		return Vector(x / b, y / b);
	}
	bool operator == (const Vector &b) const {
		return x == b.x && y == b.y;
	}
};
double Dot(const Vector &a, const Vector &b) {
	return a.x * b.x + a.y * b.y;
}
double Cross(const Vector &a, const Vector &b) {
	return a.x * b.y - a.y * b.x;
}
Vector GetAngle(const Vector &a, const Vector &b) {
	double l1 = a.len(), l2 = b.len();
	return Vector(Dot(a, b) / l1 / l2, Cross(a, b)/ l1 / l2);
}
// 逆时针旋转
Vector Rotate(const Vector &a, const Vector &angle) {
	return Vector(a.x * angle.x - a.y * angle.y, a.x * angle.y + a.y * angle.x);
}
typedef Vector Point, Angle;
int Rm, Rr, Rc;
Point O(0, 0), Coin;
Vector v;
int main()
{
	while(SF("%d%d%d%d%d%d%d", &Rm, &Rr, &Rc, &Coin.x, &Coin.y, &v.x, &v.y) == 7)
	{
		double c = - (Rr + Rc) * (Rr + Rc) + Coin.x * Coin.x + Coin.y * Coin.y;
		double b = 2 * (Coin.x * v.x + Coin.y * v.y);
		double a = v.x * v.x + v.y * v.y;
		double delta = b * b - 4 * a * c;
		if(delta <= 0) {
			puts("0.000");
			continue;
		}
		double ans = 0;
		double tmp1 = (-b + sqrt(delta)) / 2 / a, tmp2 = (-b - sqrt(delta)) / 2 / a;
		if(tmp2 >= 0) {
			c = Coin.x * Coin.x + Coin.y * Coin.y - (Rm + Rc) * (Rm + Rc);
			delta = b * b - 4 * a * c;
			if(delta <= 0) {
				ans = tmp1 - tmp2;
			}
			else {
				double tmp = (-b - sqrt(delta)) / 2 / a;
				ans = (tmp - tmp2) * 2;
			}
			PF("%.3lf\n", ans);
		}
		else {
			puts("0.000");
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值