T1:Print 341
模拟
代码实现
n = int(input())
print('1'+'01'*n)
T2:Foreign Exchange
模拟
代码实现
n = int(input())
a = list(map(int, input().split()))
for i in range(n-1):
s, t = map(int, input().split())
x = a[i]//s
a[i+1] += t*x
print(a[-1])
T3:Takahashi Gets Lost
暴搜
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
string t;
cin >> t;
vector<string> s(h);
rep(i, h) cin >> s[i];
int ans = 0;
rep(si, h)rep(sj, w) {
if (s[si][sj] == '#') continue;
bool ok = true;
int i = si, j = sj;
for (char c : t) {
if (c == 'L') j--;
if (c == 'R') j++;
if (c == 'U') i--;
if (c == 'D') i++;
if (s[i][j] == '#') {
ok = false;
break;
}
}
if (ok) ans++;
}
cout << ans << '\n';
return 0;
}
T4:Only one of two
考虑二分答案
记 \(f(x)\) 表示在 \(1 \sim x\) 中满足条件的数的个数
那么 \(f(x) = \lfloor\frac{x}{n}\rfloor + \lfloor\frac{x}{m}\rfloor - 2 \times \frac{x}{\operatorname{lcm}(n, m)}\)
判定条件为 \(f(x) \geqslant k\)
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
ll n, m, k;
cin >> n >> m >> k;
ll l = lcm(n, m);
auto f = [&](ll x) {
ll c = x/n + x/m - x/l*2;
return c >= k;
};
ll wa = 0, ac = 1e18;
while (ac-wa > 1) {
ll wj = (ac+wa)/2;
if (f(wj)) ac = wj; else wa = wj;
}
cout << ac << '\n';
return 0;
}