Codeforces Round #663 (Div. 2) (A~C题,C题 Good)
比赛链接:Here
1391A. Suborrays
简单构造题,
把 \(n\) 放最前面,接着补 \(1\) ~ \(n - 1\) 即可
1391B. Fix You
\((1,1)\) -> \((n,m)\) 统计相应个数的 R 和 D 即可
char a[110][110];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int _; for (cin >> _; _--;) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1 ; j <= m; ++j) cin >> a[i][j];
int sum = 0;
for (int i = 1; i < m; ++i) if (a[n][i] != 'R')sum += 1;
for (int i = 1; i < n; ++i) if (a[i][m] != 'D')sum += 1;
cout << sum << "\n";
}
}
1391C. Cyclic Permutations (Good)
先说结论:\(n! - 2^{n - 1}\)
对于任意的循环排列,例如 [4, 2,3,1,5,6] 它包含许多长度为3的循环: [1,2,3],[1,3,5],[3,4,5] 。请注意,所有列出的循环都包含仅从一个i选项中获得的节点。我们可以将其概括为以下几点。如果对于任何一个i,我们在它的两边做边,这将创建一个长度为3的简单循环。证明很简单。
因此,最多只能有一个峰值,即元素 \(n\) ~ 所有非循环排列都会增加,然后达到 \(n\) ,最后减少。这些形式上称为单峰置换,很容易看出,任何单峰置换都形成一棵树,因此不包含简单的循环-除了n之外,每个元素都有一个唯一定义的父元素。
我们可以通过将数字n,n相加来构造任何单峰排列−1,…,1按相同顺序排列成一个三角形。例如,[2,3,4,1]可以通过先将4,3,2推到前面,最后将1推到后面来构造。因此,对于除n之外的每个元素,我们可以选择将其推到前面或后面,使路径总数等于 \(2^{n - 1}\) .
const int mod = 1e9 + 7;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
ll a = 1, b = 1;
for (int i = 1; i <= n; ++i) a = a * i % mod;
for (int i = 1; i < n; ++i) b = b * 2 % mod;
cout << (a + mod - b) % mod;
}
Codeforces Round #663 (Div. 2) (A~C题,C题 Good)的更多相关文章
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #303 (Div. 2) D. Queue 傻逼题
C. Woodcutters Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/probl ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题
B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
随机推荐
- jdk11的HttpClient
我们都知道在jdk11之前都在用okhttp或者org.apache.httpcomponents 其实早在jdk9的时候这个方案就在孵化中 上面的截图来自openjdk的官网,注:openjdk是 ...
- C++学习笔记五:变量与数据类型(Auto类型)
Auto 允许编译器自己来推断变量的类型,这种新功能是在c++11引入的.这个关键字结合for循环使用可以节省变量类型的重复输入.VS Code可以在鼠标移动到变量上之后直接显示变量的类型. auto ...
- 封装RabbitTemplate,使用自定义消息转换器
前面创建项目我就省了...活不多说直接上代码! 核心代码 RabbitMQConfig import lombok.extern.slf4j.Slf4j; import org.springframe ...
- 浅析 ArrayList
by emanjusaka from https://www.emanjusaka.top/2023/12/java-arrayList 彼岸花开可奈何 本文欢迎分享与聚合,全文转载请留下原文地址. ...
- Educational Codeforces Round 26 Problem B
B. Flag of Berland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- HOLMES通过关联可疑信息流进行实时 APT 检测
HOLMES 通过关联可疑信息流进行实时 APT 检测 基本信息 题目:HOLMES: Real-time APT Detection through Correlation of Suspiciou ...
- GPT Zero 是什么?
from https://openaigptguide.com/gptzero/ 在人工智能技术飞速发展的今天,人们对于文字内容的准确性和可信度要求越来越高.例如在学术研究领域,防止抄袭和造假是非常重 ...
- 初识BigDecimal
BigDecimal所创建的是对象,我们不能使用传统的+.-.*./等算术运算符直接对其对象进行数学运算,而必须调用其相对应的方法. 方法中的参数也必须是BigDecimal的对象. BigDecim ...
- 【scikit-learn基础】--『监督学习』之 贝叶斯分类
贝叶斯分类是一种统计学分类方法,基于贝叶斯定理,对给定的数据集进行分类.它的历史可以追溯到18世纪,当时英国统计学家托马斯·贝叶斯发展了贝叶斯定理,这个定理为统计决策提供了理论基础. 不过,贝叶斯分类 ...
- Codeforces 1202D 思维 构造
原题链接 题意 每组数据给我们一个n,然后要求我们用{1, 3, 7}这三种字符来组成一个长度小于1e5的序列,要求其中为1337的子序列(不要求相邻)的数量恰好为n 思路 首先可以考虑最简单的一种构 ...