cf gym101061H Robocon Club(簡單計算幾何 似乎卡精度)

H. Robocon Club

time limit per test2 seconds
memory limit per test64 megabytes

Problem Description
Ahmed thought that robotics is fun so he quit ACM and joined Robocon club ! Unfortunately his first task at the Robocon Club did not go as well as he expected. He was supposed to build a robot that moves in a straight line.

The robot he had built consists of a line segment of length L with a wheel of radius R on each of it’s endpoints. He placed the robot on the x axis, such that the center of the robot was the point (0, 0) , facing the positive y axis (the left and right wheels are located on and respectively).

The two wheels started moving at the same time, however, instead of moving at the same speed, the left wheel rotated at VL revolutions per second(RPS), while the right wheel rotated at VR RPS. both wheels stopped moving after S seconds. Can you help Ahmed locate the center of his robot?

Input
The first line of the input consists of a single integer T , the number of test cases. T lines follow , each describing a test case consisting of five integers L , R , VL , VR , S . indicating the length of the robot , the radius of each wheel , the speed of the left wheel in (RPS), the speed of the right wheel in (RPS) and the duration that the robot had moved , respectively . where (1 ≤ L ≤ 100 ,1 ≤ R ≤ 100 ,0 ≤ VL ≤ 100 ,0 ≤ VR ≤ 100 , 1 ≤ S ≤ 100 ) .

Output
for each test case print two real numbers on a line separated by a space denotes the coordinates of the center of the robot rounded to three decimal places .

Example
input
4
1 1 1 1 1
7 3 2 3 2
10 1 2 1 1
4 3 2 0 1

output
0.000 6.283
-6.589 -13.682
2.865 8.817
4.000 0.000

說是計算幾何還不如說是數學題,左右速度相等的時候當然就是x爲零,y就是路程,不等的時候就是x軸繞左邊或右邊某一點爲圓心轉圈圈,圓心設一個半徑R,用速度和L一比就算出來了。

似乎卡精度,雖然我沒卡。卡了那位加了eps就過了。

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <set>
#include <algorithm>
#define M 100005
#define mod 1000000007
#define INF -0x3f3f3f3f]
#define PI acos(-1)

using namespace std;

struct node
{
    int id, liter, Max;
};

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        double l, r, vl, vr, s, R;
        bool flag = true;
        scanf("%lf %lf %lf %lf %lf", &l, &r, &vl, &vr, &s);
        if(vl > vr)
        {
            double t = vl;
            vl = vr;
            vr = t;
            flag = false;
        }
        if(vl == vr)
        {
            printf("0.000 %.3lf\n", 2. * vl * r * PI * s);
        }
        else
        {
            R = (vl * l) / (vr - vl);
            double de;
            if(!R)
            {
                de = 2. * vr * r * PI / l * s;
                if(flag)
                    printf("%.3lf %.3lf\n", -(l / 2) * (1 - cos(de)), (l / 2) * sin(de));
                else
                    printf("%.3lf %.3lf\n", (l / 2) * (1 - cos(de)), (l / 2) * sin(de));
            }
            else
            {
                de = 2. * vl * r * PI / R * s;
                if(flag)
                    printf("%.3lf %.3lf\n", -(R + l / 2) * (1 - cos(de)), (R + l / 2) * sin(de));
                else
                    printf("%.3lf %.3lf\n", (R + l / 2) * (1 - cos(de)), (R + l / 2) * sin(de));
            }

        }
    }
    return 0;
}

場上1a過。
運行結果:
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章