ACDream - Xor pairs
先上题目:
Xor pairs
Problem Description
long long ans = 0;
for(int i = 1; i <= n; i ++)
for(int j = i + 1; j <= n; j ++)
for(int k = j + 1; k <= n; k ++)
if((i ^ j ^ k) == 0) ans ++;
Input
Output
Sample Input
10
11
12
Sample Output
10
13
17 第一眼看输入只有一个数字,然后就有输出,这有很大几率是找规律。
打表以后发现好像规律还不是很明显,将相邻的两项相减,然后就找到规律了:0,1,0,1,2,3,0,1,2,3,4,5,6,7,0,``````
然后就是构造函数了,思路是先求出距离输入的n最近的2的次幂求和的那个幂数,然后求出每一个以2的次幂-1为终结的等差数列的和,求出以后再加上多出来的那一部分等差数列,就可以得到的数了。中间可能还需要一点小的调整。 上代码:
/*
* this code is made by sineatos
* Problem: 1183
* Verdict: Accepted
* Submission Date: 2014-07-31 14:59:31
* Time: 8MS
* Memory: 1088KB
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 100002
#define ll long long
using namespace std; int main()
{
ll n,i,c,r;
while(~scanf("%lld",&n))
{
if(n<) printf("0\n");
else if(n==) printf("1\n");
else
{
ll sum=;
c=;
for(i=; (c+i)<n; i<<=)
{
c+=i;
sum+=i*(i-)/;
}
r=n-c;
sum+=(+(r-))*(r-)/;
printf("%lld\n",sum);
}
} return ;
}
/*Xor pairs*/
ACDream - Xor pairs的更多相关文章
- Codeforces617 E . XOR and Favorite Number(莫队算法)
XOR and Favorite Number time limit per test: 4 seconds memory limit per test: 256 megabytes input: s ...
- Codeforeces 617E XOR and Favorite Number(莫队+小技巧)
E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法
E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...
- CodeForces 276D – Little Girl and Maximum XOR 贪心
整整10个月后第二次搞这个问题才搞懂........第一次还是太随意了. 解题思路: 经过打表可得规律答案要么是0 要么是2的N次 - 1 要得到最大的XOR值,其值一定是2的N次 - 1 即在 l ...
- XOR and Favorite Number(莫队算法+分块)
E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- uval 6657 GCD XOR
GCD XORGiven an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where1 ...
- GCD XOR uvalive6657
GCD XORGiven an integer N, nd how many pairs (A; B) are there such that: gcd(A; B) = A xor B where1 ...
- ARC 066D Xor Sum AtCoder - 2272 (打表找规律)
Problem Statement You are given a positive integer N. Find the number of the pairs of integers u and ...
- Codeforces Round #396 (Div. 2) E. Mahmoud and a xor trip dfs 按位考虑
E. Mahmoud and a xor trip 题目连接: http://codeforces.com/contest/766/problem/E Description Mahmoud and ...
随机推荐
- Luogu4198 楼房重建
https://zybuluo.com/ysner/note/1124880 题面 带修改的区间维护最大斜率. 题面 解析 用线段树区间维护斜率. 考虑如何向上合并. 左半段一定有贡献. 如果左半段的 ...
- 2018.2.24Test总结
T1(luogu3434) comment:水题,考试时我想的是开一个数组在读入时预处理出该长度什么时候会被拦住,但这样数组开不下,剩下只能模拟. 实际上应该把圆筒变成递减序列,再二分该长度即可. T ...
- windows下写的脚本,在linux下执行失败
Windows中的换行符为CRLF, 即正则表达式的rn(ASCII码为13和10), 而Unix(或Linux)换行符为LF, 即正则表达式的n. 在Windows和Linux下协同工作的时候, 往 ...
- 直接使用FileSystem以标准输出格式显示hadoop文件系统中的文件
package com.yoyosys.cebbank.bdap.service.mr; import java.io.IOException; import java.io.InputStream; ...
- codevs2503失恋28天......(背包dp)
503 失恋28天-缝补礼物 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description 话说上回他给女孩送了n件礼物,由于是廉价的所以 ...
- ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/pod
因为突然要用到cocospod,突然发现在使用pod install的时候出现 -bash: pod: command not found 我去-不知道为什么,然后我就想重新安装下cocospod,在 ...
- 用Python一键搭建Http服务器的方法
用Python一键搭建Http服务器的方法 Python3请看 python -m http.server 8000 & Python2请看 python -m SimpleHTTPServe ...
- 【知识总结】回文自动机(Palindrome_Automaton)
参考资料:Palindromic Tree--回文树[处理一类回文串问题的强力工具](请注意,其中似乎有一些错误) 回文自动机似乎和回文树是同一个东西qwq? 回文自动机(PAM)是一种处理回文串的工 ...
- Boost Bimap示例
#include <string> #include <iostream> #include <boost/bimap.hpp> template< clas ...
- Java jre7及以上版本中的switch支持String的实现细节
Java7中的switch支持String的实现细节 作者: zsxwing 更新: 2013-03-04 21:08:02 发布: 2012-04-26 13:58:19 在Java7之前,swit ...