虽然说暑假已经开始,但直到今天才暂时解决了手上的麻烦事,终于可以开始补题了。
题目链接:https://cometoj.com/contest/46
A:
一眼题。没什么好说的,数1、4、5的个数就好了。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curpos<<1 15 #define rson curpos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 2e5 + 10; 21 char s[maxn]; 22 int len; 23 24 int main() { 25 scanf("%s", s + 1); 26 len = strlen(s + 1); 27 int a = 0, b = 0, c = 0; 28 rep1(i, 1, len) { 29 if (s[i] == '1') a++; 30 else if (s[i] == '4') b++; 31 else if (s[i] == '5') c++; 32 } 33 a /= 3; b /= 2; 34 printf("%d ", min(a, min(b, c))); 35 return 0; 36 }
B:
乍一看没啥思路,但是看到样例1-10的答案都是0,感觉很奇怪。
由于数理基础不好(懒得算),直接暴力,居然还过了。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curpos<<1 15 #define rson curpos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int q; 21 ll n; 22 23 int f(int x) { 24 int ret = 0; 25 while (x) { 26 ret += x % 10; 27 x /= 10; 28 } 29 return ret; 30 } 31 32 int main() { 33 scanf("%d", &q); 34 while (q--) { 35 int ans = 0; 36 scanf("%lld", &n); 37 rep1(i, 1, 200) { 38 if (n % i == 0 && f(i) == (i >> 1)) ans++; 39 } 40 printf("%d ", ans); 41 } 42 return 0; 43 }
一看题解,做法天秀:
C:
每次从编号最小的没部署过干员的节点搞就完事了,因为要满足字典序最小。
用个堆维护编号最小,时间复杂度就降到log级别。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curpos<<1 15 #define rson curpos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 5e5 + 10; 21 int n, a[maxn], depth[maxn], vis[maxn]; 22 vector<int>adj[maxn], b[maxn]; 23 multiset<int>lim; 24 priority_queue<int, vector<int>, greater<int>>q; 25 26 void dfs(int x, int f) { 27 depth[x] = depth[f] + 1; 28 b[depth[x]].pb(x); 29 for (auto i : adj[x]) 30 if (i != f) dfs(i, x); 31 } 32 33 int main() { 34 scanf("%d", &n); 35 rep0(i, 1, n) { 36 int x, y; scanf("%d%d", &x, &y); 37 adj[x].pb(y); adj[y].pb(x); 38 } 39 dfs(1, 0); 40 rep1(i, 1, n) scanf("%d", &a[i]); 41 rep1(i, 2, n) lim.insert(a[i]); 42 printf("1 "); 43 if (n == 1) puts(""); 44 int curr = 1, minn = 1; 45 while (curr != n) { 46 while (lim.size() && minn < *lim.begin()) { 47 minn++; 48 for (auto x : b[minn]) q.push(x); 49 } 50 int x = q.top(); 51 lim.erase(lim.find(a[x])); 52 q.pop(); 53 printf("%d ", x); 54 curr++; 55 if (curr == n) puts(""); 56 } 57 return 0; 58 }
D:
从这题开始直接gg。之后就做不下去了……