A-超多数
题目简述
你有正整数A和B,若 则输出Yes,否则输出No。
思路
虽然不是有限小数,但一个数乘它也可以看作以下算式:
有了这个算式,我们就可以写出代码了。
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a, b;
int main(){
cin >> a>>b;
if(a>b*2/3) cout<<"Yes";
else cout<<"No";
return 0;//不会有人连这句都忘了吧?
}
B-停车场2
题目简述
有一个停车场。该停车场的停车费用如下:
-
在从恰好L点到恰好R点的时间段内,每停车一小时收取费用。
-
在上述时间段之外的期间,每停车一小时收取元费用。
如果一辆车从整点 A 到整点 B 停车且未过午夜,则费用是多少?
思路
- 停车总时间段:,计费区间 单价 ,其余时段单价 。
- 求两段区间重叠部分时长: 重叠左边界 重叠右边界 若重叠左 重叠右 重叠时长 ,否则
- 总停车时长:
- 普通时长:
- 总费用
代码
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int X, Y, L, R, A, B;
cin >> X >> Y >> L >> R >> A >> B;
int overL = max(A, L);
int overR = min(B, R);
int t_over = 0;
if (overL < overR) t_over = overR - overL;
int total = B - A;
int t_norm = total - t_over;
int ans = t_over * X + t_norm * Y;
cout << ans << endl;
return 0;//不会有人连这句都忘了吧?
}C-反向排列
题目简述
给你一个整数和一个长度为的字符串,其中由和组成。
有一个长度为的整数序列。初始时,。
按以下顺序对A中的元素执行操作。
-
如果,则反转的前项。具体来说,将与对换位置。
-
如果则不做任何操作。
在所有操作完成后,求出A的值。
思路
本题就是模拟,但必须坐标映射 ,正向模拟不行
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
string S;
cin >> N >> S;
vector<int> ans(N + 1);
int l = 1, r = N;
bool flip = false;
for (int k = N; k >= 1; --k) {
if (S[k - 1] == 'o') flip = !flip;
if (!flip) {
ans[r--] = k;
} else {
ans[l++] = k;
}
}
for (int i = 1; i <= N; ++i) {
cout << ans[i] << (i == N ? "\n" : " ");
}
return 0;//不会有人连这句都忘了吧?
}
D-X到Y
题目简述
你被给定整数和一个至少为的整数。
有一个变量,其初始值为。你可以对x执行以下操作零次或多次:
- 或选择一个满足的整数,并将的值替换 为y。
其中,定义为实数的最大整数。 求使所需的最少操作次数。根据给定约束条件,可以证明总能在有限步内找到一种方法使成立。 你将获得个测试用例;请分别解决每个问题。
思路
输入
-
如果 ,输出 0,结束;
-
预生成列表 :从不断除 向下取整,记录 ,直到;
-
预生成列表 :从 不断除 向下取整,记录 ,直到;
-
建立哈希字典 对应向下步数;
-
初始化答案为无穷大;
-
遍历 中每一组 :
- 若 在 中存在:
- 更新
- 若 在 中存在:
-
输出 。
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<pair<ll, int>> get_path(ll x, ll K) {
vector<pair<ll, int>> res;
int step = 0;
while (true) {
res.emplace_back(x, step);
if (x == 0) break;
x = x / K;
step++;
}
return res;
}
void solve() {
ll X, Y, K;
cin >> X >> Y >> K;
if (X == Y) {
cout << "0\n";
return;
}
vector<pair<ll, int>> px = get_path(X, K);
vector<pair<ll, int>> py = get_path(Y, K);
unordered_map<ll, int> mp;
for (size_t i = 0; i < py.size(); ++i) {
ll val = py[i].first;
int b = py[i].second;
mp[val] = b;
}
ll min_ans = 9000000000000000000LL;
for (size_t i = 0; i < px.size(); ++i) {
ll u = px[i].first;
int a = px[i].second;
if (mp.find(u) != mp.end()) {
ll total = 1LL * a + mp[u];
if (total < min_ans) {
min_ans = total;
}
}
}
cout << min_ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) solve();
return 0;//不会有人连这句都忘了吧?
}