Codeforces Round #751 (Div. 2) ABCD
Posted kaka0010
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #751 (Div. 2) ABCD相关的知识,希望对你有一定的参考价值。
比赛链接:https://codeforces.ml/contest/1602
目录
A. Two Subsequences
直接找到最小的字符输出,然后把剩下的也输出
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
const ll inf = 1e18;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 7;
#define fi first
#define se second
#define re register
#define lowbit (-x&x)
void solve()
int T; cin >> T; while (T--)
string s; cin >> s;
vector<int> vis(100+1);
int idx = 0;
for (int i = 1; i < s.size(); i++)
if (s[i]< s[idx])
idx = i;
vis[idx] = 1;
cout << s[idx] << ' ';
for (int i = 0; i < s.size(); i++)
if (!vis[i]) cout << s[i];
cout << endl;
signed main()
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
#ifdef ACM_LOCAL
auto start = clock();
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
#ifdef ACM_LOCAL
auto end = clock();
cerr << "Run Time: " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;
#endif
return 0;
B. Divine Array
可以看出超过n次操作肯定会趋于不变,因此 n 2 n^2 n2暴力一下
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
const ll inf = 1e18;
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 7;
#define fi first
#define se second
#define re register
#define lowbit (-x&x)
int a[N];
int b[2005][2005];
void solve()
int T; cin >> T; while (T--)
int n; cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
b[i][j] = 0;
for (int i = 1; i <= n; i++) cin >> a[i], b[0][i] = a[i];
for (int i = 1; i <= n; i++)
vector<int> cnt(n+1);
for (int j = 1; j <= n; j++)
cnt[b[i-1][j]]++;
for (int j = 1; j <= n; j++)
b[i][j] = cnt[b[i-1][j]];
int q; cin >> q; while (q--)
int x, k; cin >> x >> k;
if (k > n) cout << b[n][x] << endl;
else cout << b[k][x] << endl;
signed main()
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
#ifdef ACM_LOCAL
auto start = clock();
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
#ifdef ACM_LOCAL
auto end = clock();
cerr << "Run Time: " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;
#endif
return 0;
C. Array Elimination
从进制角度考虑,每次取k个&肯定会消除k个1,因此每位上的和都是k的倍数,那么可以实现。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
const ll inf = 1e18;
const int N = 2e5 + 10;
const int M = 1e6 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 7;
#define fi first
#define se second
#define re register
#define lowbit (-x&x)
int a[N];
int sum[31];
void solve()
int T; cin >> T; while (T--)
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i < 30; i++) sum[i] = 0;
for (int i = 1; i <= n; i++)
for (int j = 0; j < 30; j++)
sum[j] += (a[i] >> j & 1);
for (int i = 1; i <= n; i++)
int ff = 0;
for (int j = 0; j < 30; j++)
if (sum[j] % i != 0)
ff = 1;
if (!ff) cout << i << ' ';
cout << endl;
signed main()
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
#ifdef ACM_LOCAL
auto start = clock();
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
#ifdef ACM_LOCAL
auto end = clock();
cerr << "Run Time: " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;
#endif
return 0;
D. Frog Traveler
有点毒瘤的题,开始还以为是线段树优化建图,然后跑最短路。赛中忽略了一个重要的条件就是不能往回跳,利用这个条件剪枝就可以了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
const ll inf = 1e18;
const int N = 3e5 + 10;
const int M = 1e6 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 7;
#define fi first
#define se second
#define re register
#define lowbit (-x&x)
#define endl '\\n'
int a[N], b[N], dis[N], n, pre[N];
void print(int x)
if (x == n) return;
print(pre[x]);
cout << x << ' ';
void solve()
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
memset(dis, 0x3f, sizeof dis);
queue<int> q;
q.push(n);
int dep = n;
dis[n] = 0;
while (q.size())
int now = q.front();
q.pop();
if (now <= 0)
cout << dis[now] << endl;
print(now);
return;
int x = now + b[now];
for (int v = min(dep-1, x-1); v >= x-a[x]; v--)
if (dis[v] > dis[now] + 1)
dis[v] = dis[now] + 1;
pre[v] = now;
q.push(v);
dep = min(dep, x - a[x]);
cout << -1 << endl;
signed main()
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
#ifdef ACM_LOCAL
auto start = clock();
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
#ifdef ACM_LOCAL
auto end = clock();
cerr << "Run Time: " << double(end - start) / CLOCKS_PER_SEC << "s" << endl;
#endif
return 0;
以上是关于Codeforces Round #751 (Div. 2) ABCD的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #751 (Div. 2) ABCD
Codeforces Round #751 (Div. 1) B
Codeforces Round #751 (Div. 1) A
Codeforces Round #751 (Div. 2)E. Optimal Insertion(结论,分治)