头像

Cyan

四川成都

深度强化学习炼丹师

CCPC2019-哈尔滨站

CCPC2019-哈尔滨站

2021-11-21 · 70次阅读 · 原创 · 数据结构与算法

F. Fixing Banners

#include<bits/stdc++.h> using namespace std; const int N = 2e6 + 10; int T, n = 6; char s[6][N]; unordered_set<char> Set[6]; char g[7] = "harbin"; bool v[7]; bool check(int u) { if (u == n) return true; for (int i = 0; i < n; i++) { if (v[i]) continue; if (Set[i].count(g[u]) == 0) continue; v[i] = true; if (check(u + 1)) return true; v[i] = false; } return false; } int main() { cin >> T; while (T--) { memset(v, false, sizeof v); for (int i = 0; i < n; i++) Set[i].clear(); for (int i = 0; i < n; i++) { scanf("%s", s[i]); int len = strlen(s[i]); for (int j = 0; j < len; j++) Set[i].insert(s[i][j]); } if (check(0)) puts("Yes"); else puts("No"); } return 0; }


J. Justifying the Conjecture

#include<bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int T, n; const int M = 1e6 + 5; bool v[M]; vector<int> primes; void calc_primes() { memset(v, true, sizeof(v)); for (int i = 2; i < M; i++) { if (v[i]) { primes.push_back(i); for (int j = 2; j <= M / i; j++) v[i * j] = false; } } } bool check(int x) { for (int i:primes) { if (i * i > x) break; if (x % i == 0) return false; } return true; } int main() { cin >> T; calc_primes(); while (T--) { scanf("%d", &n); bool st = false; for (int x:primes) { if (x >= n) break; int y = n - x; if (y > 1 && !check(y)) { printf("%d %d\n", x, y); st = true; break; } } if (!st) puts("-1"); } return 0; }


K. Keeping Rabbits

#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int T, n, k, w[N]; typedef long long LL; int main() { cin >> T; while (T--) { scanf("%d%d", &n, &k); LL s = 0; for (int i = 1; i <= n; i++) { scanf("%d", &w[i]); s += w[i]; } for (int i = 1; i <= n; i++) { printf("%.5lf ", w[i] + w[i] * 1.0 / s * k); } puts(""); } return 0; }

标题: CCPC2019-哈尔滨站
链接: https://www.fightingok.cn/detail/143
更新: 2022-09-18 22:42:35
版权: 本文采用 CC BY-NC-SA 3.0 CN 协议进行许可