Codeforces Round #750 (Div. 2) ABCDEF1
Posted kaka0010
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #750 (Div. 2) ABCDEF1相关的知识,希望对你有一定的参考价值。
比赛链接:https://codeforces.ml/contest/1582
目录
- A. Luntik and Concerts
- B. Luntik and Subsequences
- C. Grandma Capa Knits a Scarf
- D. Vupsen, Pupsen and 0
- E. Pchelyonok and Segments
- F1. Korney Korneevich and XOR (easy version)
A. Luntik and Concerts
直接找规律,发现答案肯定只有01。
- 模上1,2,3的公倍数,然后暴力枚举
- (a+c)%2
#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'
void solve()
int T; cin >> T; while (T--)
int a, b, c; cin >> a >> b >> c;
cout << (a+c)%2 << 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. Luntik and Subsequences
记0的个数为num0,1的个数为num1
f = n u m 1 ∗ 2 n u m 0 f=num1*2^num0 f=num1∗2num0
#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)
void solve()
int T; cin >> T; while (T--)
int n; cin >> n;
vector<int> a(n+1);
ll base = 1, ans = 0;
for (int i = 1; i <= n; i++)
cin >> a[i];
if (a[i] == 0) base = base * 2;
for (int i = 1; i <= n; i++)
if (a[i] == 1) ans += base;
cout << ans << 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. Grandma Capa Knits a Scarf
从两端开始枚举,直到第一个不同位置,那么答案一定就是两者之一了,暴力判断一下
#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)
void solve()
int T; cin >> T; while (T--)
int n; cin >> n;
string s; cin >> s;
char c1, c2;
int flag = 0;
for (int i = 0; i < s.size() / 2; i++)
if (s[i] != s[n-i-1])
flag = 1;
c1 = s[i];
c2 = s[n-i-1];
break;
if (!flag) cout << 0 << endl;
else
int l = 0, r = n - 1;
int num1 = 0;
int flag1 = 0;
while (l < r)
if (s[l] == s[r])
l++, r--;
else
if (s[l] == c1)
l++;
num1++;
else if (s[r] == c1)
r--;
num1++;
else
flag1 = 1;
break;
l = 0, r = n - 1;
int num2 = 0;
int flag2 = 0;
while (l < r)
if (s[l] == s[r])
l++, r--;
else
if (s[l] == c2)
l++;
num2++;
else if (s[r] == c2)
r--;
num2++;
else
flag2 = 1;
break;
if (flag1 && flag2) cout << -1 << endl;
else
if (flag1 && !flag2) cout << num2 << endl;
else if (!flag1 && flag2) cout << num1 << endl;
else cout << min(num1, num2) << 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. Vupsen, Pupsen and 0
思路其实很好想,如果是偶数,直接两两配对。如果是奇数,那么我们选择三个数配对,三个数怎么选呢,如果三个数分别为a,b,c,那么我们给a,b一个系数c,c的系数为-(a+b)。这里还有一个坑,即a+b为0。我先是随机找两个数判,然后t了,后来改成两个同符号的就可以了。
记得两两配对需要除上gcd,不然第二种情况 ∑ b i \\sum bi ∑bi可能会大于1e9
以下是证明可行性:
奇数时的
∑
b
i
\\sum bi
∑bi最大可构造的数为1e4,1e4-1,1e4,1e4-1…,因此sum<1e9-1e5,那么剩下的a,b,c系数和肯定小于1e5,因此符合要求
#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];
void solve()
int T; cin >> T; while (T--)
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
if (n % 2 == 0)
for (int i = 1; i <= n; i += 2)
cout << -a[i+1] << ' ' << a[i] << ' ';
cout << endl;
else
int x, y;
vector<int> fu, zhen;
for (int i = 1; i <= n; i++)
if (a[i] > 0) zhen.push_back(i);
else fu.push_back(i);
if (fu.size() > 1) x = fu[0], y = fu[1];
else x = zhen[0], y = zhen[1];
vector<int> vis(n+1), ans(n+1);
vis[x] = vis[y] = 1;
int pre = 0;
for (int i = 1; i <= n; i ++)
if (vis[i]) continue;
if (pre)
int gcd = __gcd(abs(a[i]), abs(a[pre]));
ans[i] = -a[pre]/gcd;
ans[pre] = a[i]/gcd;
vis[pre] = vis[i] = 1;
pre = 0;
else
pre = i;
for (int i = 1; i <= n; i++)
if (!vis[i])
ans[x] = ans[y] = a[i];
ans[i] = -(a[x]+a[y]);
break;
for (int i = 1; i <= n; i++) cout << ans[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();
Codeforces Round #750 (Div. 2) - B. Luntik and Subsequences - 题解
Codeforces Round #750 (Div. 2)
Codeforces Round #750 (Div. 2) E(dp)
Codeforces Round #436 E. Fire(背包dp+输出路径)