CodeForce 424C Magic Formulas
这个题就是求出给的公式的结果。
仅仅要知道异或运算满足交换律跟结合律即可了。之后就是化简公式。
- #include<map>
- #include<string>
- #include<cstring>
- #include<cstdio>
- #include<cstdlib>
- #include<cmath>
- #include<queue>
- #include<vector>
- #include<iostream>
- #include<algorithm>
- #include<bitset>
- #include<climits>
- #include<list>
- #include<iomanip>
- #include<stack>
- #include<set>
- using namespace std;
- int psum[1000010];
- int main()
- {
- int n;
- cin>>n;
- int ans=0;
- for(int i=0;i<n;i++)
- {
- int t;
- scanf("%d",&t);
- ans^=t;
- }
- for(int i=1;i<n;i++)
- psum[i]=i^psum[i-1];
- for(int i=1;i<=n;i++)
- {
- int t=n/i;
- if(t&1)
- ans^=psum[i-1];
- t=n%i;
- ans^=psum[t];
- }
- cout<<ans;
- }
2 seconds
256 megabytes
standard input
standard output
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.
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).
The only line of output should contain a single integer — the value of Q.
- 3
- 1 2 3
- 3
CodeForce 424C Magic Formulas的更多相关文章
- Codeforce 424C Magic Formulas 找规律
题目链接:http://codeforces.com/contest/424/problem/C 题意:求Q值 思路:找规律 显然能够得到一个矩阵 把这个矩阵画出来就能发现一个横向的规律和一个主对角线 ...
- Codeforces 424 C. Magic Formulas
xor是满足交换律的,展开后发现仅仅要能高速求出 [1mod1....1modn],....,[nmod1...nmodn]的矩阵的xor即可了....然后找个规律 C. Magic Formulas ...
- codeforce-424C. Magic Formulas(数学)
C. Magic Formulas time limit per test:2 seconds memory limit per test:256 megabytes input stan ...
- 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 #242 (Div. 2) C. Magic Formulas (位异或性质 找规律)
题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1. 交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ ...
- codeforce 606A - Magic Spheres
题意:a,b,c三种球,能把俩个一样的球变成另一颜色不一样的球.给你目标x,y,z,问能否经过变化至少达打目标. #include<iostream> #include<stdio. ...
- cf C. Magic Formulas
http://codeforces.com/contest/424/problem/C #include <cstdio> #include <cstring> #includ ...
- codeforces C. Magic Formulas 解题报告
题目链接:http://codeforces.com/problemset/problem/424/C 题目意思:给出 n 个数:p1, p2, ..., pn,定义: q1 = p1 ^ (1 mo ...
- Codeforces Round #242 (Div. 2) <A-D>
CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...
随机推荐
- Windows10通过VNC远程连接Ubuntu18.04
1.打开终端输入:sudo apt-get install xrdp vnc4server xbase-clients dconf-editor 2.接着在终端输入: 进入到下面这个界面: 接着按照这 ...
- unity gitignore
/[Ll]ibrary/ /[Tt]emp/ /[Oo]bj/ /[Bb]uild/ /[Bb]uilds/ /Assets/AssetStoreTools* # Autogenerated VS/M ...
- Python安装selenium启动浏览器
1:在Python运行火狐或谷歌的浏览器是需要下载相对应的驱动 例如:你想在Python中使用代码命令打开firefox的网页 如果没有安装驱动,直接运行的话会出下面的错误 所以我们要安装相对应的浏览 ...
- MyBatis学习总结(10)——批量操作
一.mybatis中的批量操作 批量操作核心就是一次传入多个数据然后进行相关操作,增删改查中掌握其中一个其他的也不成问题 1.最新在做的短信平台,要批量插入群发的短信记录: 当然批量操作还有:批 ...
- 洛谷 P1754 球迷购票问题
P1754 球迷购票问题 题目背景 盛况空前的足球赛即将举行.球赛门票售票处排起了球迷购票长龙. 按售票处规定,每位购票者限购一张门票,且每张票售价为50元.在排成长龙的球迷中有N个人手持面值50元的 ...
- 3D打印技术之切片引擎(6)
[此系列文章基于熔融沉积( fused depostion modeling, FDM )成形工艺] 这一篇文章说一下填充算法中的网格填充.网格填充在现有的较为成熟的引擎中是非常普遍的:skeinfo ...
- hdu 3547 DIY Cube (Ploya定理)
DIY Cube Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total S ...
- poj--2391--Ombrophobic Bovines(floyd+二分+最大流拆点)
Ombrophobic Bovines Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u ...
- 85.explicit作用
#include <iostream> using namespace std; class myclass { public: int num; public: explicit myc ...
- swing导出html到excel
swing导出html到excel 1 ShowCopDetal package com.product; import java.awt.BorderLayout; import java.awt ...