[ICPC2017 Xi' an R] ICPC 2017 区域赛西安站重现赛/F题解
Simon439747 · · 题解
这题主要是概率论。
先说结论:
::::info[证明]
设对方有
设我们有
再设我们赢得概率为
明显,
此时,假设我们投入
1.赢钱
此时,有
而钱数变为
概率为
1.输钱
此时,也有
而钱数变为
概率为
合并
我们有
同理,第二种情况占比
所以
而
所以
明显,他是个正比例函数。将
| 所以 |
|---|
放个代码。
::::success[AC Code]
//警示后人:十年OI一场空,不开long long见祖宗
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using pll=pair<int,int>;
template<typename T>
inline void readinVector(vector<T>& vec,int l,int r){
for(int i=l;i<=r;i++)cin>>vec[i];
}
template<typename T>
class matvec{
public:
vector<vector<T> >mat;
matvec(){}
matvec(int n){
mat.resize(n+1);
}
void rs(int n){
mat.resize(n+1);
}
matvec(int n,int m){
mat.resize(n+1,vector<T>(m+1));
}
matvec(int n,int m,T v){
mat.resize(n+1,vector<T>(m+1,v));
}
vector<T>& operator[](int i){
return mat[i];
}
void p_b(const vector<T>&vec){
mat.push_back(vec);
}
};
int T=1;
void solve(){
int n,m;
while(cin>>n>>m){
double p=double(n)/(n+m);
cout<<fixed<<setprecision(5)<<p<<endl;
}
}
signed main(){
// freopen("xxx.in","r",stdin);
// freopen("xxx.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
// cin>>T;
while(T--)solve();
return 0;
}
::::