C. Discrete Acceleration
C. Discrete Acceleration
題解:二分。二分列舉距離,分別求出從前往後的時間與從後往前的時間,讓距離近似相等。
#include <iostream>
#include <cstdio>
typedef long long ll;
using namespace std;
const int N = 1e5+10;
double a[N];
int L;
int n;
double get1(double x){
double pre = 0,t = 0,speed = 1.0;
for(int i = 1;i <= n;i++){
if(a[i] <= x){
t += (a[i]-pre)/speed;
pre = a[i];
}else break;
speed += 1.0;
}
t += (x-pre)/speed;
return t;
}
double get2(double x){
double pre = L,t = 0,speed = 1.0;
for(int i = n;i >= 1;i--){
if(a[i] >= x){
t += (pre-a[i])/speed;
pre = a[i];
}else break;
speed += 1.0;
}
t += (pre-x)/speed;
return t;
}
void solve(){
scanf("%d%d",&n,&L);
for(int i = 1;i <= n;i++){
scanf("%lf",a+i);
}
double l = 0,r = L;
while(r-l > 1e-6){
double mid = (l+r)/2.0;
//cout<<l<<" "<<r<<" "<<mid<<endl;
double t1 = get1(mid);
double t2 = get2(mid);
if(t1 < t2){
l = mid;
}else {
r = mid;
}
}
printf("%.10lf\n",get1(l));
}
int main(){
int t;
scanf("%d",&t);
while(t--){
solve();
}
return 0;
}
相關文章
- C. MonoblockMonoBloC
- C. Checkposts
- C. Rings
- [Paper Reading] VQ-VAE: Neural Discrete Representation Learning
- C. Black Circles
- C. Splitting Items
- C. Game MasterGAMAST
- C. Game on PermutationGAM
- C. Divisor ChainAI
- C. Mixing Water
- C. Binary String Copying
- C. Nezzar and Symmetric Array
- C. MEX Game 1GAM
- C. Torn Lucky Ticket
- C. 最大公約數
- C. k-Amazing Numbers
- C. 在表格裡造序列
- C. Ehab and Path-etic MEXs
- SciTech-Mathematics-Probability+Statistics-Discrete Binomial Distribution: 離散二項式分佈
- CF 1977 C. Nikita and LCM (*1900) 數論
- Codeforces Global Round 11 C. The Hard Work of Paparazzi
- 聯賽模擬測試20 C. Weed
- C. Lose it!(思維)Codeforces Round #565 (Div. 3)
- Introduction_Optimization Models_Giuseppe C. Calafiore, Laurent El GhaouiUI
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 題解】GAM
- C. Dominant Piranha(思維) Codeforces Round #677 (Div. 3)NaN
- 【QBKbupt】第七章 圖 C. 圖練習3
- 2024牛客多校第二場 - C. Red Walking on Grid
- CF1796C C. Maximum Set 題解 排列組合
- Codeforces Round #373 (Div. 1) C. Sasha and Array 線段樹
- Codeforces Round #688 (Div. 2) C. Triangles(思維,數學)
- Codeforces C. Colored Rooks 構造 (Codeforces Round #518 (Div. 2) )
- Arch Linux作為host的vmware中安裝Windows11,啟用3D acceleration失敗解決方法LinuxWindows3D
- Educational Codeforces Round 165 (Rated for Div. 2) C. Minimizing the Sum題解
- 2018 BACS Regional Programming Contest C. BACS, Scoundrel Shopkeeper and Contiguous Sequence (模擬)
- C. VMware下LINUX的虛擬機器增加磁碟空間Linux虛擬機
- 蓋世計劃-0724-B班模擬 C. 遊戲 (game)遊戲GAM
- Sanford C. Bernstein:2019年Q3中國網約車DAU同比下滑6.3%