Codeforces Global Round 10

Codeforces Global Round 10

A. Omkar and Password

题意: 给你一个序列,现在这个序列中可以将相邻的不同的元素相加,可以重复若干次,问最后的会剩下几个元素。
题解: 仔细分析可知,不是1就是n,全都一样是n,否则为1
代码:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
int const N = 2e5 + 10;
LL t, n, a[N];

int main() {
    cin >> t;
    while (t--) {
        cin >> n;
        int flg = 1;
        for (int i = 1; i <= n; ++i) {
            scanf("%lld", &a[i]);
            if (i >= 2 && a[i] != a[i - 1]) flg = 0; 
        }
        if (flg) cout << n << endl;
        else cout << 1 << endl;
        
        
    }
    return 0;
}

B. Omkar and Infinity Clock

题意: 给你一个n,k和一个a序列,你可以进行操作,计算出a中的最大值d,然后ai=d−ai
,进行k次这样的操作,求出最后的a序列。
题解: 动手画画即可知道,这样的序列是交替的,按照k的奇偶性判断即可
代码:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
int const N = 2e5 + 10, INF = -1e9 - 10;
LL t, n, k, a[N];

int main() {
    cin >> t;
    while (t--) {
        cin >> n >> k;
        LL maxv = INF;
        for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), maxv = max(maxv, a[i]);
        if (n == 1) {
            cout << 0 << endl;
            continue;
        }
        if (k & 1) {
            for (int i = 1; i <= n; ++i) printf("%lld ", maxv - a[i]);
            printf("\n");
            continue;
        }
        else {
            LL maxv1 = INF;
            for (int i = 1; i <= n; ++i) {
                a[i] = maxv - a[i];
                // cout << a[i] << " " ;
                maxv1 = max(maxv1, a[i]);
            
            }
            // cout << endl;
            for (int i = 1; i <= n; ++i) printf("%lld ", maxv1 - a[i]);
            printf("\n");
        }
        
    }
    return 0;
}

C. Omkar and Waterslide

题意: 给你一个序列,你有个操作,可以将连续不递减的区间里面的值都增加1,问最后要使这个序列变成不递减的序列要进行多少次这样的操作。
题解: 如果出现当前数字比前一个小的情况,只需要变成和前一个一样大即可
代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
int const N = 2e5 + 10;
LL a[N], n, T;

int main() {
    // freopen("in.txt", "r", stdin);
    cin >> T;
    while (T--) {
        cin >> n;
        LL res = 0;
        for (int i = 1; i <= n; ++i) {
            scanf("%lld", &a[i]);
            if (i == 1) continue;
            if (a[i] < a[i - 1]) res += a[i - 1] - a[i];
        }
        cout << res << endl;
    }
    return 0;
}

D. Omkar and Bed Wars

题意: 有一个游戏,把大家围成一个圈,每一个人都可以攻击相邻的人,这样会造成人受到的攻击数为0,1,20,1,2,当只受到一个人的攻击时,此时你需要反击这个人才算合理,如果没有反击的话,你需要进行纠正,问最少需要纠正多少次。
题解: 如果全部一样需要特判。然后计算相同的L、R数目,数目cnt/3累加到答案内。
代码:

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
int const N = 2e5 + 10, INF = 1e9 + 10;
LL t, n, k, a[N], b[N];
string s;


int main() {
    cin >> t;
    while (t--) {
        cin >> n;
        cin >> s;
        int flg1 = 1, flg2 = 1;
        for (int i = 0; i < n; ++i) {
            if (s[i] == 'R') flg1 = 0;
            if (s[i] == 'L') flg2 = 0;
        }
        // cout << flg1 << " " << flg2 << endl;
        if (flg1 || flg2) {
            // cout << "here" << endl;
            // cout << ceil(n / 3) << endl;
            printf("%d\n", (n + 2) / 3);
            
            continue;
        }
        LL res = 0;
        string ss = s;
        if (ss[0] == ss[n - 1]) {
            int l = 1;
            while (ss[l] == ss[l - 1] && l < n) {
                l++;
            }
            int r = n - 2;
            while (ss[r] == ss[r + 1] && r >= 0) r--;
            res += (l + n - r - 1) / 3;
            // cout << l << " " << r << endl;
            // cout << res << endl;
            int len = 1;
            for (int i = l + 1; i <= r; ++i) {
                if (ss[i] == ss[i - 1]) {
                    len ++;
                }
                else {
                    // cout << i << " " << len << endl;
                    res += (len / 3);
                    len = 1;
                }
            }
            res += (len / 3);
            cout << res << endl;
        }
        else {
            int len = 1;
            int l = 0, r = n - 1;
            for (int i = l + 1; i <= r; ++i) {
                if (ss[i] == ss[i - 1]) {
                    len ++;
                }
                else {
                    // cout << i << " " << len / 3 << endl;
                    res += (len / 3);
                    len = 1;
                }
            }
            res += (len / 3);
            cout << res << endl;
        }
        // cout << res << endl;
    }
    return 0;
}

E. Omkar and Duck

题意: 要求构造一个矩阵,而后每次给定一个路径长度,要求输出一个从左上角走到右下角的路径
题解:
构造的矩阵如下:
0 1 0 4
0 2 0 8
0 4 0 16
0 8 0 32
这样对于路径长度path,观察其二进制,如果当前位为0,那么向0的方向走,否则向非0的方向走
代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
int const N = 30;
LL a[N][N], n, m, path;

int main() {
	// freopen("in.txt", "r", stdin);
	cin >> n;
	for (int j = 0; j < n; ++j) {
		for (int i = 0; i < n; ++i) {
			if (j & 1) {
				if (j / 2 == 0) a[i][j] = (1 << i);
				else a[i][j] = (1 << i) * pow(4, (j / 2)) ;
			}
			else a[i][j] = 0;
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) cout << a[i][j] << " ";
		cout << endl;
	}
	fflush(stdout);
	cin >> m;
	while (m--) {
		cin >> path;
		int x = 0, y = 0;
		cout << x + 1 << " " << y + 1 << endl;
		// 111001
		for (int i = 0; i < (n - 1) * 2; ++i) {
			if (path >> i & 1) {
				if (a[x][y] == 0) y++;
				else x++;
			}
			else {
				if (a[x][y] == 0) x++;
				else y++;
			}
			cout << x + 1 << " " << y + 1 << endl;
		}
		// cout << n << " " << n << endl << endl;
		fflush(stdout);
	}
	return 0;
}

参考

  1. https://blog.csdn.net/weixin_45031646/article/details/108053519?biz_id=102&utm_term=Codeforces%20Global%20Round%2010&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-0-108053519&spm=1018.2118.3001.4187
  2. https://wangmeng.blog.csdn.net/article/details/108055730
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值