题目

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

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

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. 【BZOJ 1007】 [HNOI2008]水平可见直线

    Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见的,否则Li为被覆盖的.    例如,对于直线:    ...

  2. WPF 进程间通讯----inter-process communication

    进程间通讯--inter-process communication  进程间相互通讯的方法有很多,如用web services,xml 等互相读取, 网络的可以使用socket 等. 2个WinFo ...

  3. android studio 突然出现Gradle project sync failed 错误

    出现: 之前还是好好的,突然就出现Gradle project sync failed  错误,网上原因可能是工具的问题. 解决办法: 重新打开android studio就好了.不知道大家还有其他的 ...

  4. hadoop历史服务器配置问题

    作者:sdjnzqr 出处:http://www.cnblogs.com/sdjnzqr/ 版权:本文版权归作者和博客园共有 转载:欢迎转载,但未经作者同意,必须保留此段声明:必须在文章中给出原文连接 ...

  5. Flex 教程(1)-------------控件拖动

    今天和大家分享下关于在Flex中 针对控件的拖动开发. 1.需要在 .mxml文件中编写一个Button按钮 如下代码: <s:Button id="button1" lab ...

  6. hibernate4.0中SessionFactory的创建

    创建SessionFactory 首先创建Configuration对象,主要方式是: new Configuration().configure() 默认情况下Hibernate会去classPat ...

  7. 字符串匹配--kmp算法原理整理

    kmp算法原理:求出P0···Pi的最大相同前后缀长度k: 字符串匹配是计算机的基本任务之一.举例,字符串"BBC ABCDAB ABCDABCDABDE",里面是否包含另一个字符 ...

  8. hdu 2940

    简单的大数乘法,直接改16进制~~ #include <cstdio> #include <cstdlib> #include <cmath> #include & ...

  9. Android 使用系统的Activity播放音频文件 intent

    Intent intent = new Intent(); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Inten ...

  10. 使用getJSON()方法异步加载JSON格式数据

    使用getJSON()方法异步加载JSON格式数据 使用getJSON()方法可以通过Ajax异步请求的方式,获取服务器中的数组,并对获取的数据进行解析,显示在页面中,它的调用格式为: jQuery. ...