[ZOJ3728] Collision && 暴力解方程

来源:互联网 发布:淘宝设置自动发货 编辑:程序博客网 时间:2024/05/16 08:54

设出时间t 解方程

#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<cstring>#include<cmath>#define SF scanf#define PF printfusing 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
原创粉丝点击