Codeforces Round 957 (Div. 3)
题目链接:Codeforces Round 957 (Div. 3)
总结:E不懂,F差一个set去重
A. Only Pluses
fag:枚举
B. Angry Monk
fag:模拟
Solution:分裂的花费为\(a_i - 1\),添加的花费为\(a_i\)。
C. Gorilla and Permutation
fag:思维
Solution:大于等于\(k\)的数,逆序放在最前面,小于等于\(m\)的数,从最后面开始从大到小放,中间的位置任意放剩下的数。
void solve(){
cin >> n >> m >> k;
vector<int> a(n + 1);
int i, l, r;
for (i = n, l = 1; i >= k; i --, l ++)
a[l] = i;
for (i = m, r = n; i >= 1; i --, r --)
a[r] = i;
for (int i = l; i <= r; i ++){
a[i] = ++ m;
}
for (int i = 1; i <= n; i ++)
cout << a[i] << " \n"[i == n];
}
D. Test of Love
fag:DP
Solution:考虑如何从上一步转移,跳过来或者游过来。
- 注意\(m\)的范围,可以直接枚举前\(m\)个格子(赛时没看到范围,用单调队列优化DP做的)
- 游过来的前提,上一格是水。
void solve(){
cin >> n >> m >> k;
string s;
cin >> s;
s = "$" + s;
deque<int> qu;
vector<int> f(n + 2, INF);
f[0] = 0;
qu.push_back(0);
for (int i = 1; i <= n + 1; i ++){
if (s[i] == 'C')
continue;
while (qu.size() && qu.front() + m < i){ // 存储原木的坐标
qu.pop_front();
}
if (qu.size())
f[i] = f[qu.front()];
if (s[i - 1] == 'W')
f[i] = min(f[i], f[i - 1] + 1);
if (s[i] == 'L'){
while (qu.size() && f[qu.back()] >= f[i])
qu.pop_back();
qu.push_back(i);
}
}
if (f[n + 1] > k){
cout << "NO\n";
}
else{
cout << "YES\n";
}
}
E. Novice's Mistake
fag:思维
Desription:给定一个\(n\),求出所有满足条件的\(a, b\)组合。
- \(1 <= a <= 1e4, 1 <= n <= 100\)
- \(n * a - b\)等于将\(a\)个字符串\(n\)然后删去末尾\(b\)个字符之后代表的整数
- \(n * a - b > 0\)
Solution:注意到字符串的操作会影响答案的位数,但是数值计算\(n * a\)最多为\(1e6\)所以最大只有\(6\)位。
- 我们枚举\(a\),然后枚举答案的位数\(k\),对于每个\(k\)求出一个\(b\),判断当前\(a, b\)是否满足条件
Competing:赛场根本没想到位数的关系
void solve(){
string n;
cin >> n;
vector<pii> ans;
for (int a = 1; a <= 10000; a ++){
int len = to_string(stoi(n) * a).size(); // 当前位数
// if (a == 1262)
// debug(len);
for (int k = len; k; k --){
int b = a * n.size() - k;
if (!b)
continue;
int t = 0;
for (int i = 1, j = 0; i <= k; i ++){
if (j == n.size())
j = 0;
t = t * 10 + (n[j ++] - '0');
}
if (t == stoi(n) * a - b){
ans.push_back({a, b});
}
// if (a == 1262 && b == 2519){
// debug(t, stoi(n) * a - b);
// }
}
}
cout << ans.size() << endl;
for (auto [a, b] : ans){
cout << a << " " << b << endl;
}
}
F. Test of Love
fag:思维
Description:有\(n\)个数,给定一个\(x\),将\(n\)个数分为\(k\)个连续区间,每个区间满足任意一个子集的乘积不等于\(x\)。
1 <= n <= 1e5 2 <= x <= 1e5
1 <= a_i <= 2e5
Solution:从前往后模拟当前区间能够得到那些因数(使用set去重),因为因数的个数很少,所以可做
Competing:没考虑到使用\(set\)去重
void solve(){
int x;
cin >> n >> x;
vector<int> a(n);
set<int> v; // 记录当前区间所有可能出现的x的约数
for (int i = 0; i < n; i ++)
cin >> a[i];
int ans = 1;
for (int i = 0; i < n; i ++){
if (x % a[i])
continue;
set<int> tmp;
for (auto j : v){
tmp.ep(a[i] * j); // 记录能够构造出来的数
}
for (auto j : tmp){
if (x % j)
continue;
v.ep(j);
}
if (v.find(x) != v.end()){
ans ++;
v.clear();
}
v.ep(a[i]);
}
cout << ans << endl;
}
Codeforces Round 957 (Div. 3)的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- C# 串口读取并转换字符串
public string ReadString() { ASCIIEncoding ascii = new ASCIIEncoding(); byte[] readBuffer = new byte ...
- VMware安装教程---------------------以及Windows,Linux,Apple MAC OS系统安装
1.什么是VMware虚拟机 VMware虚拟机是一个虚拟机软件,它可以在一台机器上同时运行多个系统,这些系统包括Windows,Linux,Apple os等. 2.虚拟机有什么用 虚拟机的用处很多 ...
- 2022年3月(202203)小米路由R3G(3G)刷openwrt和padavan的总结
本篇文章是本人这2天刷小米路由R3G的记录,中间可能有很多错误,欢迎留言指出. 1.千万别断电 2.刷机的时候要多等待 小米路由很多型号有着很强的可玩性,128M以上的ROM,256M以上的内存,R3 ...
- golang 正则表达式
package main import "bytes" import "fmt" import "regexp" func main() { ...
- python常用模块汇总
os模块 os.remove() 删除文件 os.unlink() 删除文件 os.rename() 重命名文件 os.listdir() 列出指定目录下所有文件 os.chdir() 改变当前工作目 ...
- Codeforces Round 856 (Div2)
Counting Factorizations 任何一个正整数 \(m\) 都可以被唯一的分解为 \(p_1^{e_1} \cdot p_2^{e_2} \ldots p_k^{e_k}\) 的形式. ...
- docker 下载镜像配置
现在docker 安装镜像的时候,会发现下载不了镜像. 有网友提供了一些可用的镜像,亲测可用. { "registry-mirrors": [ "https://dock ...
- Sealos Devbox 使用教程:使用 Cursor 一键搞定数据库开发环境
"诶,你这前后端开发环境怎么搭建这么快?" "用了 Devbox 啊." "不是吧,你怎么在 Cursor 里连接开发环境的数据库,这些都配好了?&q ...
- RPM 与 YUM
RPM 与 YUM rpm 包的管理 rpm 用于互联网下载包的打包及安装工具,它包含在某些 Linux 分发版中.它生成具有.RPM 扩展名的文件.RPM是 RedHat Package Manag ...
- 【Amadeus原创】更改docker run启动参数
经过一整天的摸索,答案: 没法直接修改.只能另外创建. 但是还好不用完全重头来,用docker commit命令可以基于当前修改的内容创建一个新的image. 执行docker 看看帮助先: Comm ...