Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
91831 sh25_shenpy 车轮轴迹 C++ 解答错误 0 MS 268 KB 2019 2026-06-17 06:57:34

Tests(0/10):


#include <iostream> #include <vector> #include <cmath> #include <iomanip> using namespace std; const double eps = 1e-8; struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} Point operator-(const Point& p) const { return Point(x-p.x, y-p.y); } Point operator+(const Point& p) const { return Point(x+p.x, y+p.y); } Point operator*(double k) const { return Point(x*k, y*k); } }; double dot(const Point& a, const Point& b) { return a.x*b.x + a.y*b.y; } double cross(const Point& a, const Point& b) { return a.x*b.y - a.y*b.x; } double len(const Point& a) { return sqrt(a.x*a.x + a.y*a.y); } Point norm(const Point& a) { double l = len(a); return Point(a.x/l, a.y/l); } // 求线段 i 的轴心起点 Point get_center(const Point& p, const Point& dir, double r) { Point nor(-dir.y, dir.x); // 左转法线 return p + nor * r; } int main() { int n; double r; cin >> n >> r; vector<Point> p(n); for (int i = 0; i < n; ++i) { cin >> p[i].x >> p[i].y; } double total = 0.0; // 每一段路面 i -> i+1 for (int i = 0; i < n-1; ++i) { Point s = p[i]; Point e = p[i+1]; Point seg = e - s; double L = len(seg); total += L; // 轴心直线段长度 = 路面长度 } // 每一个中间拐角 i (1<=i<=n-2) for (int i = 1; i <= n-2; ++i) { Point pre = p[i] - p[i-1]; Point nxt = p[i+1] - p[i]; Point u = norm(pre); Point v = norm(nxt); double cr = cross(u, v); double dt = dot(u, v); double theta = atan2(cr, dt); // 外角:车轮绕的角度 double phi = M_PI - fabs(theta); if (theta < -eps) phi = -phi; // 保证方向一致 total += r * fabs(phi); } cout << fixed << setprecision(2) << total << endl; return 0; }


测评信息: