题目链接: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. 【C++】《C++ Primer 》第十八章

    第十八章 用于大型程序的工具 大规模应用程序的特殊要求包括: 在独立开发的子系统之间协同处理错误的能力. 使用各种库进行协同开发的能力. 对比较复杂的应用概念建模的能力. 一.异常处理 异常处理(ex ...

  2. mmall商城分类模块总结

    后台分类model的开发具体功能有:添加分类名称,修改分类名称,查询所有子分类,查询父分类以及它下面的子分类(递归) 需要注意的是,在后台管理进行操作的时候,都需要验证当前用户是否是管理员的角色,不管 ...

  3. 【高级排序算法】2、归并排序法的实现-Merge Sort

    简单记录 - bobo老师的玩转算法系列–玩转算法 -高级排序算法 Merge Sort 归并排序 Java实现归并排序 SortTestHelper 排序测试辅助类 package algo; im ...

  4. 使用CDN访问免备案网站

    如何使用CDN绕过服务器域名备案 前言 不得不说,大陆需要备案,时间真的有点长,至少得5天~20天起步,对于我们这些火急火燎的站长还是比较难受的.这里教大家如何使用cdn绕过备案, 访问速度很快,亲测 ...

  5. Java高并发与多线程(三)-----线程的基本属性和主要方法

    今天,我们开始Java高并发与多线程的第三篇,线程的基本属性和主要方法. [属性] 编号(ID) 类型long 用于标识不同的线程,编号唯一,只存在java虚拟机的一次运行 名称(Name) 类型St ...

  6. 【老孟Flutter】如何提高Flutter应用程序的性能

    首先 Flutter 是一个非常高性能的框架,因此大多时候不需要开发者做出特殊的处理,只需要避免常见的性能问题即可获得高性能的应用程序. 重建最小化原则 在调用 setState() 方法重建组件时, ...

  7. 入门OJ:最短路径树入门

    题目描述 n个城市用m条双向公路连接,使得任意两个城市都能直接或间接地连通.其中城市编号为1..n,公路编号为1..m.任意个两个城市间的货物运输会选择最短路径,把这n*(n-1)条最短路径的和记为S ...

  8. 低功耗降线性稳压器,24V转5V降压芯片

    PW2330开发了一种高效率的同步降压DC-DC变换器3A输出电流.PW2330在4.5V到30V的宽输入电压范围内工作集成主开关和同步开关,具有非常低的RDS(ON)以最小化传导 损失.PW2330 ...

  9. JavaScript学习总结(基础知识)

    js代码引入 方式1: <script> alert('欢迎来到德玛西亚!') </script> 方式2:外部文件引入 src属性值为js文件路径 <script sr ...

  10. Flask源码流程分析(一)

    Flask源码流程分析: 1.项目启动: 1.实例化Flask对象 1. 重要的加载项: * url_rule_class = Rule * url_map_class = Map * session ...