Codeforces Round #529 (Div. 3) 练习赛

Examples
input
6
baabbb
output
bab
input
10
ooopppssss
output
oops
思路:
模拟等差数列即可
#include<bits/stdc++.h>
using namespace std;
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n; string s, ss = "";
cin >> n >> s; int t = 1;
for (int i = 0; i < n; i += t) {
ss += s[i], ++t;
}
cout << ss << endl;
}

Examples
input
4
1 3 3 7
output
2
input
2
1 100000
output
0
Note
In the first example you can remove \(7\) then instability of the remaining array will be \(3−1=2\).
In the second example you can remove either 11 or 100000100000 then instability of the remaining array will be $100000−100000=0 $ and \(1−1=0\) correspondingly.
思路:
取删最小值或最大值的min
#include<bits/stdc++.h>
using namespace std;
int a[100100];
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; ++i)cin >> a[i];
sort(a + 1, a + 1 + n);
cout << min(a[n - 1] - a[1], a[n] - a[2]) << endl;
}

Examples
input
9 4
output
YES
1 2 2 4
思路:

#include<bits/stdc++.h>
using namespace std;
multiset<int>s;
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, k;
cin >> n >> k;
int m = n;
for (int i = 0; m; m >>= 1, ++i)if (m & 1)s.insert(1 << i);
if (n < k || s.size() > k) cout << "NO" << endl;
else {
while (s.size() < k) {
int a = *(--s.end()); s.erase(--s.end());
if (a == 1)break;
s.insert(a / 2);
s.insert(a / 2);
}
cout << "YES" << endl;
while (s.size()) {
cout << *s.begin() << " ";
s.erase(s.begin());
}
}
}

