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 ...
随机推荐
- mysql 的存储过程调试软件
免费下载链接:http://download.csdn.net/detail/meiyoudao/6371137 需要注册 调试还是 F10 类似的
- ubuntu 12.04 搭建nginx + php + mysql +phpmyadmin
1. 使用官方PPA安装 Nginx 最新版本,使用以下命令:sudo add-apt-repository ppa:nginx/stablesudo apt-get updatesudo apt-g ...
- 【转】Dancing Links题集
转自:http://blog.csdn.net/shahdza/article/details/7986037 POJ3740 Easy Finding [精确覆盖基础题]HUST1017 Exact ...
- 01-05-01-2【Nhibernate (版本3.3.1.4000) 出入江湖】立即加载实现--NHibernateUtil.Initialize()和添加fetch关键字的HQL查询
相关资料: http://www.cnblogs.com/lyj/archive/2008/10/29/1322373.html 问题的提出: 1.延迟加载,可能会引起session已经关闭的异常,例 ...
- prefix springmvc
设置了@RequestMapping("/jsp/info.do"),也可以写成"jsp/info.act"不影响 retuen "index&quo ...
- Unity3D脚本中文系列教程(四)
http://dong2008hong.blog.163.com/blog/static/4696882720140302451146/ Unity3D脚本中文系列教程(三) 送到动画事件. ◆ va ...
- MethodInvoker 委托
MethodInvoker 提供一个简单委托,该委托用于调用含 void 参数列表的方法. 在对控件的 Invoke 方法进行调用时或需要一个简单委托又不想自己定义时可以使用该委托. 下面的代码示例演 ...
- DiskGenius的 “终止位置参数溢出”错误解决方法。
(转帖)同事电脑系统启动突然明显变慢,重装系统后问题仍未解决(windowsxp sp3).帮忙分析感觉是磁盘分区表出现了错误,用通用PE工具箱进入PE系统,DiskGenius工具检查:“终止位置参 ...
- POJ 3468 A Simple Problem with Integers(线段树区间更新,模板题,求区间和)
#include <iostream> #include <stdio.h> #include <string.h> #define lson rt<< ...
- POJ2632Crashing Robots
做模拟题做的我直接睡着了,题并不难,就是一个细心的问题,有一些细节问题注意了就差不多了,代码写的精美的一般找错误也好找一些,应该学着些好看的代码 #include<cstdio> #inc ...