Codeforces Round #770 (Div. 2) ABC

Problem - A - Codeforces

题目大意:给定一个长度为n的字符串s,变换次数为k。问k次操作过后能得到多少不同的字符串?

操作规则:1. s→s+reverse(s)   or   2.  s→reverse(s)+ s (任选一种变换)

input

4
3 2
aab
3 3
aab
7 1
abacaba
2 0
ab

output

2
2
1
1

当字符串为回文时,两种变换中最终都是同一种,所以只需要判断s是否为回文字符串即可确定未来变换的趋势。 非回文在一次操作之后也会变成回文,所以就比回文多一步。

特判k==0时他还存在于原字符串一种形式中

#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;
}

Problem - B - Codeforces

题目大意:一开始Alice从x开始操作,Bob从x+3开始操作,然后有一个长度为n的序列a,从前往后遍历这个序列,每次Alice和Bob他们必须对自己的数字做以下变换:

1.d→d+ai; 2.d→d xor ai(二选一)。

问最后所有操作完成后,谁能够恰好得到y,并输出(题目保证有且只有一个人能得到y)。

input

4
1 7 9
2
2 0 2
1 3
4 0 1
1 2 3 4
2 1000000000 3000000000
1000000000 1000000000

output

Alice
Alice
Bob
Alice

通过x与x+3可以得知两人的奇偶性不同,每次对奇数经行一次异或操作都会更改其奇偶性,所以我们可以先假设alice所持为奇数,并与数组a进行异或运算,如果Alice在和整个数组异或完毕之后和y的奇偶性相同,那么就输出Alice ,否则输出Bob。

异或 ^ :110  000  101  010

按位与 & :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;
}

Problem - C - Codeforces

题目大意:n行m列,问能否把1~n*m都装进这个矩阵中并且任意一行的任意一串数字拿出来,他们的平均数都必须是整数。

input

4
1 1
2 2
3 3
3 1

output

YES
1 
YES
1 3 
2 4 
NO
YES
1 
2 
3 

可以直接简化到两个数字来思考,/2要为整,那必须是同奇偶,延伸至长串数字来看也必须是奇偶相同才能得整。那么控制奇偶分家就成了。

#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;//如果是奇数行必有一行会出奇偶共存的现象
        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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vijurria

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值