Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)
比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了。。。。
还是先总结一下位移或的性质吧:
1、 交换律 a ^ b = b ^ a
2、 结合律 (a^b) ^ c = a ^ (b^c)
3、 0^a = a;
4、 a^a = 0; a^a^a = a;
5、 知道a,b,c中任意两个就能推知第三个.
a^b = c 两边同时与a异或得: a ^ (a^b) = a^c 即 0^b = a^c 亦即 b = a^c
四个也是一样 若d = a ^ b ^ c 则a = d ^ b ^ c
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
const int maxn = +; __int64 p, ans, a[maxn];
void init()
{
int i;
a[] = ;
for(i = ; i < maxn; i++)
a[i] = (a[i-]^i);
}
int main()
{
int n, i, x;
while(cin>>n)
{
init();
ans = ;
for(i = ; i <= n; i++)
{
cin>>p;
ans ^= p;
}
for(i = ; i <= n; i++)
{
if(n%(*i) != )
{
x = n%(*i);
if(x >= i)
{
ans ^= a[i-];
x -= i;
}
ans ^= a[x]; //把a[x]写成了x结果调试了一晚上
}
}
cout<<ans<<endl;
}
return ;
}
Codeforces Round #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)的更多相关文章
- 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 #260 (Div. 2) A , B , C 标记,找规律 , dp
A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #493 (Div. 1) B. Roman Digits 打表找规律
题意: 我们在研究罗马数字.罗马数字只有4个字符,I,V,X,L分别代表1,5,10,100.一个罗马数字的值为该数字包含的字符代表数字的和,而与字符的顺序无关.例如XXXV=35,IXI=12. 现 ...
- Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
- Codeforces Round #242 (Div. 2) A~C
题目链接 A. Squats time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputou ...
- Codeforces Round #242 (Div. 2) <A-D>
CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...
- Codeforces Round #242 (Div. 2) C题
题目链接:http://codeforces.com/contest/424/problem/C, 想来一个小时,就是做不出,都做出来了,悲剧! 分析:我们知道交换异或的顺序不影响答案! 然后就是求t ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...
- Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算
D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...
随机推荐
- ASP.NET Web - 服务器控件
控件 HTML 说明 Label <span> 返回一个包含文本的span元素 Literal static text 返回简单的静态文本.使用Literal控件,可以根据客户应用程序转换 ...
- netbeans设置字体
选择 monospaced 字体 摘抄自:http://blog.sina.com.cn/s/blog_4b6047bc01000boz.html 今天看该文档时,突然意识到通过修改JRE的字体配置文 ...
- For和While在C和MATLAB中的区别——MATLAB的大坑
For和while是常见的循环关键字,在许多语言中都是通用的.但是想必不是所有人,都被其中的区别困扰过,尤其是MATLAB“程序员”. x=[,,,,,,]; i=; while i<=leng ...
- PHP之set_error_handler()函数讲解
定义和用法 set_error_handler() 函数设置用户自定义的错误处理函数. 该函数用于创建运行时期间的用户自己的错误处理方法. 该函数会返回旧的错误处理程序,若失败,则返回 null. 语 ...
- Unity3D 优化相关
抛砖引玉: http://www.luzexi.com/unity3d%E4%BC%98%E5%8C%96%E4%B9%8B%E8%B7%AF/ 关于图片 一.Unity3D自身会把导入的图片进行压缩 ...
- Linux下SVN的一些使用方法总结
Linux下SVN的一些使用方法总结 近期的一个项目不方便 Check 到本地,需要在测试服务器上进行编写和测试,所以就研究了一下如何在 Linux 命令行下使用 SVN. 首先 svn help ...
- POJ 3286 How many 0's?
题目链接 题意 :写下m到n之间所有的数,会写多少个0. 思路 :先算0到m的,再算0到n的,最后相减. 网上有位大神是这么推的,看下面.... 首先转化成求 [0, x] 中所有数中,含有的 0 的 ...
- POJ1328Radar Installation
http://poj.org/problem?id=1328 题的大意就是说在海里有小岛,坐标位置会给出,需要岸边的雷达覆盖所有的小岛,但雷达的覆盖范围有限,所以,需要最少的雷达覆盖所有的小岛,但若是 ...
- Test Markdown Editor
Last night, I just saw a cute blogger's homepage. Then I want to write something. But anyway, I use ...
- Android 近百个项目的源代码
Android 近百个项目的源代码 Android PDF 阅读器 http://sourceforge.net/projects/andpdf/files/个人记账工具 OnMyMeans http ...