Codeforces 424 C Magic Formulas

Time Limit:2000MS     Memory Limit:262144KB    
64bit IO Format:%I64d & %I64u

Submit
Status Practice CodeForces 424C

Description

People in the Tomskaya region like magic formulas very much. You can see some of them below.

Imagine you are given a sequence of positive integer numbers
p1,
p2, ...,
pn. Lets write down some magic formulas:


Here, "mod" means the operation of taking the residue after dividing.

The expression means applying the bitwise
xor (excluding "OR") operation to integers
x and y. The given operation exists in all modern programming languages. For example, in languages C++ and Java it is represented by "^", in
Pascal — by "xor".

People in the Tomskaya region like magic formulas very much, but they don‘t like to calculate them! Therefore you are given the sequence
p, calculate the value of
Q.

Input

The first line of the input contains the only integer n (1?≤?n?≤?106). The next line contains
n integers: p1,?p2,?...,?pn
(0?≤?pi?≤?2·109).

Output

The only line of output should contain a single integer — the value of
Q.

Sample Input

Input

3
1 2 3

Output

3

题意:如题。

思路:纵向分析,先是p1^……^pn。。。不说了,贴个网址,我觉得说的肯定比我清楚。http://www.tuicool.com/articles/InYrm2M

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdlib.h>

using namespace std;

int p;
int a[1000006];

int main(){
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&p);
        ans^=p;
    }
    for(int i=1;i<=n;i++){
        a[i]=a[i-1]^i;
        if(n%(2*i)!=0){
            int x=n%(2*i);
            if(x>=i){
                ans^=a[i-1];
                x-=i;
            }
            ans^=a[x];
        }
    }
    printf("%d\n",ans);
    return 0;
}



Codeforces 424 C Magic Formulas,布布扣,bubuko.com

时间: 2024-08-13 17:56:20

Codeforces 424 C Magic Formulas的相关文章

CodeForce 424C Magic Formulas

这个题就是求出给的公式的结果. 只要知道异或运算满足交换律跟结合律就行了,之后就是化简公式. #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<iostream> #i

codeforces 710C C. Magic Odd Square(构造)

题目链接: C. Magic Odd Square Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n (1 ≤ n ≤ 49). Output Print n lines with n integers. All the

(最小生成树)Codeforces Educational Codeforces Round 9 Magic Matrix

You're given a matrix A of size n?×?n. Let's call the matrix with nonnegative elements magic if it is symmetric (so aij?=?aji), aii?=?0 and aij?≤?max(aik,?ajk) for all triples i,?j,?k. Note that i,?j,?k do not need to be distinct. Determine if the ma

Codeforces 424 B Megacity【贪心】

题意:给出城市(0,0),给出n个坐标,起始人数s,每个坐标k个人, 每个坐标可以覆盖到半径为r的区域,r=sqrt(x*x+y*y)的区域,问最小的半径是多少,使得城市的总人数大于等于1000000 最开始是排序,贪心来做的,发现sqrt的精度老达不到要求,于是翻了代码 于是发现用map就可以解决了 map<int,int>,it->first是第一个int的内容,it->second是第二个int的内容 话说本来是按照标签来找的,想做二分查找的题目的= = 1 #include

codeforces 424 D Biathlon Track

题意:给出一个布满数字的网格,可以上下左右走,若下一个格子的数字比当前格子要大或者小或者一样,分别都要付出代价.给出一个期望代价,问当要求顺时针走出一个长宽均大于3的矩形的四条边后,最接近期望代价的情况. 做法:由于长宽大于3,直接暴力枚举即可. #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath

Codeforces 710 C. Magic Odd Square(构造)——Educational Codeforces Round 16

传送门 Find an n?×?n matrix with different numbers from 1 to n2, so the sum in each row, column and both main diagonals are odd. Input The only line contains odd integer n(1?≤?n?≤?49). Output Print n lines with n integers. All the integers should be dif

Codeforces 424C(异或)

Magic Formulas Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description People in the Tomskaya region like magic formulas very much. You can see some of them below. Imagine you are given a sequence of pos

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