输入包括一行,四个整数x, f, d, p(1 ≤ x,f,d,p ≤ 2 * 10^9),以空格分割
输出一个整数, 表示小易最多能独立生活多少天。
3 5 100 10
11
则对应代码为: if(d / x <= f) cout << d / x << endl;
Dx + (D-f)p<=d 化简得: D <= (d + f*p) / (x + p)
#include <bits/stdc++.h> using namespace std; int main() { long long x, f, d, p; cin >> x >> f >> d >> p; if(d / x <= f) cout << d / x << endl; else cout << (d + f*p) / (x + p) << endl; return 0; }
#include<iostream> using namespace std; int main(){ int x=0,f=0,d=0,p=0; cin>>x>>f>>d>>p; long long ans=d/x; if(ans<=f){ cout<<ans<<endl; }else{ cout<<f+(d-f*x)/(p+x)<<endl; } return 0; }