Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <vector>
- #include <map>
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- int nextInt() {
- int x;
- scanf("%d", &x);
- return x;
- }
- double nextDouble() {
- double x;
- scanf("%lf", &x);
- return x;
- }
- struct Point {
- double x, y;
- Point (double x = 0, double y = 0) : x(x), y(y) {};
- Point operator - (Point op) { return Point(x - op.x, y - op.y); }
- Point operator + (Point op) { return Point(x + op.x, y + op.y); }
- Point operator * (double op) { return Point(x * op, y * op); }
- double operator * (Point op) { return x * op.x + x * op.x; }
- double operator % (Point op) { return x * op.y - y * op.x; }
- double length2() { return x * x + y * y; }
- double length() { return sqrt(x * x + y * y); }
- };
- Point nextPoint() {
- double x = nextDouble();
- double y = nextDouble();
- return Point(x, y);
- }
- typedef vector<Point> Poly;
- const double eps = 1e-9;
- double totalLength(Poly &p) {
- double res = 0;
- for (int i = 1; i < p.size(); ++i) {
- res += (p[i] - p[i - 1]).length();
- }
- return res;
- }
- Point getLPoint(Poly &p, double f) {
- double L = totalLength(p);
- double alp = 0;
- for (int i = 1; i < p.size(); ++i) {
- double l = (p[i] - p[i - 1]).length();
- double beta = alp + l;
- if (alp <= f + eps && f <= beta + eps) {
- Point res = p[i - 1] + (p[i] - p[i - 1]) * ((f - alp) / l);
- return res;
- }
- alp = beta;
- }
- cerr << "botva!2"; throw 0;
- }
- Point convert(Point p, Point s0, Point e0, Point s1, Point e1) {
- Point a0 = e0 - s0;
- Point a1 = e1 - s1;
- Point v0 = p - s0;
- double A = a1.length2() / a0.length2() * (a0 * v0);
- double B = a1.length2() / a0.length2() * (a0 % v0);
- double D = a1.length2();
- double Dx = a1.x * B + a1.y * A;
- double Dy = a1.y * B - a1.x * A;
- Point v1(Dx / D, Dy / D);
- Point res = s1 + v1;
- return res;
- }
- Point solve(int d, double f, Poly &p, Point s, Point e) {
- if (d == 0) {
- Point r = getLPoint(p, f);
- r = convert(r, p[0], p.back(), s, e);
- return r;
- }
- double L = totalLength(p);
- double alp = 0;
- for (int i = 1; i < p.size(); ++i) {
- double l = (p[i] - p[i - 1]).length();
- cerr << l << endl;
- double beta = alp + l;
- cerr << alp << " " << beta << endl;
- if (alp <= f + eps && f <= beta + eps) {
- Point ns = convert(p[i - 1], s, e, p[i - 1], p[i]);
- Point ne = convert(p[i], s, e, p[i - 1], p[i]);
- return solve(d - 1, (f - alp) / l, p, ns, ne);
- }
- alp = beta;
- }
- cerr << "botva!"; throw 0;
- }
- int main() {
- int c = nextInt();
- while (c--) {
- int n = nextInt();
- Poly p(n);
- for (int i = 0; i < n; ++i) {
- p[i] = nextPoint();
- cerr << p[i].x << " " << p[i].y << endl;
- }
- int d = nextInt();
- double f = nextDouble();
- Point res = solve(d, f, p, p[0], p.back());
- printf("(%.10lf,%.10lf)\n", res.x, res.y);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement