2022.3.28
2022/3/28 6:22:40
本文主要是介绍2022.3.28,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Codeforces Round #779 (Div. 2)
A. Marin and Photoshoot
把所有0的位置找出来放到数组里,如果相邻的0距离为1的话,说明要往中间插2个1,如果距离为2的话只需要插1个1。
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<set> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int N=2e5+10,INF=1e8; int a[N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int t; cin>>t; while(t--) { int n; cin >> n; string s; cin >> s; int cnt = 0,ans=0; for (int i = 0; i < s.size();i++) { if(s[i]=='0') a[cnt++] = i; } for (int i = 0; i < cnt-1;i++) { if(abs(a[i]-a[i+1])==1) { ans+=2; } else if(abs(a[i]-a[i+1])==2) { ans ++; } } cout << ans << '\n'; } return 0; }
B. Marin and Anti-coprime Permutation
为了满足条件,需要把奇数的位置放偶数,偶数的位置放奇数,这样乘起来每个位置一定是偶数,那么最大公约数必不可能为1。放位置的就是排列组合,把n/2,即偶数和奇数的位置的个数,然后分别全排列最后在相乘。当n为奇数一定不满足,因为奇数和偶数的位置个数不一样。
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<set> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int N=2e5+10,INF=1e8,mod=998244353; int main() { cin.tie(nullptr)->sync_with_stdio(false); int t; cin>>t; while(t--) { int n; cin >> n; if(n&1) cout << 0 << '\n'; else { int k = n / 2; ll ans = 1; for (int i = 1; i <= k;i++) { ans = ans * i % mod; } ans = ans * ans % mod; cout << ans << '\n'; } } return 0; }
C. Shinju and the Lost Permutation
这篇关于2022.3.28的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了
- 2024-05-09Google Chrome驱动程序 124.0.6367.62(正式版本)去哪下载?
- 2024-05-09有没有大佬知道这种数据应该怎么抓取呀?
- 2024-05-09这种运行结果里的10.100000001,怎么能最快改成10.1?