Codeforces Round #242 (Div. 2)C(找规律,异或运算)
2024-10-19 12:35:01
一看就是找规律的题。只要熟悉异或的性质,可以秒杀。
为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法。
一些性质如下:
交换律:
结合律:
恒等律:
归零律:
典型应用:交换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 ;
}
最新文章
- 元素的click与dblclick
- NIO源码阅读
- Linux常用命令02
- MySQL Profiling 的使用
- 【转】Android M新控件之AppBarLayout,NavigationView,CoordinatorLayout,CollapsingToolbarLayout的使用
- C#_自动化测试1_模拟post,get_12306火车票网站自动登录工具
- [OM]Dropship SO(直发/直运订单)的流程
- WebAPI通过multipart/form-data方式同时上传文件以及数据(含HttpClient上传Demo)
- [ios] NSURL
- es6笔记7^_^class
- 如何使用华为软件开发云快速部署PHP网站
- 关于 IIS 的 Management Service Delegation 配置 备份
- linux 常用命令 和 nginx(反响代理、负载均衡)安装和配置
- Codeforces Round #454 Div. 1
- C#批量删除注释与空行
- Html dom 赋值
- Ubuntu_安装Wiz笔记
- exception ORA-00918: 未明确定义列
- Android Bigmap的操作(绘制,裁剪)
- Bootstrap学习笔记(排版)