A. Floor Number

https://codeforces.com/contest/1426/problem/A

题意:

一个楼房房间号由 \(1\) 递增,一楼仅2个房间。给定一位用户的房间号和 \(2\)楼以上每层的房间数\(x\)

求出用户所在楼层

思路:

很简单,理解题意即可。

如果 \(n≤2\) ,则答案为1。否则,您可以“删除”第一层,然后答案为 \(⌊\frac{n-3}{x}⌋+ 2。\)

#python
for i in range(int(input())):
n, x = map(int, input().split())
print(1 if n <= 2 else (n - 3) // x + 2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int _; cin >> _; while (_--) {
ll n, x;
cin >> n >> x;
if (n <= 2)cout << 1 << endl;
else cout << (n - 3) / x + 2 << endl;
}
}

B. Symmetric Matrix

https://codeforces.com/contest/1426/problem/B

题目有点长,大家点击链接看原题 或者 题意↓

题意:

给定 n 种 2 x 2大小的方块,问是否能通过这些方块组成 m x m的矩形(需要 \(s[i][k] = s[j][i]\))

思路:

首先,如果m为奇数,则出于显而易见的原因,答案为“否”。 否则,我们会注意到图块的左上角和右下角值无关紧要(因为我们可以对称放置图块)。 因此,我们只需要检查是否有一些图块的右上值等于其左下值(因为这是我们获得主对角线对称性的方式)。

#python
for i in range(int(input())):
n, m = map(int, input().split())
a = []
for i in range(n):
a.append([[int(x) for x in input().split()] for i in range(2)])
ok = False
for i in range(n):
ok |= a[i][0][1] == a[i][1][0]
ok &= m % 2 == 0
print("YES" if ok else "NO")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
ll n, m;
cin >> n >> m;
ll a, b, c, d;
bool f1 = 0, f2 = 0;
for (int i = 1; i <= n; ++i) {
cin >> a >> b >> c >> d;
if (!f2 && b == c)f2 = 1;
}
if (m % 2 == 0)f1 = 1;
if (f1 && f2)cout << "YES" << endl;
else cout << "NO" << endl;
} int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int _; cin >> _; while (_--)solve();
}

C. Increase and Copy

https://codeforces.com/contest/1426/problem/C

题意:

思路:

直观地说,我们首先需要进行所有增量操作,然后才需要复制数字(因为否则我们可以交换移动顺序,并且总和不会减少)。 您可能会注意到答案不超过 \(O(\sqrt{n})\),所以我们可以从1迭代到⌊\(O(\sqrt{n})\)⌋,然后确定要复制的数字。 设为x。 那么我们需要x-1个移动来获得它,还需要⌈\(\frac{n-x}x\)⌉个移动来获得足够数量的副本。 因此,我们可以用此举数来更新答案。

时间复杂度:每个测试用例为\(O(\sqrt{n})\)。

实际上,所需的数字总是非常接近⌊\(O(\sqrt{n})\)⌋,因此只要尝试在[⌊\(O(\sqrt{n})\)⌋-5; ⌊\(O(\sqrt{n})\)⌋ + 5]范围内进行一些选择就足够了。 回答。 这是 \(O(1)\)解决方案。

#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 t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ans = 1e9;
for (int x = 1; x * x <= n; ++x) {
ans = min(ans, x - 1 + ((n - x) + x - 1) / x);
}
cout << ans << endl;
}
}

D. Non-zero Segments

https://codeforces.com/contest/1426/problem/D

从开始遍历,利用sum去统计前面一段的值。

如果已经出现过,说明会导致有区间和为0的情况出现,ans++并且map clear 重新计数 sum从当前开始.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n; cin >> n;
map<ll, ll>m;
ll ans = 0, sum = 0, x;
m[0]++;
for (int i = 0; i < n; ++i) {
cin >> x;
sum += x;
if (m[sum] > 0) {
ans++;
sum = x;
m.clear();
m[0]++;
}
m[sum]++;
}
cout << ans;
}

E. Rock, Paper, Scissors

https://codeforces.com/contest/1426/problem/E

Alice 和 Bob这次开始玩猜拳了,给定他们玩的次数n,和石头剪刀布出现的次数,求Alice能赢的最多次数和最少次数。

思路:

赢最多不用说吧?

赢最少, 无非是 拳头被拳头和包吃了, 剪刀被剪刀和石头吃了, 包被拳头和包吃了

