欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

CodeforcesRound#773A~D

时间:2023-04-29
有空就写题解 A、Hard Way 思路

签到
特判,一条边平行于 y = 0 y = 0 y=0 的直线,且第三个点在该边下方

#include using namespace std;int main() { int t; cin >> t; while (t -- ) { int x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; if (y1 == y2 && y1 && y3 < y1) { printf("%dn", abs(x1 - x2)); } else if (y2 == y3 && y2 && y1 < y2) { printf("%dn", abs(x3 - x2)); } else if (y1 == y3 && y1 && y2 < y1) { printf("%dn", abs(x1 - x3)); } else { printf("%dn", 0); } } return 0;}


B、Power Walking 思路

签到

#include using namespace std;int main() { int t; scanf("%d", &t); while (t -- ) { int n; map mp; scanf("%d", &n); for (int i = 1; i <= n; i ++ ) { int a; scanf("%d", &a); mp[a] ++; } int cnt = mp.size(); for (int i = 1; i <= n; i ++ ) if (i <= cnt) printf("%d ", cnt); else printf("%d ", i); puts(""); } return 0;}


C、Great Sequence 思路

签到

#include using namespace std;const int N = 2e5 + 10;char str[N];int main() { int t; scanf("%d", &t); while (t -- ) { int n, x; map mp; scanf("%d%d", &n, &x); for (int i = 1; i <= n; i ++ ) { int a; scanf("%d", &a); mp[a] ++; } int ans = 0; for (auto [val, cnt] : mp) { if (1ll * val * x <= 1e9 && mp[val * x]) { int num = mp[val * x]; mp[val * x] -= min(num, cnt); mp[val] -= min(num, cnt); } ans += mp[val]; } printf("%dn", ans); } return 0;}

优化版

#include using namespace std;int main() { int t; scanf("%d", &t); while (t -- ) { int n, x; scanf("%d%d", &n, &x); multiset st; VI a(n); for (int i = 0; i < n; i ++ ) scanf("%d", &a[i]); sort(a.begin(), a.end()); for (int i = 0; i < n; i ++ ) { if (a[i] % x == 0 && st.find(a[i] / x) != st.end()) { st.erase(st.find(a[i] / x)); } else st.insert(a[i]); } printf("%dn", st.size()); } return 0;}


D、Repetitions Decoding 思路

每两个一样的数消除一次,最多要 n n n 个操作,那么 q q q 最多为 n 2 / 2 n ^ 2 / 2 n2/2,每次从后面开始找,每找到就往前面插入数字,然后消除这两个一样的数字。算了,举例子吧
3 2 1 1 2 3
操作 1:2 2 3 2 1 1 2 3
操作 2:2 1 1 2 3 2 1 1 2 3
操作 3:2 1 1 1 1 2 3 2 1 1 2 3
操作 4:2 1 1 2 2 1 1 2 3 2 1 1 2 3
2 1 1 2
操作 1:1 1 2 1 1 2
操作 2:1 1 1 1 2 1 1 2
1 1
操作 1:1 1 1 1

#include using namespace std;void work() { int n; cin >> n; VI a(n); for (int i = 0; i < n; i ++ ) cin >> a[i]; vector res; VI len; while (a.size()) { int i = a.size() - 1, j = i - 1; for (; j >= 0; j -- ) if (a[j] == a[i]) break; if (j == -1) { cout << -1 << endl; return; } for (int k = 0; k < i - j - 1; k ++ ) res.PB({j + k, a[i - k - 1]}); reverse(a.begin() + j, a.end() - 1); len.PB(2 * (i - j)); a.pop_back(), a.pop_back(); } cout << res.size() << endl; for (auto [p, c] : res) cout << p << ' ' << c << endl; cout << len.size() << endl; for (int i = len.size() - 1; i >= 0; i -- ) cout << len[i] << ' '; cout << endl;}int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t -- ) { work(); } return 0;}

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。