AtCoder Beginner Contest 197

链接

https://atcoder.jp/contests/abc197

A

题意

给定长度为3的字符串 s s s,按 s [ 1 ] 、 s [ 2 ] 、 s [ 0 ] s[1]、s[2]、s[0] s[1]s[2]s[0]的顺序输出;

code
#include <iostream>
using namespace std;
int n, a[300005];
string s;
int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    cin >> s;
    for (int i = 1; i < s.size(); i++)
        cout << s[i];
    cout << s[0];
}

B

题意

给定一张大小 h × w h\times w h×w的图(包含.#),给顶坐标 ( x , y ) (x,y) (x,y),问从该点出发沿上下左右四个方向走,遇到.的数量,如果遇到#就停止, ( x , y ) (x,y) (x,y)点也计入结果,求总的遇到.的数量

code
#include <iostream>
using namespace std;
int n, a[300005];
char s[104][104];
int d[6][2] = {0, -1, 0, 1, 1, 0, -1, 0, 0, 0};
int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    for (int i = 1; i <= h; i++) 
        cin >> s[i] + 1;
    int ans = 0;
    for (int i = x; i <= h; i++) {
        if (s[i][y] == '.') ans++;
        else
            break;
    }
    for (int i = x ; i > 0; i--) {
        if (s[i][y] == '.') ans++;
        else
            break;
    }
    for (int i = y; i <= w; i++) {
        if (s[x][i] == '.') ans++;
        else
            break;
    }
    for (int i = y; i > 0; i--) {
        if (s[x][i] == '.') ans++;
        else
            break;
    }
    if (s[x][y] == '.')
        cout << ans - 3;
    else
        cout << ans;
}

C

题意

给定长度为 n n n的序列,现在把这个序列划分成一个或多个子区间,计算每个子区间的与运算的结果,将所有子区间的与的结果异或起来,求这个值的最小值;

题解

n n n最大为 20 20 20,那么我们想象,有 n − 1 n-1 n1个隔板,然后枚举所有的隔板的情况,即选或不选,那么就是所有的区间划分的情况,比如情况 i i i的第 j j j位为1,就是说第 j j j位后有个隔板;

code
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;
int n, x, a[200];

int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    cin >> n;
    for (int i = 0; i <= n - 1; i++) 
        cin >> a[i];
    int res = 1 << 30;
    for (int i = 0; i <  1 << (n - 1); i++) {
        int xbor = 0, bor = 0;
        for (int j = 0; j <= n - 1; j++) {
            bor |= a[j];
            if (i >> j & 1) xbor ^= bor, bor = 0;
        }
        xbor ^= bor;
        res = min(res, xbor);
    }
    cout << res << endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值