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 ...
随机推荐
- 20145120 《Java程序设计》第2周学习总结
20145120 <Java程序设计>第2周学习总结 教材学习内容总结 因为前面有学习过C语言以及汇编语言,类型.运算符.流程控制等很多都是之前接触过的,因此在学习第三章的时候感觉并非十分 ...
- Android PopupWindow 点击消失解决办法
1.点击PopupWindow 外部区域时,PopupWindow消失 popMenu = new PopupWindow(getApplicationContext()); popMenu.setW ...
- 1833: [ZJOI2010]count 数字计数 - BZOJ
Description给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次.Input输入文件中仅包含一行两个整数a.b,含义如上所述.Output输出文件中包含一 ...
- 剑指offer--面试题8
题目:求旋转数组中的最小数字 以下为自己所写代码: #include "stdafx.h" #include <iostream> #include <excep ...
- windows 下c++编译
http://blog.csdn.net/dyllove98/article/details/9314993
- C语言关键字register、extern、static
C语言中: 一.register变量 关键字regiter请求编译器尽可能的将变量存在CPU的寄存器中.有以下几点注意的地方. register变量必须是能被CPU寄存器所接受的类型,这通常意味着re ...
- Java 泛型(Generics)
Generics, 类似C++中的模版. 允许在定义类和接口的时候使用类型参数(type parameters), 声明的类型参数在使用的时候用具体的类型来替换. 如 ArrayList<Str ...
- C++ Variables and Basic Types Notes
1. Type conversion: If we assign an out-of-range value to an object of unsigned type, the result is ...
- POJ1008Maya Calendar
http://poj.org/problem?id=1008&lang=default&change=true 这个题倒是不难,就是麻烦一点,但是还WA了几次都是因为处理天数的时候没处 ...
- 毕向东JAVA视频讲解(第六课)
用java语言对现实生活中的事物进行描述. 通过类的形式来体现的. 怎么描述呢? 对于事物描述通常只关注两方面. 一个是属性,一个是行为. 只要明确该事物的属性和行为并定义在类中即可. 对象:其实就是 ...