当前位置:网站首页>Codeforces Round #770 (Div. 2) ABC
Codeforces Round #770 (Div. 2) ABC
2022-07-05 01:37:00 【Vijurria】
The main idea of the topic : Given a length of n String s, The number of transformations is k. ask k How many different strings can you get after one operation ?
Operating rules :1. s→s+reverse(s) or 2. s→reverse(s)+ s ( Choose any transformation )
input
4 3 2 aab 3 3 aab 7 1 abacaba 2 0 aboutput
2 2 1 1
When the string is palindrome , Both transformations are ultimately the same , So just judge s Whether it is a palindrome string can determine the trend of future transformation . Non palindromes will also become palindromes after an operation , So it's one step more than palindrome .
Special judgement k==0 He still exists in a form of the original string
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int t; cin>>t;
while(t--)
{
int n,k; cin>>n>>k;
string s; cin>>s;
bool flag=true;
if(k==0) cout<<"1"<<endl;
else{
for(int i=0;i<n;i++)
if(s[i]!=s[n-i-1]) flag=false;
if(flag==false) cout<<"2"<<endl;
else cout<<"1"<<endl;
}
}
return 0;
}The main idea of the topic : In limine Alice from x Start the operation ,Bob from x+3 Start the operation , And then there's a length of n Sequence a, Traverse this sequence from front to back , Every time Alice and Bob They have to make the following changes to their numbers :
1.d→d+ai; 2.d→d xor ai( A choice ).
Ask after all the operations are finished , Who can just get y, And the output ( The title is guaranteed to be available to only one person y).
input
4 1 7 9 2 2 0 2 1 3 4 0 1 1 2 3 4 2 1000000000 3000000000 1000000000 1000000000output
Alice Alice Bob Alice
adopt x And x+3 We can know that their parity is different , Each exclusive or operation on an odd number will change its parity , So we can assume alice Hold an odd number , And with arrays a Xor operation , If Alice After XOR with the whole array, and y The parity of is the same , Then output Alice , Otherwise output Bob.
Exclusive or ^ :110 000 101 010
Bitwise AND & :111 100 010 000
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
LL a[200200];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL t,n,x,y;
cin>>t;
while(t--)
{
cin>>n>>x>>y;
for(int i=1;i<=n;i++)
{
cin>>a[i];
x^=a[i];
}
if(((x^y)&1)==0)cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
return 0;
}The main idea of the topic :n That's ok m Column , Ask if you can put 1~n*m Put them into this matrix and take out any string of numbers on any row , Their average must be an integer .
input
4 1 1 2 2 3 3 3 1output
YES 1 YES 1 3 2 4 NO YES 1 2 3
It can be simplified to two numbers ,/2 To be integer , That must be the same parity , Extended to a long string of numbers, it must be the same parity to get the whole . Then controlling the odd and even separation becomes .
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int t,n,m;
cin>>t;
while(t--)
{
cin>>n>>m;
if(m==1)
{
cout<<"YES"<<endl;
for(int i=1;i<=n;i++)
cout<<i<<endl;
}
else if(n&1) cout<<"NO"<<endl;// If it is an odd row, there must be a row with odd and even coexistence
else
{
cout<<"YES"<<endl;
for(int i=1,k=1;i<=n*m;i+=2,k++)
{
cout<<i<<" ";
if(k%m==0) cout<<endl;
}
for(int i=2,k=1;i<=n*m;i+=2,k++)
{
cout<<i<<" ";
if(k%m==0) cout<<endl;
}
}
}
return 0;
}边栏推荐
- Great God developed the new H5 version of arXiv, saying goodbye to formula typography errors in one step, and mobile phones can also easily read literature
- Global and Chinese market of optical densitometers 2022-2028: Research Report on technology, participants, trends, market size and share
- Interesting practice of robot programming 15- autoavoidobstacles
- Global and Chinese market of network connected IC card smart water meters 2022-2028: Research Report on technology, participants, trends, market size and share
- La jeunesse sans rancune de Xi Murong
- Jcenter () cannot find Alibaba cloud proxy address
- WCF: expose unset read-only DataMember property- WCF: Exposing readonly DataMember properties without set?
- 【大型电商项目开发】性能压测-性能监控-堆内存与垃圾回收-39
- 如果消费互联网比喻成「湖泊」的话,产业互联网则是广阔的「海洋」
- Discrete mathematics: reasoning rules
猜你喜欢

ROS command line tool

Nebula Importer 数据导入实践

Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)

【大型电商项目开发】性能压测-优化-中间件对性能的影响-40

Yyds dry inventory jetpack hit dependency injection framework Getting Started Guide

【大型电商项目开发】性能压测-性能监控-堆内存与垃圾回收-39

增量备份 ?db full

JS implementation determines whether the point is within the polygon range

Phpstrom setting function annotation description

Delaying wages to force people to leave, and the layoffs of small Internet companies are a little too much!
随机推荐
[Chongqing Guangdong education] National Open University spring 2019 1042 international economic law reference questions
Redis' hyperloglog as a powerful tool for active user statistics
Interesting practice of robot programming 16 synchronous positioning and map building (SLAM)
【LeetCode】88. Merge two ordered arrays
微信小程序:星宿UI V1.5 wordpress系统资讯资源博客下载小程序微信QQ双端源码支持wordpress二级分类 加载动画优化
Database postragesq BSD authentication
Pytorch common code snippet collection
Blue Bridge Cup Square filling (DFS backtracking)
整理混乱的头文件,我用include what you use
Database postragesq role membership
Are you still writing the TS type code
Exploration and practice of integration of streaming and wholesale in jd.com
Delaying wages to force people to leave, and the layoffs of small Internet companies are a little too much!
Database postragesq peer authentication
PHP 基础篇 - PHP 中 DES 加解密详解
[wave modeling 2] three dimensional wave modeling and wave generator modeling matlab simulation
Yyds dry goods inventory kubernetes management business configuration methods? (08)
[OpenGL learning notes 8] texture
Application and Optimization Practice of redis in vivo push platform
Lsblk command - check the disk of the system. I don't often use this command, but it's still very easy to use. Onion duck, like, collect, pay attention, wait for your arrival!