抵消完后, 要么你剩下拳头/剪刀/包, 对手剩下剪刀/包/拳头, 这就是你最少赢的

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll q_max(ll x, ll y, ll z, ll h) {
x = x > y ? x : y;
x = x > z ? x : z;
x = x > h ? x : h;
return x;
} int main() {
//freopen("in.txt", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
ll n, a, b, c, x, y, z;
cin >> n;
cin >> a >> b >> c >> x >> y >> z;
cout << q_max(0, a - x - z, b - x - y, c - y - z ) << " " << min(a, y) + min(b, z) + min(c, x);
}

F. Number of Subsequences

没做出来

先贴一下dalao的代码留做学习

#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
typedef ll ll;
int main() {
int n; cin >> n;
string ss; cin >> ss;
ll x = 0;
ll ans = 0;
ll temp = 0;
ll num = 1;
for (int i = 0; i < n; i++) {
if (ss[i] == 'a') x += num;
else if (ss[i] == 'b') temp += x;
else if (ss[i] == 'c') ans += temp;
else {
ans = ans * 3 + temp;
temp = temp * 3 + x;
x = x * 3 + num;
num *= 3;
}
num %= mod;
x %= mod; temp %= mod; ans %= mod;
}
cout << ans << endl;
}

学习隔壁 洛绫璃dalao 的写法:

利用模拟思想:

题目问我们能组成 abc 的可能性,需要在3^k的情况取模

先把可能的情况标出来以后再处理

1~~a
2~~?
3~~ab
4~~a?
5~~?b
6~~??
7~~abc
8~~ab?
9~~a?c
10~~?bc
11~~a??
12~~?b?
13~~??c
14~~???
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define IOS ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, mod = 1e9 + 7;
int n, m, _, k;
char s[N];
ll a[20], ans = 0;
int qpow(ll a, ll b) {//快速幂
ll ans = 1; a %= mod;
for (; b; a = a * a % mod, b >>= 1)
if (b & 1) ans = ans * a % mod;
return ans;
}
int main() {
IOS; cin >> n;
cin >> s + 1;
rep(i, 1, n)
if (s[i] == 'a') ++a[1];
else if (s[i] == 'b') {
a[3] += a[1];
a[5] += a[2];
}
else if (s[i] == 'c') {
a[7] += a[3];
a[9] += a[4];
a[10] += a[5];
a[13] += a[6];
}
else {
a[14] += a[6];
a[12] += a[5];
a[11] += a[4];
a[8] += a[3];
a[6] += a[2];
a[4] += a[1];
++a[2];
}
//如果存在这种可能性,利用相应组合计算
if (a[7]) ans = a[7] % mod * qpow(3, a[2]) % mod;
if (a[8]) ans = (ans + a[8] % mod * qpow(3, a[2] - 1) % mod) % mod;
if (a[9]) ans = (ans + a[9] % mod * qpow(3, a[2] - 1) % mod) % mod;
if (a[10]) ans = (ans + a[10] % mod * qpow(3, a[2] - 1) % mod) % mod;
if (a[11]) ans = (ans + a[11] % mod * qpow(3, a[2] - 2) % mod) % mod;
if (a[12]) ans = (ans + a[12] % mod * qpow(3, a[2] - 2) % mod) % mod;
if (a[13]) ans = (ans + a[13] % mod * qpow(3, a[2] - 2) % mod) % mod;
if (a[14]) ans = (ans + a[14] % mod * qpow(3, a[2] - 3) % mod) % mod;
cout << ans;
return 0;
}

