1176A. Divide it!

题目链接:http://codeforces.com/problemset/problem/1176/A

题意:

给定一个数字 \(n\) 和三种操作

  1. 如果 n 能被 2 整除则 \(n /= 2\)
  2. 如果 n 能被 3 整除 \(n = \frac{2n}3\)
  3. 如果 n 能被 5 整除 \(n = \frac{4n}5\)

求问 \(n\) 最少执行多少次能变成 \(1\) ,如果不行则输出 \(-1\)

//搜索
// Author : RioTian
// Time : 20/10/15
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll _, n, cnt;
void dfs(ll x, ll step) {
if (x == 1) {
cnt = min(step, cnt);
return;
}
if (x % 2 == 0)
dfs(x / 2, step + 1);
else if (x % 3 == 0)
dfs(x * 2 / 3, step + 1);
else if (x % 5 == 0)
dfs(x * 4 / 5, step + 1);
else
cnt = -1;
}
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> _;
while (_--) {
cin >> n, cnt = 9999999;
if (n == 1)
cnt = 0;
else
dfs(n, 0);
cout << cnt << endl;
}
}
//math
#include <bits/stdc++.h>
using namespace std;
int64_t n, i, q;
int main() {
for (cin >> q; q--;) {
cin >> n;
for (i = 0; n > 1 && i < 200; i++)
n % 2 == 0
? n /= 2
: n % 3 == 0 ? n = 2 * n / 3 : n % 5 == 0 ? n = 4 * n / 5 : 0;
cout << (n > 1 ? -1 : i) << endl;
}
}

1176B.Merge it!

题目链接:http://codeforces.com/problemset/problem/1176/B

题意:给定序列,任意俩个元素可以相加成一个元素,求序列元素能被3整除的最大数量。

思路: 对于所有元素进行 模3 的预处理,然后 贪心 余数1 和 余数2 的配对,剩下的 3个 一组配对。

AC代码:

// Author : RioTian
// Time : 20/10/15
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T;
scanf("%d", &T);
while (T--) {
int n, t, a[3] = {0};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &t);
a[t % 3]++;
}
printf("%d\n", a[0] + min(a[1], a[2]) +
(max(a[1], a[2]) - min(a[1], a[2])) / 3);
}
}

1176C. Lose it!

题目链接:https://codeforces.com/problemset/problem/1176/C

题意:保证这个顺序 4,8,15,16,23,42 ,删除其他多余的数据,计算要删除多少个数字,才能保证剩下的数字能组成n套这样的(n≥1);

题解:遍历序列,如果这个数为n,且这个数前面的数字为1,则b[n++],b[前面那个数字]–。

例子:

12

4 8 4 15 16 8 23 15 16 42 23 42

遍历这个序列:

第一个数字是4,则b[4++];

第二个数字是8,则b[8++],b[4–];因为顺序是规定的,所以有8,一定有4。

第三个数字是4,则b[4++];

第四个数字是15,则b[15++],b[8–];

第五个数字是16,则b[16++],b[15–];如果有16一定有15,所以可以用16代替前面的所有数字。

以此类推。(建议在纸上画一下就可以理解了。)

// Author : RioTian
// Time : 20/10/15
#include <bits/stdc++.h>
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long ll;
const int N = 5e5 + 100;
int n, m, a[N], ans[] = {4, 8, 15, 16, 23, 42}, vis[10];
map<int, int> mp;
void init() {
mp[4] = 1; mp[8] = 2;
mp[15] = 3; mp[16] = 4;
mp[23] = 5; mp[42] = 6;
ms(vis, 0);
}
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
while (cin >> n) {
init();
for (int i = 1; i <= n; i++) {
cin >> m;
if (mp[m] == 1)
vis[1]++;
else if (vis[mp[m] - 1] > 0) {
vis[mp[m] - 1]--;
vis[mp[m]]++;
}
}
if (n < 6) cout << n << endl;
else cout << n - vis[6] * 6 << endl;
}
return 0;
}

1176D. Recover it!

https://codeforces.com/problemset/problem/1176/D

题意:给出b[n],按照一定的规则变成a[n];

题解:

原理是:倒推,原本题意是,由a[n]变成b[n];

遍历:

如果a[n]是质数,那么在b[n]中,保留a[n]并且加上质数表中的第a[n]个质数;

如果a[n]是合数,那么在b[n]中,保留a[n]并且加上b[n]的最大除数。

#include <bits/stdc++.h>
using namespace std;
#define N 3000000
int n, i, j, k, x, p[N], q[N], c[N], b[N];
int main() {
for (i = 2; i < N; i++)
if (!p[i]) {
q[++k] = i;
for (j = i + i; j < N; j += i) p[j] = 1;
}
for (cin >> n, i = 0; i < n + n;) cin >> b[i], c[b[i++]]++;
sort(b, b + n + n);
for (i = n + n - 1; i + 1; i--) {
x = b[i];
if (c[x] <= 0 || !p[x]) continue;
for (j = 2; x % j; j++)
;
cout << x << " ", c[x]--, c[x / j]--;
}
for (i = 0; i < n + n; i++)
if (x = b[i], c[x] > 0) cout << x << " ", c[x]--, c[q[x]]--;
return 0;
}

1176E.Cover it! - bfs

https://codeforc.es/contest/1176/problem/E

https://www.cnblogs.com/Yinku/p/11217093.html

久了不写bfs了。一开始用dfs写,的确用dfs是很有问题的,一些奇怪的情况就会导致多染一些色。

注意无向图的边要开双倍。

