Codeforces Round #671 (Div. 2) (A - B、D1题)
比赛链接:https://codeforces.com/contest/1419
https://codeforces.com/contest/1419/problems
A. Digit Game

Example
input
4
1
2
1
3
3
102
4
2069
output
2
1
1
2
题意:
Raze and Breach参加比赛,给定一个 \(n\) 位的数字(从高位到低位 \(14\)~ \(n\)),Raze只能标记奇数位的数字,而Breach只能标记偶数的值,如果存在当仅剩一个未标记的数字时,比赛结束。 如果最后一位数字是奇数,则Raze获胜,否则Breach获胜。
#include<bits/stdc++.h>
using namespace std;
int _, n; string s;
void solve() {
cin >> n >> s;
bool f1 = false, f2 = false;
for (int i = 0; i < n; i += 2)if ((s[i] - '0') % 2 == 1)f1 = true;
for (int i = 1; i < n; i += 2)if ((s[i] - '0') % 2 == 0)f2 = true;
if (n % 2) puts(f1 ? "1" : "2");
else puts(f2 ? "2" : "1");
}
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> _; while (_--)solve();
}
B. Stairs

Example
input
4
1
8
6
1000000000000000000
output
1
2
1
30
思路:
待补
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll _, n, ans, now;
void solve() {
cin >> n;
ans = 2, now = 0;
while ((ans - 1) * ans / 2 <= n)n -= (ans - 1) * ans / 2, now++, ans *= 2;
cout << now << endl;
}
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> _; while (_--)solve();
}
D1. Sage's Birthday (easy version)
https://codeforces.com/problemset/problem/1419/D1
现在有 n 个数,对 a[] 重新排序,使得好数最多
好数的定义:在数组中比相邻的两个数都小,则称为好数,当然数组最左边和最右边的数不能称之为好数
可以保证在数组 a 中,所有的数都是不相同的
观察好数定义,要在数组中相邻的两个数都小,利用样例举例
5
1 2 3 4 5 (这个时候即使乱序也没事,需要sort)
如果我们先从2开始放入b[],间隔2
会得到:
2 x 4 x 5
然后再从1开始:
2 1 4 3 5
b[]符合好数定义
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n; long long a[N + 10], b[2 * N + 1];
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i)cin >> a[i];
sort(a + 1, a + 1 + n); int idx = 1;
cout << (n - 1) / 2 << endl;
for (int i = 2; i <= n; i += 2)b[i] = a[idx++];
for (int i = 1; i <= n; i += 2)b[i] = a[idx++];
for (int i = 1; i < idx; ++i)cout << b[i] << " ";
cout << endl;
}
Codeforces Round #671 (Div. 2) (A - B、D1题)的更多相关文章
- Codeforces Round #524 (Div. 2)(前三题题解)
这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...
- Codeforces Round #671 (Div. 2)
比赛链接:https://codeforces.com/contest/1419 A. Digit Game 题意 给出一个 $n$ 位数,游戏规则如下: 1-indexed Raze标记奇数位 Br ...
- Codeforces Round #671 (Div. 2) B. Stairs 难度1200
题目链接: Problem - 1419B - Codeforces 题目 题意 给x个格子,你可以用这x个格子去拼成楼梯 好的楼梯的要求如下: 1. 第n列有n个格子 2. 这个楼梯的所有格子可以被 ...
- Codeforces Round #671 (Div. 2) (A~E)
Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...
- Codeforces Round #671 (Div. 2) B. Stairs (递推)
题意:一个台阶由一些单元格组成,如果一个高度为\(n\)的台阶中有\(n\)个不相邻的正方形(如图中的样例),就称这个台阶是"好台阶",现给你\(x\)个单元格,问最多能组成多少个 ...
- Codeforces Round #426 (Div. 2)A B C题+赛后小结
最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...
- Codeforces Round #243 (Div. 2) B(思维模拟题)
http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...
- Codeforces Round #340 (Div. 2) A. Elephant 水题
A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...
- Codeforces Round #340 (Div. 2) D. Polyline 水题
D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...
随机推荐
- python计算代码运行时间
记录一下自己用python编写计算运行时间的代码 时间类 import time import numpy as np # 编写时间类来方便操作 class Timer: def __init__(s ...
- CentOS 7替换默认软件源
安装CentOS 7后,默认源在国外,可以替换为国内的源以提升访问速度 参考https://mirrors.ustc.edu.cn/help/centos.html sudo vi /etc/yum. ...
- PageHelper插件注意事项
PageHelper插件注意事项 使用PageHelper.startPage后要紧跟查询语句 下面的代码就有可能出问题: PageHelper.startPage(10, 10); if(param ...
- 【WCH以太网接口系列芯片】基于CH395的组播请求(IGMP)
在上一篇文章中,我们通过直连电脑测试了CH395在组播环境中进行数据的收发,但在实际的使用场景中更多的是将CH395接入局域网环境中.因此,我们需要使用到一个协议--IGMP(Internet Gro ...
- 探究vue的diff算法
1.diff算法是什么? diff算法是一种通过**同层的树节点**进行比较的高效算法 Diff 算法探讨的就是虚拟 DOM 树发生变化后,生成 DOM 树更新补丁的方式.对比新旧两株虚拟 DOM 树 ...
- Python——CSS(层叠样式表,Cascading Style Sheets)、选择器(Selectors)
CSS(层叠样式表,Cascading Style Sheets)是一种用于描述文档样式和布局的样式表语言.它可以与HTML结合使用,用于控制网页的外观和格式.以下是CSS的主要特点和一些基本概念: ...
- C语言汉诺塔递归算法实现
这是个目录 一.什么是递归函数 1.先看一下一个递归的例子 2.递归的基本原理 二.汉诺塔问题 1.简要概括一下汉诺塔的故事 2.回到编程,汉诺塔问题主要就是解决这个问题: 3.怎么解决汉诺塔问题 要 ...
- Baidu Comate实践指南,惊艳了我...
1 啥是Baidu Comate Comate是百度开发的编程大模型工具,它基于文心大模型,结合百度积累多年的编程现场大数据和外部优秀开源数据,为我们生成更符合实际研发场景的优质代码:它能提升编码效率 ...
- win10安装WSL
一.什么是WSL? Windows Subsystem for Linux 简称 WSL,是一个在Windows 10上能够运行原生Linux二进制可执行文件(ELF格式)的兼容层. 二.如何安装WS ...
- 最大伪森林——kruskal算法活用 (HDU - 3367)
最大伪森林--kruskal算法活用 (HDU - 3367) kruskal这一用来求生成树的算法,经过修改拓展之后,可以求很多种形式的子图,本题(HDU3367)即为一个应用案例 单击进入原题 以 ...