【CPE】一顆星選集(Part 6) | C++

更新 發佈閱讀 5 分鐘

What is the Probability!!

題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=997

中文題目: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

題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1209#google_vignette

#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;
}


留言
avatar-img
留言分享你的想法!
avatar-img
Jim的沙龍
1會員
31內容數
Jim的沙龍的其他內容
2025/08/14
TeX Quotes 題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=208 中文題目:https://zerojudge.t
2025/08/14
TeX Quotes 題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=208 中文題目:https://zerojudge.t
2025/08/13
Problem J: Summing Digits 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=25&page=show_problem&problem=2307#google_vign
2025/08/13
Problem J: Summing Digits 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=25&page=show_problem&problem=2307#google_vign
2025/08/13
List of Conquests 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1361 #include <iostream
2025/08/13
List of Conquests 題目:https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1361 #include <iostream
看更多