题目

比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了。。。。

还是先总结一下位移或的性质吧:

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 (位异或性质 找规律)的更多相关文章

  1. Codeforces Round #242 (Div. 2) C. Magic Formulas

    解题思路是: Q=q1^q2.......^qn = p1^p2......^pn^((1%1)^....(1%n))^((2%1)^......(2%n))^.... 故Q的求解过程分成两部分 第一 ...

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

  3. Codeforces Round #493 (Div. 1) B. Roman Digits 打表找规律

    题意: 我们在研究罗马数字.罗马数字只有4个字符,I,V,X,L分别代表1,5,10,100.一个罗马数字的值为该数字包含的字符代表数字的和,而与字符的顺序无关.例如XXXV=35,IXI=12. 现 ...

  4. Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点

    // Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...

  5. Codeforces Round #242 (Div. 2) A~C

    题目链接 A. Squats time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputou ...

  6. Codeforces Round #242 (Div. 2) &lt;A-D&gt;

    CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...

  7. Codeforces Round #242 (Div. 2) C题

    题目链接:http://codeforces.com/contest/424/problem/C, 想来一个小时,就是做不出,都做出来了,悲剧! 分析:我们知道交换异或的顺序不影响答案! 然后就是求t ...

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

  9. Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算

    D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...

随机推荐

  1. 笔记本电脑连接wifi有时候会自动断网提示有限的访问权限解决办法

    解决办法如下: [设备管理器],找到[网络适配器]第一项,右键属性

  2. C#: Create a WebRequest with HTTPClient

    http://www.cnblogs.com/shanyou/archive/2012/03/21/2410739.html http://msdn.microsoft.com/zh-cn/libra ...

  3. 【BZOJ】【2588】COT(Count On a Tree)

    可持久化线段树 maya……树么……转化成序列……所以就写了个树链剖分……然后每个点保存的是从它到根的可持久化线段树. 然后就像序列一样查询……注意是多个左端点和多个右端点,处理方法类似BZOJ 19 ...

  4. 【BZOJ】【3143】【HNOI2013】游走

    数学期望/高斯消元/贪心 啊……用贪心的思路明显是要把经过次数期望越大的边的权值定的越小,那么接下来的任务就是求每条边的期望经过次数. 拆边为点?nonono,连接x,y两点的边的期望经过次数明显是 ...

  5. soft particles

    http://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf nvdia ------------- ...

  6. spring <context:component-scan>(转)

    在xml配置了这个标签后,spring可以自动去扫描base-pack下面或者子包下面的java文件,如果扫描到有@Component @Controller@Service等这些注解的类,则把这些类 ...

  7. override equals in Java

    equals() (javadoc) must define an equality relation (it must be reflexive, symmetric, and transitive ...

  8. 【leetcode】Majority Element (easy)(*^__^*)

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  9. IE浏览器 下面的文本框,获得焦点后无法输入内容

    今天遇到一个问题,在IE浏览器下面,我点击 按钮  弹出一个弹出层,里面有一个 文本编辑器和一个文本框,但是第二次弹出后,文本框和文本编辑器无法输入内容,在控制台用js代码测试 $(document) ...

  10. Win7 64 安装Visual Studio 2010和SQL Server 2008 R2

    1. 在MSDN,我告诉你下载安装文件,VS 2010 不论32位还是64位都是同一个文件,cn_visual_studio_2010_ultimate_x86_dvd_532347.iso.SQL下 ...