Codeforces Round #779 (Div. 2)
A
题目大意
给一个01串,其中每一个长度大于等于2的子区间中0的数量不大于1的数量,最少插入多少1
思路
寻找 00 和 010
00 -->0110 加2
010 -->0110 加1
代码
#include <bits/stdc++.h>
using namespace std;
int t;
int main()
{
std::ios::sync_with_stdio(false);
cin >> t;
while (t--)
{
int n;
cin >> n;
string s;
cin >> s;
if (n == 1)
{
cout << "0" << endl;
continue;
}
int z = 0;
for (int i = 0; i < n; i++)
{
if (s[i] == '0')
z++;
}
if (z == 0 || z == 1 && n >= 2)
{
cout << "0" << endl;
continue;
}
int ans = 0;
for (int i = 0; i < n; i++)
{
if (s[i] == '0')
{
for (int j = i + 1; j < n; j++)
{
if (s[j] == '0')
{
if (j - i == 1)
ans += 2;
else if (j - i == 2)
ans += 1;
i = j - 1;
break;
}
}
}
}
cout << ans << endl;
}
return 0;
}
小结:
简单的字符串问题,从最小的单元为起点去思考
B
题意
给一个1~n的排列,若满足以下条件则是一个“美丽排列”。
gcd(1*p1,2*p2,...,n*pn) > 1 ( gcd 求所以元素的最大公约数 )
给定一个n,问有多少种美丽排列,模998244353 。
思路
若 n 为奇数则答案为 0
为偶数则让奇偶相乘 有 (n/2)! * (n/2)!
代码
#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int main()
{
int t;
cin >> t;
while (t--)
{
long long a = 1;
int n;
cin >> n;
if (n % 2 == 1)
{
cout << 0 << endl;
continue;
}
for (int i = 1; i <= n / 2; i++)
{
a = a * i;
a = a % mod;
}
cout << (a * a) % mod << endl;
}
return 0;
}
C
题目大意
这题目题意贼绕
给一个1~n的排列p,根据p做数列b,bi表示p1~pi中的最大值。b数列中不同的数值数量就是排列p的力量。
现在给出数列c,ci表示p向左循环右移i-1位所得到的力量值。问给出的c有没有可能被一种p得到。
思路
观察可知 1 有且只有一个,不符合的可直接判错
通过几组数据模拟可发现,每移动一位 ,下一个力量值最多增加 1 以此判断是否正确
需要注意最后一位也要对第一为进行判断
代码
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
int s[n+1];
int flag = 0;
for (int i = 0; i < n; i++)
{
cin >> s[i];
if (s[i] == 1)
flag++;
}
s[n]=s[0];
int k = 1;
for (int i = 0; i + 1 <= n; i++)
if (s[i + 1] - s[i] > 1)
{
k = 0;
break;
}
if (k == 1 && flag == 1)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
Codeforces Round #779 (Div. 2)的更多相关文章
- 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 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- 一文学会text-justify,orientation,combine文本属性
大家好,我是半夏,一个刚刚开始写文的沙雕程序员.如果喜欢我的文章,可以关注 点赞 加我微信:frontendpicker,一起学习交流前端,成为更优秀的工程师-关注公众号:搞前端的半夏,了解更多前端知 ...
- Kafka生成消息时的3种分区策略
摘要:KafkaProducer在发送消息的时候,需要指定发送到哪个分区, 那么这个分区策略都有哪些呢? 本文分享自华为云社区<Kafka生产者3中分区分配策略>,作者:石臻臻的杂货铺. ...
- 基础学习:社会工程学---利用Kali下的setoolkit进行钓鱼网站制作
利用Kali下的setoolkit进行钓鱼网站制作 1.打开kali2019,输入setoolkit,打开setoolkit模块 2.输入命令1,进入钓鱼攻击页面 3.输入命令2,进入web钓鱼攻击页 ...
- 实战| Nginx+keepalived 实现高可用集群
一个执着于技术的公众号 前言 今天通过两个实战案例,带大家理解Nginx+keepalived 如何实现高可用集群,在学习新知识之前您可以选择性复习之前的知识点: 给小白的 Nginx 10分钟入门指 ...
- Django学习——图书相关表关系建立、基于双下划线的跨表查询、聚合查询、分组查询、F查询、Q查询、admin的使用、使用脚本调用Django、Django查看源生sql
0 图书相关表关系建立 1.5个表 2.书籍表,作者表,作者详情表(垂直分表),出版社表,书籍和作者表(多对多关系) 一对一 多对多 本质都是一对多 外键关系 3.一对一的关系,关联字段可以写在任意一 ...
- 【Electron】使用 build-tools 在 Windows 中编译 electron
[Electron]使用 build-tools 在 Windows 中编译 electron 提前准备 预留好磁盘空间 Git 缓存目录:%UserProfile%/.git_cache ,大概有 ...
- 使用grabit分析mysql数据库中的数据血缘关系
使用grabit分析mysql数据库中的数据血缘关系 Grabit 是一个辅助工具,用于从数据库.GitHub 等修订系统.bitbucket 和文件系统等各种来源收集 SQL 脚本和存储过程,然后将 ...
- Mybatis-Plus乐观锁Version
实现原理 取出记录时,获取当前version更新时,带上这个version执行更新时, set version = newVersion where version = oldVersion如果ver ...
- 好客租房8-React基础阶段总结
React总结 1react是构建用户组件的javascript库 2使用react是,推荐使用脚手架方式 3初始化项目命令:npx create-react-app my-app 4启动项目命令:y ...
- 133_Power BI 报表服务器2020年1月版本更新亮点
博客:www.jiaopengzi.com 焦棚子的文章目录 请点击下载附件 一个很长的春节假期后,居家办公. 升级了Power BI 报表服务器(2020年1月版本). 具体的升级内容见官网博客: ...