Max and Bike CodeForces
For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists’ competitions.
He knows that this year n competitions will take place. During the i-th competition the participant must as quickly as possible complete a ride along a straight line from point si to point fi (si < fi).
Measuring time is a complex process related to usage of a special sensor and a time counter. Think of the front wheel of a bicycle as a circle of radius r. Let’s neglect the thickness of a tire, the size of the sensor, and all physical effects. The sensor is placed on the rim of the wheel, that is, on some fixed point on a circle of radius r. After that the counter moves just like the chosen point of the circle, i.e. moves forward and rotates around the center of the circle.
At the beginning each participant can choose any point bi, such that his bike is fully behind the starting line, that is, bi < si - r. After that, he starts the movement, instantly accelerates to his maximum speed and at time tsi, when the coordinate of the sensor is equal to the coordinate of the start, the time counter starts. The cyclist makes a complete ride, moving with his maximum speed and at the moment the sensor’s coordinate is equal to the coordinate of the finish (moment of time tfi), the time counter deactivates and records the final time. Thus, the counter records that the participant made a complete ride in time tfi - tsi.
Maxim is good at math and he suspects that the total result doesn’t only depend on his maximum speed v, but also on his choice of the initial point bi. Now Maxim is asking you to calculate for each of n competitions the minimum possible time that can be measured by the time counter. The radius of the wheel of his bike is equal to r.
Input
The first line contains three integers n, r and v (1 ≤ n ≤ 100 000, 1 ≤ r, v ≤ 109) — the number of competitions, the radius of the front wheel of Max’s bike and his maximum speed, respectively.
Next n lines contain the descriptions of the contests. The i-th line contains two integers si and fi (1 ≤ si < fi ≤ 109) — the coordinate of the start and the coordinate of the finish on the i-th competition.
Output
Print n real numbers, the i-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10 - 6.
Namely: let’s assume that your answer equals a, and the answer of the jury is b. The checker program will consider your answer correct if .
Example
Input
2 1 2
1 10
5 9
Output
3.849644710502
1.106060157705
題意大概就是給出自行車比賽的計時方式,輪胎上的計時器與起點線位於豎直面上開始即時,與終點線位於同一豎直面上時停止計時,所以如圖所示。
開始計時的時候,s點到輪胎圓心的水平距離差和停止計時時的距離差就是不參與計時的路程,我們就是需要找到一種策略使得這段不參與計時的路程達到最長,易知(不會證)如圖上那種策略時最優的,也就是開始計時時和停止計時的時候計時器是對稱的,假設總路長為dist,我們取len=dist減去路程中完全圓周長的長度(dist/(周長)*周長),剩下的就是最後需要走的距離l和節省下來的兩段距離s。這裡剩下來的距離S等於開始時計時器距離圓心的水平距離*2,所以只要我們找到滿足l+s=len的最小的l就行了,這裡可知s=r*sin(l / r) ,所以l+s是單調的,我們只要用二分法就能快速找到最小的滿足條件的l了。
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
int n, r, v,s,f;
double pai = acos(-1);
int main(){
scanf("%d%d%d", &n, &r, &v);
for (int i = 0; i < n; i++){
scanf("%d%d", &s, &f);
double len = f - s;
double c = pai*r * 2;
int k = len / c;
double ans = k*c / v;
len -= c*k;
len /= 2;
double lef = 0, rig = len;
for (int i = 0; i < 50; i++){
double mid = (lef + rig) / 2;
if (mid + r*sin(mid / r) >= len)rig = mid;
else lef = mid;
}
ans += 2 * lef / v;
printf("%.15lf\n", ans);
}
return 0;
}
相關推薦
Max and Bike CodeForces
For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a
Little Elephant and Elections CodeForces - 258B
clu == ttl 10個 最大值 ant ref 題意 col Little Elephant and Elections CodeForces - 258B 題意:給出m,在1-m中先找出一個數x,再在剩下數中找出6個不同的數y1,...,y6,使得y1到y6中數字
Iahub and Xors Codeforces - 341D
++ get += ORC clas 樹套樹 efi 維護 \n 二維線段樹被卡M+T。。。於是去學二維樹狀數組區間更新區間查詢 樹狀數組維護數列區間xor的修改、刪除(就是把原問題改成一維): 以下p*i實際都指i個p相xor,即(i&1)*pa表示原數列d[
Little Elephant and Array CodeForces - 220B(莫隊)
code con for cin arr main sync r+ ring 給一段長為n的序列和m個關於區間的詢問,求出每個詢問的區間中有多少種數字是 該種數字出現的次數等於該數字 的。 #include <iostream> #include <
codeforces 536a//Tavas and Karafs// Codeforces Round #299(Div. 1)
codeforce lin ostream pre pac cst names 選擇 iostream 題意:一個等差數列,首項為a,公差為b,無限長。操作cz是區間裏選擇最多m個不同的非0元素減1,最多操作t次,現給出區間左端ll,在t次操作能使區間全為0的情況下,問右端
Vasya and Multisets CodeForces - 1051C(英語限制了我的想象力)
存在 分配 元素 == color ons 不想 inf end 題意: 對輸入的每個數都進行分配到兩個多重集中,問分配完以後 每個多重集中的個數為1的元素是否相等 相等則輸出一個分配方式, 不想等為NO 解析: 三種情況 1、原數列中個數為1 的數的個數為偶
Petya and Array CodeForces - 1042D (樹狀數組)
byte get .org sin posit width cli 而不是 class D. Petya and Array time limit per test 2 seconds memory limit per test 256 megabytes inp
Vasya and Robot CodeForces - 1073C (經典走方格問題+二分)
題意:機器人從起點(0,0)開始,每次只能向上,下,左,右進行移動,給出一個移動序列,問你通過修改這個移動序列,可以讓機器人走到(x,y)點的最小修改量(最小修改量定義為:修改的最大編號-最小編號+1)。 思路:將能否走到(x,y)轉化為偏移量能否從 0到 x,0到y. &nb
E. Vanya and Balloons Codeforces Round #355 (Div. 2)
http://codeforces.com/contest/677/problem/E 題意:有n*n矩形,每個格子有一個值(0、1、2、3),你可以在矩形裡畫一個十字(‘+’形或‘x’形),十字的四條邊需等長。問十字覆蓋的格子的值累乘最大是多少? 思路:
Kefa and Watch CodeForces - 580E
http://codeforces.com/problemset/problem/580/E 兩種操作 一是將區間全部改為某個數字 二是詢問一個區間內的數字串是否具有周期性 大體思路是 線段樹維護區間雜湊值 設週期為t 先查[l,l+t-1] [l+t,l+3t-1] [l+3t,
Mashmokh and Numbers CodeForces - 415C
題意:就是n個數和k,每次按順序那兩個數,最大公約數的和為k。 思路:注意:當n=1,k>0時一定不存在,還有n=1,k=0時為1即可。 然後再正常情況下,第一組的最大公約數為k-n/2+1即可,後面是含有素數。(本來,配的是素數和素數+1, 然後會怕第一組會重複,後來直解兩個素數了,因為第一
E - Balls and Boxes CodeForces - 260C(思維)
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Va
H - Sasha and Sticks CodeForces - 832A(long long的使用)
DescriptionIt’s one more school day now. Sasha doesn’t like classes and is always bored at them. So, each day he invents some game and plays in it alone or
P - Kyoya and Photobooks CodeForces - 554A(數學,插空法求排列數
大意 :在一段小寫字母組成的字串中插入一個小寫字母,問有幾種情況 Input a Output 51 Input hi Output 76 對於
T - Memory and Trident CodeForces - 712B( 注意:* ++ = 的優先順序
題意:有四種命令:U代表上移一個單位,D代表下移一個單位,R代表右移一個單位,L代表左移一個單位。 現在給出一串命令,問怎樣修改命令中的任意一條命令,使得命令結束後重新返回原點,並且修改的步數最少。 思路:把問題抽象化,統計四中命令各自有多少,之後D與U相互抵消(numD-numU),R與L相互抵消(nu
T - Memory and Trident CodeForces - 712B( 註意:* ++ = 的優先級
改進 代碼 mem pan 現在 就是 == codeforce 奇數 題意:有四種命令:U代表上移一個單位,D代表下移一個單位,R代表右移一個單位,L代表左移一個單位。 現在給出一串命令,問怎樣修改命令中的任意一條命令,使得命令結束後重新返回原點,並且修改的步數最少。 思
George and Accommodation CodeForces - 467A(語法訓練題)
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the universit
Drazil and Date CodeForces - 515A
Text Reverse Time limit 1000 ms Memory limit 262144 kB Source Codeforces Round #292 (Div. 2) Tags math *1100 Editorial Announcement Tutorial Pro
Codeforces Round #512(Technocup 2019 Elimination Round 1) B. Vasya and Cornfield (Codeforces 1030B)
題意:給出兩個整數n,d,代表有一個在第一象限的矩形,座標是(0,d) (d,0) (n,n-d) (n-d,n),再給出一些點的座標,求出這些點是否在矩形中。 思路:分類討論下。 程式碼: #inc
W - Pasha and Phone CodeForces - 595B (收益頗豐的數學題
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly n digits.