比赛链接: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题)的更多相关文章

  1. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  2. Codeforces Round #671 (Div. 2)

    比赛链接:https://codeforces.com/contest/1419 A. Digit Game 题意 给出一个 $n$ 位数,游戏规则如下: 1-indexed Raze标记奇数位 Br ...

  3. Codeforces Round #671 (Div. 2) B. Stairs 难度1200

    题目链接: Problem - 1419B - Codeforces 题目 题意 给x个格子,你可以用这x个格子去拼成楼梯 好的楼梯的要求如下: 1. 第n列有n个格子 2. 这个楼梯的所有格子可以被 ...

  4. Codeforces Round #671 (Div. 2) (A~E)

    Link~ 题面差评,整场都在读题 A 根据奇偶性判断一下即可. #include<bits/stdc++.h> #define ll long long #define N #defin ...

  5. Codeforces Round #671 (Div. 2) B. Stairs (递推)

    题意:一个台阶由一些单元格组成,如果一个高度为\(n\)的台阶中有\(n\)个不相邻的正方形(如图中的样例),就称这个台阶是"好台阶",现给你\(x\)个单元格,问最多能组成多少个 ...

  6. Codeforces Round #426 (Div. 2)A B C题+赛后小结

    最近比赛有点多,可是好像每场比赛都是被虐,单纯磨砺心态的作用.最近讲的内容也有点多,即便是点到为止很浅显的版块,刷了专题之后的状态还是~"咦,能做,可是并没有把握能A啊".每场网络 ...

  7. Codeforces Round #243 (Div. 2) B(思维模拟题)

    http://codeforces.com/contest/426/problem/B B. Sereja and Mirroring time limit per test 1 second mem ...

  8. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  9. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  10. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

随机推荐

  1. 编程技巧 --- VS如何调试.Net源码

    引言 如题,在VS中如何调试 .Net 源码呢? 一般来说,VS2022,都是默认启用 F12 转到定义能够看到源码,如果大家发现自己无法使用 F12 查看源码,可以在 "工具" ...

  2. stm32存储器:Flash

    先擦除后写入,stm32内置flash擦或写时,必须打开外部/内部高速振荡器. 擦除操作 以页为单位,每页1024个字节 起始地址0x0800 0000 擦写时要避开用户程序存储区 最多擦写10万次 ...

  3. 手把手教你搭建 Ceph+JuiceFS

    Ceph 提供了对象存储,可作为存储引擎在 JuiceFS 中使用.这一组合非常适合云计算.大数据分析和机器学习等数据密集型应用场景. 在日常部署中可直接通过 Ceph RADOS 配合 JuiceF ...

  4. vertx的学习总结7之用kotlin 与vertx搞一个简单的http

    这里我就简单的聊几句,如何用vertx web来搞一个web项目的 1.首先先引入几个依赖,这里我就用maven了,这个是kotlin+vertx web <?xml version=" ...

  5. SpringBoot整合Swagger3

    1.导入相关依赖 <!--swagger--> <dependency> <groupId>io.springfox</groupId> <art ...

  6. MySQL运维13-Mycat分库分表之按月分片

    一.按照月分片 使用场景为按照自然月来分片,每个自然月为一个分片,但是一年有12个月,是不是要有12个数据节点才行呢?并不是.例如我现在只有三个分片数据库,这样就可以1月在第一个数据分片中,2月在第二 ...

  7. 华企盾DSC控制台升级提示不能连接服务器

    ​ 由于服务器Apache没有启动导致无法升级,查看版本说明看看是否是版本问题,尝试手动启动Apache服务

  8. GPT Zero 是什么?

    from https://openaigptguide.com/gptzero/ 在人工智能技术飞速发展的今天,人们对于文字内容的准确性和可信度要求越来越高.例如在学术研究领域,防止抄袭和造假是非常重 ...

  9. java,ArrayList类

    ArrayList 是一个数组列表,可以将多个对象放入数组中,是一个长度可变的集合,提供了增删改查的功能. public class Test2 { public static void main(S ...

  10. Python中的协程、线程和进程

    一.协程与多线程和多进程一起使用有什么不同   协程.多线程和多进程都是实现程序并发执行的方法,不过它们在工作方式和适合的应用场景上存在一些区别. 1.协程(Coroutine)   协程是在单一线程 ...