Codeforces Round #242 (Div. 2)C(找规律,异或运算)
一看就是找规律的题。只要熟悉异或的性质,可以秒杀。
为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法。
一些性质如下:
交换律:
结合律:
恒等律:
归零律:
典型应用:交换a和b的值:a=a^b^(b=a);
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
#define INF 1000000000
#define eps 1e-8
#define pii pair<int,int>
#define LL long long int
int n,p;
int ans=;
int x[];
int main()
{
//freopen("in7.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&n);
x[]=;
for(int i=; i<=n; i++)
{
x[i]=x[i-]^(i-);
int t=n/i;
if(t%==) ans^=x[i];
ans^=x[n%i+];
}
for(int i=; i<n; i++)
{
scanf("%d",&p);
ans^=p;
}
printf("%d\n",ans);
//fclose(stdin);
//fclose(stdout);
return ;
}
Codeforces Round #242 (Div. 2)C(找规律,异或运算)的更多相关文章
- Codeforces Round #242 (Div. 2) C题
题目链接:http://codeforces.com/contest/424/problem/C, 想来一个小时,就是做不出,都做出来了,悲剧! 分析:我们知道交换异或的顺序不影响答案! 然后就是求t ...
- Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)
题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1. 交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ ...
- Codeforces Round #242 (Div. 2) A~C
题目链接 A. Squats time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputou ...
- Codeforces Round #290 (Div. 2) _B找矩形环的三种写法
http://codeforces.com/contest/510/status/B 题目大意 给一个n*m 找有没有相同字母连起来的矩形串 第一种并查集 瞎搞一下 第一次的时候把val开成字符串了 ...
- Codeforces Round #242 (Div. 2) C. Magic Formulas
解题思路是: Q=q1^q2.......^qn = p1^p2......^pn^((1%1)^....(1%n))^((2%1)^......(2%n))^.... 故Q的求解过程分成两部分 第一 ...
- Codeforces Round #242 (Div. 2) A. Squats
注意题目一次只能改变一个松鼠,Pasha can make some hamster ether sit down or stand up.是单数不是复数 #include <iostream& ...
- Codeforces Round #242 (Div. 2) B. Megacity
按照半径排序,然后累加人数直到超过百万 #include <iostream> #include <algorithm> #include <cmath> #inc ...
- Codeforces Round #242 (Div. 2) <A-D>
CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...
- Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...
随机推荐
- Spring Boot之AOP面向切面编程-实战篇
目录 前言 编程范式主要有以下几类 引入pom依赖 aop注解 实现日志分割功能 前言 AOP是一种与语言无关的程序思想.编程范式.项目业务逻辑中,将通用的模块以水平切割的方式进行分离统一处理,常用于 ...
- bootstrap-select 使用笔记 设置选中值及手动刷新
直接笔记: 1.页面刚加载完填充select选项数据时,需要手动刷新一下组件,否则没有选项值.(组件初始化时,li 与 option 分离的,需要刷新一下(据说)) $.post('/cpms/tod ...
- hibernate 操作 Postgresql 数据库报 operator does not exist: integer = character varying
网上的说法如下: Java开发Postgresql 数据库兼容应用的问题,与Oracle有一些不同: Java类型映射数据库类型的不同,Oracle jdbc驱动程序处理Java String类型可正 ...
- jQuery:自学笔记(2)——jQuery选择器
jQuery:自学笔记(2)——jQuery选择器 基本选择器 说明 jQuery的基本选择器与CSS的选择器相似: 实例 标签选择器 //使用标签选择器更改字体大小 $(div).css('font ...
- Harbor私有仓库搭建
1.安装docker yum install -y dockersystemctl start dockersystemctl enable docker 2.安装docker-compose 1.下 ...
- Python基础知识补充(重要)-作用域、特殊语法
Python作用域 python代码内部块如if语句内声明变量,在if代码段后在调用此变量并未报如“undefinded name"此类错误,例子如下: if 1 == 1: name = ...
- C#无边框窗体移动的三种方法
1. 重写WndProc protected override void WndProc(ref Message m) { const int WM_NCHITTEST = 0x84; const i ...
- 关于dispatch_semaphore的使用
dispatch_semaphore是GCD用来同步的一种方式,与他相关的共有三个函数,分别是 dispatch_semaphore_create,dispatch_semaphore_signal, ...
- 【Tech】mac下svn和scp使用笔记
1.命令行从svn下载代码 mac本身自带svn,所以使用非常简单,在本地创建代码存放的文件夹,然后cd到该文件夹下,运行: svn checkout svn://ip地址/文件路径 . 然后出现要求 ...
- yuv转opencv中的IplImage
http://www.2cto.com/kf/201208/145559.html http://www.opencv.org.cn/forum.php?mod=viewthread&tid= ...