- 思路: 随便选定一个起点即可。那就选择 1吧 , 选择建边 来把原来的图 恢复, 题目给出的信息是这个点后面的两个点
- 我们不能确定这个点与谁相连,当能知道的是 后面的两个点一定相连,所以建两个无向边,最终得到的vector 是 每个点都有
- 两个相连的点,一左一右, 题目让输出的是 从左往右 ,所以我们要保证 dfs恢复图的过程中 从1出发是往后走 。
- 第一个遍历的是 g[ 1 ] [ 0 ]所以保证 g[ 1 ] [ 0 ]是 1后面的点即可。
Ps:成功复习了一遍DFS.
#include<bits/stdc++.h>
using namespace std;
#define maxn 234567
vector<int>g[maxn],o;
int n,x,y,s,t;
void dfs(int u,int p)
{
if(o.size()==n)return ;
o.push_back(u);
if(o.size()==n)return ;
for(int i=0; i<2; i++)
{
if(g[u][i]==p)continue;
dfs(g[u][i],u);
}
}
int main()
{
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%d%d",&x,&y);
if(i==1)s=x,t=y;
g[x].push_back(y);
g[y].push_back(x);
}
if(g[1][1]==s||g[1][1]==t)swap(g[1][0],g[1][1]);
dfs(1,0);
for(int i=0; i<n-1; i++)printf("%d ",o[i]);
printf("%d\n",o[n-1]);
return 0;
}
Codeforces Round #529 (Div. 3) 练习赛的更多相关文章
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence (思维)
Codeforces Round #529 (Div. 3) 题目传送门 题意: 给你由左右括号组成的字符串,问你有多少处括号翻转过来是合法的序列 思路: 这么考虑: 如果是左括号 1)整个序列左括号 ...
- CodeForces Round #529 Div.3
http://codeforces.com/contest/1095 A. Repeating Cipher #include <bits/stdc++.h> using namespac ...
- Codeforces Round #529 (Div. 3) 题解
生病康复中,心情很不好,下午回苏州. 刷了一套题散散心,Div 3,全部是 1 A,感觉比以前慢了好多好多啊. 这几天也整理了一下自己要做的事情,工作上要努力... ... 晚上还是要认认真真背英语的 ...
- Codeforces Round #529 (Div. 3) C. Powers Of Two
http://codeforces.com/contest/1095/problem/C 题意:给n找出k个2的幂,加起来正好等于n.例如 9,4:9 = 1 + 2 + 2 + 4 思路:首先任何数 ...
- Codeforces Round #529 (Div. 3) C. Powers Of Two(数学????)
传送门 题意: 给出一个整数 n ,问能否将 n 分解成 k 个数之和,且这 k 个数必须是2的幂. 如果可以,输出"YES",并打印出任意一组解,反之输出"NO&quo ...
- Codeforces Round #529 (Div. 3) F.Make It Connected
传送门 题意: 有 n 个顶点,每个顶点有个花费 a[ i ],连接顶点 u,v 需要花费 a[v]+a[u]的代价. 有 m 个特殊边,每条边有三个参数 u,v,w 代表的意思是连接 u,v 的花费 ...
- Codeforces Round #529 (Div. 3) D. Circular Dance
传送门 题意: 有 n 个孩子编号为 1~n ,绕着圣诞树 dance: 编号为 i 的孩子可以记住ai1,ai2两个小孩,ai1,ai2是 i 在顺时针方向的相邻的两个小孩,但ai1,ai2不一定是 ...
- Codeforces Round #529 (Div. 3) E. Almost Regular Bracket Sequence(思维)
传送门 题意: 给你一个只包含 '(' 和 ')' 的长度为 n 字符序列s: 给出一个操作:将第 i 个位置的字符反转('(' ')' 互换): 问有多少位置反转后,可以使得字符串 s 变为&quo ...
- Codeforces Round #529 (Div. 3) F. Make It Connected (贪心,最小生成树)
题意:给你\(n\)个点,每个点都有权值,现在要在这\(n\)个点中连一颗最小树,每两个点连一条边的边权为两个点的点权,现在还另外给了你几条边和边权,求最小权重. 题解:对于刚开始所给的\(n\)个点 ...
随机推荐
- Go语言函数详解
函数 (1)函数的定义 函数使用func进行定义 函数是基本的代码块,用于执行一个任务 Go语言至少有一个main函数 函数声明告诉了编译器函数的名称,返回类型和参数 //1.无参数无返回值函数的定义 ...
- Grafana系列-Loki-基于日志实现告警
系列文章 Loki 系列文章 前言 实际应用中除了基于 Metrics 告警, 往往还有基于日志的告警需求, 可以作为基于 Metrics 告警之外的一个补充. 典型如基于 NGINX 日志的错误率告 ...
- [THUPC2022 决赛] rsraogps
[THUPC2022 决赛] rsraogps 题目描述 给序列 \(a_1,\dots,a_n\),\(b_1,\dots,b_n\),\(c_1,\dots,c_n\), 定义区间 \([l,r] ...
- React Hooks 钩子特性
人在身处逆境时,适应环境的能力实在惊人.人可以忍受不幸,也可以战胜不幸,因为人有着惊人的潜力,只要立志发挥它,就一定能渡过难关. Hooks 是 React 16.8 的新增特性.它可以让你在不编写 ...
- Spring系列:基于Spring-AOP和Spring-Aspects实现AOP切面编程
目录 一.概念及相关术语 概念 相关术语 ①横切关注点 ②通知(增强) ③切面 ④目标 ⑤代理 ⑥连接点 ⑦切入点 作用 二.基于注解的AOP 技术说明 准备工作 创建切面类并配置 各种通知 切入点表 ...
- Netty源码学习9——从Timer到ScheduledThreadPoolExecutor到HashedWheelTimer
系列文章目录和关于我 一丶前言 之前在学习netty源码的时候,经常看netty hash时间轮(HashedWheelTimer)的出现,时间轮作为一种定时调度机制,在jdk中还存在Timer和Sc ...
- python pycurl 安装使用
python pycurl 安装使用 本文主要讲下pycurl 安装使用. 1.安装 首先使用 pip 命令安装. pip install pycurl 输出如下: Collecting pycurl ...
- ElasticSearch之cat health API
命令样例如下: curl -X GET "https://localhost:9200/_cat/health?v=true&pretty" --cacert $ES_HO ...
- JavaScript forEach 方法跳出循环
for循环 JavaScript中,for循环可以使用 break 和 continue 来跳出: continue:跳出本次循环 break:结束循环 for (let i = 0; i < ...
- 聊聊ChatGLM-6B部署与微调的深入理解
ChatGLM的部署,主要是两个步骤: 在Github上下载chatglm的库文件 在Hugging Face上下载模型参数与配置文件 ChatGLM包 从Github上看ChatGLM项目文件的结构 ...