A
题目链接:
https://codeforces.ml/contest/1343/problem/A
这一题我学到了一个除了pow的新知识,在比赛中我用pow怎么都运行不出来,都显示pow不可以运用,结果这个题目中(1<<pw)就指的是2的次方!!!
奇奇怪怪的知识点又学到了,还有就是群里的。
1.for (int& i : p)
cin >> i;
意思是1–p输入i;
2.(1<<k)
意思是2的次方
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int pw = 2; pw < 30; ++pw) {
int val = (1 << pw) - 1;
if (n % val == 0) {
cerr << val << endl;
cout << n / val << endl;
break;
}
}
}
return 0;
}
B
第二题很简单就直接跳过了,哈哈哈,答案没有奇奇怪怪的东西。
C
https://codeforces.ml/contest/1343/problem/C
1.for (auto &it : a)
这个叫做自动迭代器
表示遍历lst这个集合,每次的迭代的其中一个元素是it(auto表示自动推测类型)我在这里又找到更详细的解释。
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
//这个地方我没看懂,求大佬讲解啊!!!
auto sgn = [&](int x) {
if (x > 0) return 1;
else return -1;
};
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (auto &it : a) cin >> it;
long long sum = 0;
for (int i = 0; i < n; ++i) {
int cur = a[i];
int j = i;
while (j < n && sgn(a[i]) == sgn(a[j])) {
cur = max(cur, a[j]);
++j;
}
sum += cur;
i = j - 1;
}
cout << sum << endl;
}
return 0;
}
D
https://codeforces.ml/contest/1343/problem/D
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (auto &it : a) cin >> it;
vector<int> cnt(2 * k + 1);
for (int i = 0; i < n / 2; ++i) {
++cnt[a[i] + a[n - i - 1]];
}
vector<int> pref(2 * k + 2);
for (int i = 0; i < n / 2; ++i) {
int l1 = 1 + a[i], r1 = k + a[i];
int l2 = 1 + a[n - i - 1], r2 = k + a[n - i - 1];
assert(max(l1, l2) <= min(r1, r2));
++pref[min(l1, l2)];
--pref[max(r1, r2) + 1];
}
for (int i = 1; i <= 2 * k + 1; ++i) {
pref[i] += pref[i - 1];
}
int ans = 1e9;
for (int sum = 2; sum <= 2 * k; ++sum) {
ans = min(ans, (pref[sum] - cnt[sum]) + (n / 2 - pref[sum]) * 2);
}
cout << ans << endl;
}
return 0;
}
感觉越到后面越是膜拜大佬们的代码了,后面两道题目还是等到后来水平再高点再搞吧,实在是有的搞不懂啊。下个星期进行!