Codeforces Round #676 (Div. 2) A - D个人题解(E题待补)

这篇博客主要提供了Codeforces Round #676 (Div. 2) 中A-D题目的解题思路,包括XORwice、Putting Bricks in the Wall、Palindromifier和Hexagons(D题为补题)。作者通过分享C++和Python代码,阐述了如何解决这些问题。在XORwice问题中,重点在于利用XOR操作找到最优解;Putting Bricks in the Wall中,讨论了如何通过改变相邻格子状态以达到目标;Palindromifier是一个构造题,需要找到构造回文字符串的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1421A. XORwice

题目链接:Click Here

cpp

// Author : RioTian
// Time : 20/10/18
#include <bits/stdc++.h>
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long ll;
ll n, m, _;
void solve() {
    cin >> n >> m;
    cout << (n ^ m) << endl;
}
int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> _;
    while (_--) solve();
}
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

1421B. Putting Bricks in the Wall

题目链接:Click Here

如果选择S的邻居为1,我们就可以F使为0的邻居,就没有办法从S到F,但这在最坏的情况下需要4个开关,这是不够的。 幸运的是,为了减少到2个开关,只需反过来考虑,使相邻S的正方形变为0,使相邻的正方形变为F 1。必须存在最多具有两个开关的两个正方形的解,并且您不会从S到F,因为被迫选择1(或0),并且无法通过与F相反的邻居。

cpp

// Author : RioTian
// Time : 20/10/18
#include <bits/stdc++.h>
#define ms(a, b) memset(a, b, sizeof a)
using namespace std;
typedef long long ll;
ll n, m, _;
char x[210][210];
void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> x[i] + 1;
    int a = x[1][2] - '0', b = x[2][1] - '0', c = x[n][n - 1] - '0',
        d = x[n - 1][n] - '0';
    if (a == b && c == d && a != c)
        cout << 0 << endl;
    else if (a != b && c != d)
        cout << 2 << endl
             << 1 << " " << 2 << endl
             << (a == c ? n - 1 : n) << " " << (a == c ? n : n - 1) << endl;
    else if (a != b)
        cout << 1 << endl
             << (a == c ? 1 : 2) << ' ' << (a == c ? 2 : 1) << endl;
    else if (c != d)
        cout << 1 << endl
             << (a == c ? n : n - 1) << ' ' << (a == c ? n - 1 : n) << endl;
    else
        cout << 2 << endl << 1 << ' ' << 2 << endl << 2 << " " << 1 << endl;
}
int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> _;
    while (_--) solve();
}
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

python

#python
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))

t,=I()
for _ in range(t):
	n,=I()
	l=[input().strip() for i in range(n)]
	an=[]
	le=[0,0,1,1,1];p=[1,1,0,0,0]
	rq=[l[0][1],l[1][0],l[1][1],l[2][0],l[0][2]]
	pos=[[1,2],[2,1],[2,2],[3,1],[1,3]]
	ct=cp=0;a1=[]
	for i in range(5):
		if le[i]!=int(rq[i]):
			ct+=1
			a1.append(pos[i])
	for i in range(5):
		if p[i]!=int(rq[i]):
			cp+=1
			an.append(pos[i])
	if ct<=cp:
		an=a1
	print(len(an))
	for i in an:
		print(*i)
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

1421C. Palindromifier

题目链接:Click Here

这道题写的挺懵的,一开始都没理解题意

被dalao提醒以后然后发现是构造题,根据题目说的两种方案:

对于任何字符串都可以先 $L ,i = 2 ,然后,然后R,i = 2 $ + R,i=7R,i=7。一定能构造需所需的字符串

cpp

// Author : RioTian
// Time : 20/10/18
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int main() {
    // freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> s;
    cout << "3\nL 2\nR 2\n";
    cout << "R " << 2 * s.size() - 1 << endl;
}
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

python

print('3\nL 2\nR 2\nR',len(input())*2-1)
  •  

1421D. Hexagons (补)

题目链接:Click Here

cpp

// Author : RioTian
// Time : 20/10/18
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int inf = 1e9 + 7;
ll x, y, c1, c2, c3, c4, c5, c6;
ll check(ll ad) {
    ll ans = 0;
    if (ad > 0)
        ans += ad * c1;
    else
        ans += -ad * c4;
    if (x - ad > 0)
        ans += (x - ad) * c6;
    else
        ans += (ad - x) * c3;
    if (y - ad > 0)
        ans += (y - ad) * c2;
    else
        ans += (ad - y) * c5;
    return ans;
}
void solve() {
    cin >> x >> y >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
    ll l = -inf, r = inf;
    while (l < r) {
        ll mid = l + r >> 1;
        if (check(mid) < check(mid + 1))
            r = mid;
        else
            l = mid + 1;
    }
    cout << min({check(l), check(l + 1), check(l - 1)}) << '\n';
}
int main() {
    int t;
    cin >> t;
    while (t--) solve();
}
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

1421E. Swedish Heroes (补)

题目链接:Click Here

 

鞋子
美容
母婴
箱包
53货源网
特产
货源关键词大全
学院
女鞋
情侣装
内衣
男鞋
女鞋
童鞋

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值