Codeforces Round #674 (Div. 3) (A - F题题解)的更多相关文章

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

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

  2. Codeforces Round #599 (Div. 2)的简单题题解

    难题不会啊…… 我感觉写这个的原因就是因为……无聊要给大家翻译题面 A. Maximum Square 简单题意: 有$n$条长为$a_i$,宽为1的木板,现在你可以随便抽几个拼在一起,然后你要从这一 ...

  3. Codeforces Round #674 (Div. 3) C、D 题解

    C.Increase and Copy #枚举 题目链接 题意 最初你有仅包含一个数字\(1\)的数组\(a\),一次操作中可对该数组进行两类操作: 从数组中选择一个元素,将该元素\(+1\): 从数 ...

  4. Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2) (前三题题解)

    这场比赛好毒瘤哇,看第四题好像是中国人出的,怕不是dllxl出的. 第四道什么鬼,互动题不说,花了四十五分钟看懂题目,都想砸电脑了.然后发现不会,互动题从来没做过. 不过这次新号上蓝名了(我才不告诉你 ...

  5. Codeforces Round #573 (Div. 1) 差F

    Codeforces Round #573 (Div. 1) E 题意:二维平面上有 n 个点,你可以放至多 m 条直线使得 (0,0) 与每个点的连线至少与一条直线相交.求原点与所有直线的距离最小值 ...

  6. BestCoder Round #11 (Div. 2) 前三题题解

    题目链接: huangjing hdu5054 Alice and Bob 思路: 就是(x,y)在两个參考系中的表示演全然一样.那么仅仅可能在这个矩形的中点.. 题目: Alice and Bob ...

  7. Codeforces Round #674 (Div. 3) F. Number of Subsequences 题解(dp)

    题目链接 题目大意 给你一个长为d只包含字符'a','b','c','?' 的字符串,?可以变成a,b,c字符,假如有x个?字符,那么有\(3^x\)个字符串,求所有字符串种子序列包含多少个abc子序 ...

  8. Codeforces Round #600 (Div. 2)E F

    题:https://codeforces.com/contest/1253/problem/E 题意:给定n个信号源,俩个参数x和s,x代表这个信号源的位置,s代表这个信号源的波及长度,即这个信号源可 ...

  9. Codeforces Round #346 (Div. 2) E F

    因为很久没有个人认真做题了 昨天晚上开了场虚拟cf来锻炼个人手速 选的是第一次做cf的场 那时候7出3还被hack...之后也没补题 这次做的时候顺便回忆了一下以前比赛的时候是怎么想的 发现经验还是很 ...

  10. Codeforces Round #336 (Div. 2)-608A.水题 608B.前缀和

    A题和B题...   A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabyte ...

随机推荐

  1. 解锁 ElasticJob 云原生实践的难题

    发生了什么 最近在逛 ElasticJob 官方社区时发现很多小伙伴都在头疼这个 ElasticJob 上云的问题,ElasticJob 本就号称分布式弹性任务调度框架,怎么在云原生环境就有了问题了呢 ...

  2. 神经网络入门篇:详解搭建神经网络块(Building blocks of deep neural networks)

    搭建神经网络块 这是一个层数较少的神经网络,选择其中一层(方框部分),从这一层的计算着手.在第\(l\)层有参数\(W^{[l]}\)和\(b^{[l]}\),正向传播里有输入的激活函数,输入是前一层 ...

  3. 将mysql的输出文本写回mysql

    1 准备工作 1.1 环境准备 操作系统:Microsoft Windows 10 专业工作站版 软件版本:Python 3.9.6 第三方包: pip install pandas2.1.0 pip ...

  4. 【UniApp】-uni-app-自定义组件

    前言 经过上个章节的介绍,大家可以了解到 uni-app-网络请求的基本使用方法 那本章节来给大家介绍一下 uni-app-自定义组件 的基本使用方法 原本打算是直接写项目的,在写项目之前还有个内容需 ...

  5. 组合式api-计算属性computed的使用

    计算属性在vue3中和vue2的思想概念都是一样,唯一区别就是在使用组合式api时候的语法稍有不同. 使用步骤: 导入computed函数 import {computed} from 'vue' 使 ...

  6. Alpha-Beta剪枝的原理的深入理解(无图预警)

    转载请注明 原文链接 :https://www.cnblogs.com/Multya/p/17929261.html 考虑一个树: 一棵树上只有叶子节点有值,有确定的根节点的位置 根据层数来划分叶子节 ...

  7. 【eBPF-02】入门:基于 BCC 框架的程序进阶

    本文是 eBPF 系列的第二篇文章,我们来学习 eBPF BCC 框架的进阶用法,对上一篇文章中的代码进行升级,动态输出进程运行时的参数情况. 主要内容包括: 通过 kprobe 挂载内核事件的 eB ...

  8. Java数组常见的几种排序。

    public class code2 { public static void main(String[] args) { int[] x = {37, 89, 23}; for (int z = 0 ...

  9. SaaS 营销,如何利用 RPA 实现自动化获客?

    大家好,这次给大家带来如何利用 RPA 实现自动化获客. 一.RPA 是什么?难吗? RPA 对大家来说,可能挺陌生的,其实它很简单. Robotic Process Automation(简称 RP ...

  10. Python从0到1丨图像增强及运算:形态学开运算、闭运算和梯度运算

    摘要:本文主要介绍图像形态学处理,详细讲解了图像开运算.闭运算和梯度运算.数学形态学是一种应用于图像处理和模式识别领域的新方法,其基本思想是用具有一定形态的结构元素去量度和提取图像中对应形状以达到对图 ...