题目链接: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的更多相关文章

  1. Codeforces Round #676 (Div. 2)【ABCD】

    比赛链接:https://codeforces.com/contest/1421 A. XORwice 题意 给出两个正整数 \(a.b\),计算 \((a \oplus x) + (b \oplus ...

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

    1421A. XORwice 题目链接:Click Here // Author : RioTian // Time : 20/10/18 #include <bits/stdc++.h> ...

  3. 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 ...

  4. Codeforces Round #443 (Div. 2) 【A、B、C、D】

    Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...

  5. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  6. Codeforces Round #437 (Div. 2)[A、B、C、E]

    Codeforces Round #437 (Div. 2) codeforces 867 A. Between the Offices(水) 题意:已知白天所在地(晚上可能坐飞机飞往异地),问是否从 ...

  7. 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. 题解:答案就是 ...

  8. 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 ...

  9. Codeforces Round #440 (Div. 2)【A、B、C、E】

    Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...

随机推荐

  1. ASP.NET Core - JWT认证实现

    一.JWT结构 JWT介绍就太多了,这里主要关注下Jwt的结构. Jwt中包含三个部分:Header(头部).Payload(负载).Signature(签名) Header:描述 JWT 的元数据的 ...

  2. DHCP最佳实践(二)

    这是Windows DHCP最佳实践和技巧的最终指南. 如果您有任何最佳做法或技巧,请在下面的评论中发布它们. 在本指南(二)中,我将分享以下DHCP最佳实践和技巧. 从DHCP作用域中排除IP 了解 ...

  3. myisam崩溃后发生损坏的概率比innodb高的原因

    myisam崩溃后发生损坏的概率比innodb高的原因

  4. CTFHub - Web(一)

    请求方法: 1.进入页面,提示:HTTP 请求方法, HTTP/1.1协议中共定义了八种方法(也叫动作)来以不同方式操作指定的资源. 2.当前http的请求方式是get请求,当你使用CTFHUB为请求 ...

  5. 代码页(CodePage)列表

    代码页编号    国家地区或语言37                 IBM037    IBM EBCDIC (US-Canada)    437                 IBM437    ...

  6. 在nodejs中创建child process

    目录 简介 child process 异步创建进程 同步创建进程 在nodejs中创建child process 简介 nodejs的main event loop是单线程的,nodejs本身也维护 ...

  7. JavaFx ObservableList的使用详解

    原文地址:JavaFx ObservableList的使用详解 | Stars-One的杂货小窝 最近在研究MVVM模式,发现可以将之前写的FxRecyclerView控件改造一下,便是开始尝试,尝试 ...

  8. ThinkPHP3.2.4 order方法注入

    漏洞详情: 漏洞文件:./ThinkPHP\Library\Think\Db\Driver.class.php 中的 parseOrder方法: 这也是继上次order方法注入之后的修复手段. 可以看 ...

  9. 【译】Async/Await(四)—— Pinning

    原文标题:Async/Await 原文链接:https://os.phil-opp.com/async-await/#multitasking 公众号: Rust 碎碎念 翻译 by: Praying ...

  10. Java——数据类型

    数据类型分类 基本数据类型: 数值型: 整数类型(byte,short,int,long): 浮点类型(float,double): 字符型(char): 布尔值(boolean): 引用数据类型: ...