AtCoder Beginner Contest 161
https://atcoder.jp/contests/abc161
这套不算难,但是sb我还是写不出来是为什么呢
F是个妙妙题
C - Replacing Integer
WA了一次所以放上来
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main () {
ll a, b;
cin >> a >> b;
if (a > b) a %= b;
if (a < abs (a - b)) cout << a;
else cout << abs (a - b);
}
D - Lunlun Number
队列模拟
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int k;
int main () {
queue<ll>q;
for (int i = 1; i <= 9; i++) q.push(i);
cin >> k;
k--;
while (k--) {
ll t = q.front();
int d = t % 10;
q.pop ();
ll tt = t * 10 + d;
if (d != 0) q.push (tt - 1);
q.push (tt);
if (d != 9) q.push (tt + 1);
}
cout << q.front ();
}
E - Yutori
正向贪心 + 逆向贪心
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;
int n, k, c, l[N], r[N];
string s;
int main () {
cin >> n >> k >> c >> s;
s = ' ' + s;
vector<int> v1, v2;
int lst = -1e9;
for (int i = 1; i <= n; i++) {
l[i] = l[i-1];
if (s[i] == 'o' && i - lst > c) l[i]++, lst = i;
}
lst = 1e9;
for (int i = n; i >= 1; i--) {
r[i] = r[i+1];
if (s[i] == 'o' && lst - i > c) r[i]++, lst = i;
}
//for (int i = 1; i <= n; i++) cout << l[i] << ' ';cout << endl;
//for (int i = 1; i <= n; i++) cout << r[i] << ' ';cout << endl;
for (int i = 1; i <= n; i++) {
if (s[i] == 'x') continue;
if (l[i-1] + r[i+1] + 1 == k) cout << i << endl;
}
}
F - Division or Subtraction
根号分治
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main () {
ll n, ans = 0;
cin >> n;
//根号分治: n = k^x(ky+1)
if (n == 2) {
cout << 1;
return 0;
}
for (ll i = 2; i * i <= n; i++) {
//k>sqrt(n) -> n % k = 1, k|(n-1)
if ((n - 1) % i == 0) {
ans ++;
if (i * i != n - 1) ans ++;
}
//k<=sqrt(n) -> 暴力除k
ll m = n;
while (m % i == 0) m /= i;
if (m != n && m % i == 1) ans++;
}
cout << ans + 2; //y = 0, n自身
}
//由根号断开
标签:AtCoder,cout,Beginner,int,ll,long,++,lst,161
From: https://www.cnblogs.com/CTing/p/17550059.html