Codeforces Round #676 (Div. 2) XORwice、Putting Bricks in the Wall、Palindromifier
题目链接:XORwice
题意:给你两个数a、b。求一个数x,使得((a异或x)+(b异或x))这个值最小,输出最小那个x
题解:
输出(a|b)-(a&b)就行(猜了一手
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#define mem(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int main()
{
int t;
scanf("%d",&t);;
while(t--)
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",(a|b)-(a&b));
}
return 0;
}
题目链接:Putting Bricks in the Wall
题意:给你一个n*n的方形,每一个小格子有一个值(除了(1,1)和(n,n))。你从一个位置只能移动到与它相邻一条边的其他位置(也就是上下左右移动)
它需要从起点(1,1)移动到终点(n,n),你要保证这条路径上所经历过的所有格子的值都一样(除了(1,1)和(n,n))
现在你可以反转最多两个格子的值(也就是把一个格子的值从0变1,或从1变0),使得找不到一条满足条件从起点(1,1)到终点(n,n)的路径
然后输出你需要反转的格子的坐标
题解:
只需要让(1,1)位置周围两个点 和(n,n)周围两个点的值变成相反的就可以了
就比如让(1,2)和(2,1)位置的值变成1,让 (n-1,n)和(n,n-1)位置的点变成0
代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#define mem(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const int maxn=1e3+10;
const int INF=0x3f3f3f3f;
char s[maxn][maxn];
int main()
{
int t;
scanf("%d",&t);;
while(t--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i)
{
scanf("%s",s[i]+1);
}
int one_st=0,zero_st=0,one_la=0,zero_la=0,one_st2=0,zero_st2=0,one_la2=0,zero_la2=0;
if(s[1][2]=='1')
one_st++;
else zero_st++;
if(s[2][1]=='1')
one_st2++;
else zero_st2++; if(s[n][n-1]=='1')
one_la++;
else zero_la++;
if(s[n-1][n]=='1')
one_la2++;
else zero_la2++;
int res=INF;
res=min(res,one_st2+one_st+zero_la+zero_la2);
int temp=res,flag=0;
res=min(res,zero_st2+zero_st+one_la2+one_la);
if(temp==res) flag=1;
printf("%d\n",res);
if(flag)
{
if(s[2][1]=='1')
printf("2 1\n");
if(s[1][2]=='1')
printf("1 2\n");
if(s[n][n-1]=='0')
printf("%d %d\n",n,n-1);
if(s[n-1][n]=='0')
printf("%d %d\n",n-1,n);
}
else
{
if(s[2][1]=='0')
printf("2 1\n");
if(s[1][2]=='0')
printf("1 2\n");
if(s[n][n-1]=='1')
printf("%d %d\n",n,n-1);
if(s[n-1][n]=='1')
printf("%d %d\n",n-1,n);
}
}
return 0;
}
题目链接:Palindromifier
题意:
给你一个字符串s(下标从1开始,长度为n),你有两种操作,你最多使用30次操作,你要保证经过操作之后的字符串是一个回文字符串,且这个回文字符串的长度不超过1e6
操作一、从区间[2,n-1]这个区间内挑一个x,然后把下标区间为[2,x]这一个子串倒过来(也就是abc变成cba)之后追加到原串的头部
操作二、从区间[2,n-1]这个区间内挑一个x,然后把下标区间为[x,n-1]这一个子串倒过来(也就是abc变成cba)之后追加到原串的尾部
题解:
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#define mem(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int INF=0x3f3f3f3f;
char s[maxn];
int main()
{
scanf("%s", s);
int l = strlen(s);
printf("3\n");
printf("R %d\n", l - 1);
printf("L %d\n", l);
printf("L 2\n");
return 0;
}
Codeforces Round #676 (Div. 2) XORwice、Putting Bricks in the Wall、Palindromifier的更多相关文章
- Codeforces Round #676 (Div. 2)【ABCD】
比赛链接:https://codeforces.com/contest/1421 A. XORwice 题意 给出两个正整数 \(a.b\),计算 \((a \oplus x) + (b \oplus ...
- Codeforces Round #676 (Div. 2) A - D个人题解(E题待补)
1421A. XORwice 题目链接:Click Here // Author : RioTian // Time : 20/10/18 #include <bits/stdc++.h> ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers (数位dp、状态压缩)
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- Codeforces Round #443 (Div. 2) 【A、B、C、D】
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #437 (Div. 2)[A、B、C、E]
Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...
- Codeforces Round #434 (Div. 2)【A、B、C、D】
Codeforces Round #434 (Div. 2) codeforces 858A. k-rounding[水] 题意:已知n和k,求n的最小倍数x,要求x后缀至少有k个0. 题解:答案就是 ...
- Codeforces Round #298 (Div. 2) A、B、C题
题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...
- Codeforces Round #440 (Div. 2)【A、B、C、E】
Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...
随机推荐
- 最新最简洁Spring Cloud Oauth2.0 Jwt 的Security方式
因为Spring Cloud 2020.0.0和Spring Boot2.4.1版本升级比较大,所以把我接入过程中的一些需要注意的地方告诉大家 我使用的版本是Spring boot 2.4.1+Spr ...
- vue中选中弹出框内的表格
一:可多选情况且对应勾选 由于是弹出框形式,所以会出现新增DOM与数据的改变问题,因此要使用$nextTick,不然一开始弹出得时候DOM还没有生成,却要获取DOM会报错:这种多选情况会出现一个bug ...
- 安装weblogic 11g
参考 https://blog.csdn.net/z69183787/article/details/38401013 https://blog.csdn.net/wjf8882300/article ...
- Python 日志打印之logging.getLogger源码分析
日志打印之logging.getLogger源码分析 By:授客 QQ:1033553122 #实践环境 WIN 10 Python 3.6.5 #函数说明 logging.getLogger(nam ...
- Kafka底层原理剖析(近万字建议收藏)
Kafka 简介 Apache Kafka 是一个分布式发布-订阅消息系统.是大数据领域消息队列中唯一的王者.最初由 linkedin 公司使用 scala 语言开发,在2010年贡献给了Apache ...
- 【Linux】rsync错误解析
rsync: Failed to exec ssh: No such file or directory (2) rsync error: error in IPC code (code 14) at ...
- oracle rac与单实例DG切换
1.主库查看状态(RAC库) SQL> select database_role,switchover_status from v$database; DATABASE_ROLE SWITCHO ...
- 浅入深出了解XXE漏洞
环境搭建 https://github.com/c0ny1/xxe-lab 为了更深入的理解,我准备理论和实际相结合的了解XXE! 浅谈XML 初识XML 一个好的代码基础能帮助你更好理解一类漏洞,所 ...
- 获取html中某些标签的值
一.获取单选按钮radio的值 <!doctype html> <html lang="en"> <head> <meta charset ...
- Mac 禁用动画
# opening and closing windows and popovers defaults write -g NSAutomaticWindowAnimationsEnabled -boo ...