What is the Probability!!
中文題目:https://zerojudge.tw/ShowProblem?problemid=e510
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
int S, N, K;
double p;
cin >> S;
while (S--) {
cin >> N >> p >> K;
if (p == 0) {
cout << "0.0000\n";
continue;
}
double first = pow(1.0 - p, K-1) * p;
double r = pow(1.0 - p, N);
cout << fixed << setprecision(4) << first / (1.0 - r) << "\n";
}
return 0;
}
The Hotel with Infinite Rooms
題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1111中文題目:https://zerojudge.tw/ShowProblem?problemid=e555
#include <iostream>
using namespace std;
int main() {
long long S, D, cnt;
while (cin >> S >> D) {
cnt = S;
D -= S;
while (D > 0) {
cnt++;
D -= cnt;
}
cout << cnt << "\n";
}
return 0;
}
498-bis
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
string s;
int x;
vector<int> v;
int main() {
while (cin >> x) {
getline(cin, s);
getline(cin, s);
stringstream ss(s);
v.clear();
while (ss >> s) {
v.push_back(stoi(s));
}
v.pop_back();
reverse(v.begin(), v.end());
long long mul = 1;
int ans = 0;
for (int i=0; i<v.size(); i++) {
ans += v[i]*(i+1)*mul;
mul *= x;
}
cout << ans << "\n";
}
return 0;
}