Codeforces Round #565 (Div. 3)

Posted wstong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #565 (Div. 3)相关的知识,希望对你有一定的参考价值。

传送门

 

技术图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int main() {
 5     int q; cin >> q;
 6     while (q--) {
 7         ll n; cin >> n;
 8         ll ans = 0;
 9         while (n % 5 == 0) {
10             n = n/5*4;
11             ans++;
12         }
13         while (n % 3 == 0) {
14             n = n/3*2;
15             ans++;
16         }
17         while (n % 2 == 0) {
18             n = n/2;
19             ans++;
20         }
21         if (n != 1) ans = -1;
22         cout << ans << endl;
23     }
24     return 0;
25 }
A. Divide it!

 

技术图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 1005;
 5 map<int,int> mp;
 6 int main() {
 7     int t; cin >> t;
 8     while (t--) {
 9         mp.clear();
10         int n; cin >> n;
11         int ans = 0;
12         for (int i = 1; i <= n; ++i) {
13             int x; cin >> x;
14             if (x % 3 == 0) ans++;
15             else mp[x%3]++;
16         }
17         if (mp[2] == mp[1]) ans += mp[1];
18         else if (mp[2] > mp[1]) {
19             ans += mp[1];
20             mp[2] -= mp[1];
21             ans += mp[2]/3;
22         }
23         else if (mp[1] > mp[2]) {
24             ans += mp[2];
25             mp[1] -= mp[2];
26             ans += mp[1]/3;
27         }
28         cout << ans << endl;
29     }
30     return 0;
31 }
B. Merge it!

 

技术图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 queue<int> que[10];
 5 int main() {
 6     int n, good = 0;
 7     cin >> n;
 8     for (int i = 1; i <= n;++i) {
 9         int x; cin >> x;
10         if (x == 4) que[1].push(i);
11         else if (x == 8) que[2].push(i);
12         else if (x == 15) que[3].push(i);
13         else if (x == 16) que[4].push(i);
14         else if (x == 23) que[5].push(i);
15         else if (x == 42) que[6].push(i);
16     }
17     while (true) {
18         int x = que[1].front();
19         for (int i = 2; i <= 6; ++i) {
20             while (que[i].front() < x && !que[i].empty()) {
21                 que[i].pop();
22             }
23             if (que[i].empty()) break;
24             else if (i == 6 && !que[i].empty()) {
25                 good += 6;
26                 que[6].pop();
27             }
28             else {
29                 x = que[i].front();
30                 que[i].pop();
31             }
32         }
33         if (que[1].empty()) break;
34         else que[1].pop();
35     }
36     cout << n-good << endl;
37     return 0;
38 }
C. Lose it!

 

技术图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 4e5+5;
 5 int b[maxn];
 6 bool prime[2750131+5];
 7 vector<int> ve, a;
 8 map<int,int> mp;
 9 bool cmp(int x, int y) {
10     return x > y;
11 }
12 int main() {
13     memset(prime,true,sizeof(prime));
14     prime[0] = prime[1] = false;
15     for (int i = 2; i <= 2750131; ++i) {
16         if (prime[i] == false) continue;
17         ve.push_back(i);
18         for (int j = i*2; j <= 2750131; j+=i) {
19             prime[j] = false;
20         }
21     }
22     /*
23     for (int i = 1; i <= 100; ++i) {
24         cout << "i: " << i << " prime: " << prime[i] << endl; 
25     }
26     */
27     // cout << lower_bound(ve.begin(),ve.end(),5)-ve.begin()+1 << endl;
28     int n; scanf("%d",&n);
29     for (int i = 1; i <= 2*n; ++i) {
30         scanf("%d",&b[i]);
31         mp[b[i]]++;
32     }
33     sort(b+1,b+1+2*n,cmp);
34     // for (int i = 1; i <= 2*n; ++i) cout << b[i] << endl;
35     for (int i = 1; i <= 2*n; ++i) {
36         if (mp[b[i]] == 0) continue;
37         if (prime[b[i]] == true) {  // 如果是质数
38             int ans = lower_bound(ve.begin(),ve.end(),b[i])-ve.begin()+1;  // 搜索是第几个质数 
39             if (prime[ans] == true) {
40                 mp[ans]--; mp[b[i]]--;
41                 a.push_back(ans);
42                 continue;
43             }
44         }
45         
46         int ans = 1;
47         for (int j = 2; j*j <= b[i]; ++j) {  // 搜索最大除数 
48             if (b[i] % j == 0) ans = max(ans,b[i]/j);
49         }
50         mp[ans]--; mp[b[i]]--;
51         a.push_back(b[i]);
52     }
53     printf("%d",a[0]);
54     for (int i = 1; i < a.size(); ++i) {
55         printf(" %d",a[i]);
56     }
57     printf("
");
58     return 0;
59 }
D. Recover it!

 

技术图片
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn = 2e5+5;
 5 vector<int> ve[maxn];
 6 set<int> se1, se2;
 7 bool vis[maxn];
 8 void dfs(int u, int fa, bool odd) {
 9     if (odd == true) se1.insert(u);
10     else se2.insert(u);
11     for (int i = 0; i < ve[u].size(); ++i) {
12         int to = ve[u][i];
13         if (to == fa) continue;
14         if (vis[to] == true) continue;
15         vis[to] = true;
16         dfs(to,u,odd^1);
17     }
18 }
19 int main() {
20     int t; scanf("%d",&t);
21     while (t--) {
22         memset(vis,false,sizeof(vis));
23         se1.clear(); se2.clear();
24         int n, m; scanf("%d%d",&n,&m);
25         for (int i = 1; i <= n; ++i) {
26             ve[i].clear();
27         }
28         for (int i = 1; i <= m; ++i) {
29             int u, v; scanf("%d%d",&u,&v);
30             ve[u].push_back(v);
31             ve[v].push_back(u);            
32         }
33         vis[1] = true;
34         dfs(1,-1,true);
35         if (se1.size() <= se2.size()) {
36             printf("%d
",se1.size());
37             for (set<int>::iterator iter = se1.begin(); iter != se1.end(); ++iter) {
38                 if (iter == se1.begin()) printf("%d",*iter);
39                 else printf(" %d",*iter);
40             }
41             putchar(
);
42         }
43         else {
44             printf("%d
",se2.size());
45             for (set<int>::iterator iter = se2.begin(); iter != se2.end(); ++iter) {
46                 if (iter == se2.begin()) printf("%d",*iter);
47                 else printf(" %d",*iter);
48             }
49             putchar(
);
50         }
51     }
52     return 0;
53 }
E. Cover it!

 

以上是关于Codeforces Round #565 (Div. 3)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #565 (Div. 3) C. Lose it!

Codeforces Round #565 (Div. 3)

Codeforces Round #565 (Div. 3) E. Cover it!

Codeforces Round #565 (Div. 3)

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)