Codeforces Round #676 (Div. 2)

A
A ^ A = A,^a 或 ^b结果最小,都为a ^ b.

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t, a, b;cin >> t;
    while (t--){
        cin >> a >> b;
        cout << (a ^ b) << endl;//直接异或输出加括号
    }
}

B
1.s的四周为0,f的四周为1.
2.s的四周为1,f的四周为0.
哪种满足条件使用哪种.

#include<bits/stdc++.h>
using namespace std;
char a[210][210];
int main()
{
    int t, n, i, j;cin >> t;
    while (t--){
        cin >> n;
        for (i = 1; i <= n; i++)
            cin >> a[i] + 1;
        int cnt1 = 0, cnt2 = 0;
        if (a[1][2] == '1') cnt1++;
        if (a[2][1] == '1') cnt1++;
        if (a[n][n - 1] == '0') cnt1++;
        if (a[n - 1][n] == '0') cnt1++;
        if (a[1][2] == '0') cnt2++;
        if (a[2][1] == '0') cnt2++;
        if (a[n][n - 1] == '1') cnt2++;
        if (a[n - 1][n] == '1') cnt2++;
        if (cnt1 <= 2){
            cout << cnt1 << endl;
            if (a[1][2] == '1') cout << 1 << ' ' << 2 << endl;
            if (a[2][1] == '1') cout << 2 << ' ' << 1 << endl;
            if (a[n][n - 1] == '0') cout << n << ' ' << n - 1 << endl;
            if (a[n - 1][n] == '0') cout << n - 1 << ' ' << n << endl;
        }
        else{
            cout << cnt2 << endl;
            if (a[1][2] == '0') cout << 1 << ' ' << 2 << endl;
            if (a[2][1] == '0') cout << 2 << ' ' << 1 << endl;
            if (a[n][n - 1] == '1') cout << n << ' ' << n - 1 << endl;
            if (a[n - 1][n] == '1') cout << n - 1 << ' ' << n << endl;
        }
    }
}

C
规律题.有一个通用的构造回文串的规律:
R n - 1
L n
L 2

#include<bits/stdc++.h>
using namespace std;
char s[100010];
bool check(char *s)
{
    int i, l = strlen(s);
    for (i = 0; i < l / 2; i++)
        if (s[i] != s[l - i - 1]) return 0;
    return 1;
}
int main()
{
    cin >> s;
    int i, l = strlen(s);
    if (check(s)) cout << 0 << endl;//原串回文输出0
    else{
        cout << 3 << endl;
        cout << 'R' << ' ' << l - 1 << endl;
        cout << 'L' << ' ' << l << endl;
        cout << 'L' << ' ' << 2 << endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值