//DFS 修改以后AC的代码
#include<bits/stdc++.h>
const int maxn = 2e5+10;
using namespace std;
vector<int> V[maxn],ans[2];
int n,m;
int T;
int vis[maxn];
void dfs(int u,int ind) {
vis[u]=1;
ans[ind].push_back(u);
for(auto nx:V[u]) {
if(vis[nx]) continue;
dfs(nx,ind^1);
}
return;
}
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i) {V[i].clear();vis[i]=0;}
ans[0].clear();ans[1].clear();
for(int i=1;i<=m;++i) {
int a,b;
scanf("%d%d",&a,&b);
V[a].push_back(b);
V[b].push_back(a);
}
dfs(1,0);
if(ans[0].size()>ans[1].size()) {
swap(ans[0],ans[1]);
}
printf("%lu\n",ans[0].size());
for(auto x:ans[0]) printf("%d ",x);
puts("");
}
return 0;
}

Codeforces Round #565 (Div. 3) (重现赛个人题解)的更多相关文章

  1. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  2. Codeforces Round #565 (Div. 3) B. Merge it!

    链接: https://codeforces.com/contest/1176/problem/B 题意: You are given an array a consisting of n integ ...

  3. Codeforces Round #565 (Div. 3) A. Divide it!

    链接: https://codeforces.com/contest/1176/problem/A 题意: You are given an integer n. You can perform an ...

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

    链接: https://codeforces.com/contest/1176/problem/C 题意: You are given an array a consisting of n integ ...

  5. Codeforces Round #565 (Div. 3) B

    B. Merge it! 题目链接:http://codeforces.com/contest/1176/problem/B 题目 You are given an array a consistin ...

  6. Codeforces Round #565 (Div. 3) A

    A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You ca ...

  7. Codeforces Round #565 (Div. 3) F.Destroy it!

    题目地址:http://codeforces.com/contest/1176/problem/F 思路:其实就是一个01背包问题,只是添加了回合和每回合的01限制,和每当已用牌数到了10的倍数,那张 ...

  8. Codeforces Round #565 (Div. 3)

    传送门 A. Divide it! •题意 给定一个数n, 每次可以进行下列一种操作 1.如果n可以被2整除,用n/2代替n 2.如果n可以被3整除,用2n/3代替n 3.如果n可以被5整除,用4n/ ...

  9. Codeforces Round #565 (Div. 3)--D. Recover it!--思维+欧拉筛

    D. Recover it! Authors guessed an array aa consisting of nn integers; each integer is not less than ...

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

    题意:给你一串只含\(4,8,15,16,23,42\)的序列,如果它满足长度是\(6\)的倍数并且有\(\frac {k}{6}\)个子序列是\([4,8,15,16,23,42]\),则定义它是好 ...

随机推荐

  1. ClickHouse(16)ClickHouse日志引擎Log详细解析

    日志引擎系列 这些引擎是为了需要写入许多小数据量(少于一百万行)的表的场景而开发的. 这系列的引擎有: StripeLog Log TinyLog 共同属性 引擎: 数据存储在磁盘上. 写入时将数据追 ...

  2. 基于DotNetty实现一个接口自动发布工具 - 通信实现

    基于 DotNetty 实现通信 DotNetty : 是微软的 Azure 团队,使用 C#实现的 Netty 的版本发布.是.NET 平台的优秀网络库. 项目介绍 OpenDeploy.Commu ...

  3. 每天5分钟复习OpenStack(十二)Ceph FileStore 和 BlueSotre

    一个最小化的Ceph集群需要三个组件MON MGR OSD.上一章我们部署了MON,本章节我们完成剩下MGR 和OSD 的部署.在文末我们将重点介绍下什么是FileStore和BlueStore,并详 ...

  4. [python]数据分析--数据清洗处理case1

    数据预处理案例1 主要涉及pandas读取csv文件,缺失值和重复值处理,分组计数,字段类型转换 ,结果写入到Excel. 根据要求对CSV数据集进行处理要求如下: 保留数据关键信息:time.lat ...

  5. 深入理解 Docker 核心原理:Namespace、Cgroups 和 Rootfs

    通过这篇文章你可以了解到 Docker 容器的核心实现原理,包括 Namespace.Cgroups.Rootfs 等三个核心功能. 如果你对云原生技术充满好奇,想要深入了解更多相关的文章和资讯,欢迎 ...

  6. 传统GIS与数字孪生结合带来的改变

    传统的地理信息系统(GIS)在地理数据的收集.存储和分析方面发挥着重要作用,而数字孪生技术则通过虚拟模型的构建与真实世界进行交互和模拟.将传统GIS与数字孪生技术相结合,不仅增强了地理数据的可视化和分 ...

  7. tomcat中文乱码怎么解决

    需要修改Tomcat根目录下面的"logging.properties"文件,把所有的encoding=UTF-8的改成encodng=GBK,保存之后,重启Tomcat服务器,就 ...

  8. MinIO客户端之cat

    MinIO提供了一个命令行程序mc用于协助用户完成日常的维护.管理类工作. 官方资料 mc cat 使用cat命令输出本地硬盘上的文本文件的内容至控制台. ./mc cat ./local.json ...

  9. Spring Boot入坑-2-第一个Spring Boot项目

    Spring Boot简介 自从2014年4月Pivotal团队推出以来,作为一个基于Spring的开源轻量级框架,备受企业级应用喜爱 简化Spring应用的搭建与开发过程 是对Spring缺点进行的 ...

  10. 如何从零开始实现TDOA技术的 UWB 精确定位系统(4)

    这是一个系列文章<如何从零开始实现TDOA技术的 UWB 精确定位系统>第4部分. 重要提示(劝退说明): Q:做这个定位系统需要基础么?A:文章不是写给小白看的,需要有电子技术和软件编程 ...