Codeforces Round #461 (Div. 2) B. Magic Forest
B. Magic Forest
time limit per test 1 second
memory limit per test 256 megabytes
Problem Description
Imp is in a magic forest, where xorangles grow (wut?)
A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers not exceeding n, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order n to get out of the forest.
Formally, for a given integer n you have to find the number of such triples (a, b, c), that:
1 ≤ a ≤ b ≤ c ≤ n;
, where denotes the bitwise xor of integers x and y.
(a, b, c) form a non-degenerate (with strictly positive area) triangle.
Input
The only line contains a single integer n (1 ≤ n ≤ 2500).
Output
Print the number of xorangles of order n.
Examples
Input
6
Output
1
Input
10
Output
2
Note
The only xorangle in the first sample is (3, 5, 6).
解题心得:
- 题意是从1到n中选出三个数(可以相同),这三个数异或和为0,并且三个数可以形成一个三角形,问一共有多少中方案。
- n最大是2500,跑三重循环不现实,但是想想还是就明白的,三个数异或和为0,那么两个数异或起来肯定等于第三个数,这样跑双重循环就可以了。然后需要标记找过的三角形,由于异或起来的第三个数并不能确定和前两个数的大小关系,所以只能hash标记,这里就很坑了,之前选了一个233来hash,结果被卡了,想了半天才想到被卡了hash,连2333都会被卡。晕哦,最后23333过了。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7+10;
typedef long long ll;
map<ll,ll> maps;
int main(){
ll n;
ll a[5],ans=0;
scanf("%lld",&n);
for(ll i=1;i<=n;i++){
for(ll j=i+1;j<=n;j++){
ll c = i^j;//由前两个数得到第三个数
if(c > n || c < 1)//判读是否出了边界
continue;
a[0] = i;a[1] = j;a[2] = c;
sort(a,a+3);
ll temp = a[0];
temp = temp*23333+a[1];
temp = temp*23333+a[2];
if(maps[temp] == 233)
continue;
maps[temp] = 233;
if(a[0] + a[1] > a[2])//两小边之和大于第三边
ans++;
}
}
printf("%lld\n",ans);
return 0;
}
Codeforces Round #461 (Div. 2) B. Magic Forest的更多相关文章
- CF922 CodeForces Round #461(Div.2)
CF922 CodeForces Round #461(Div.2) 这场比赛很晚呀 果断滚去睡了 现在来做一下 A CF922 A 翻译: 一开始有一个初始版本的玩具 每次有两种操作: 放一个初始版 ...
- Codeforces Round #461 (Div. 2)B-Magic Forest+位运算或优雅的暴力
Magic Forest 题意:就是在1 ~ n中找三个值,满足三角形的要求,同时三个数的异或运算还要为0: , where denotes the bitwise xor of integers ...
- Codeforces Round #461 (Div. 2) B C D
题目链接:http://codeforces.com/contest/922 B. Magic Forest time limit per test 1 second memory limit per ...
- Codeforces Round #461 (Div. 2)
A - Cloning Toys /* 题目大意:给出两种机器,一种能将一种原件copy出额外一种原件和一个附件, 另一种可以把一种附件copy出额外两种附件,给你一个原件, 问能否恰好变出题目要求数 ...
- 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 #192 (Div. 1) B. Biridian Forest 暴力bfs
B. Biridian Forest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/pr ...
- [Codeforces Round #192 (Div. 2)] D. Biridian Forest
D. Biridian Forest time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算
D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
随机推荐
- codesmith 在安装32位Oracle 客户端问题解决
问题解决办法如下: https://blog.csdn.net/csdn1152789046/article/details/52248669
- php允许被跨域ajax请求
只要在被请求端,加一句: header('Access-Control-Allow-Origin: *');
- 【踩坑】服务器部署springboot应用时报错--端口被tomcat占用
今天将本机尬聊一下项目(基于netty-socketio)的服务端程序调试好以后,通过jar包部署在服务器的时候,出现了报错,提示tomcat已经占用了端口. 之前在部署iReview项目时的确是通过 ...
- cf600E. Lomsat gelral(dsu on tree)
题意 题目链接 给出一个树,求出每个节点的子树中出现次数最多的颜色的编号和 Sol dsu on tree的裸题. 一会儿好好总结总结qwq #include<bits/stdc++.h> ...
- 2016多校训练3_1007(hdu5758 Explorer Bo)
#include <functional> #include <algorithm> #include <iostream> #include <iterat ...
- Android在应用设置里关闭权限,返回生命周期处理
问题 在处理6.0运行时权限时,很多人都忽略了这样一个问题: 在一个App应用里,如果已经允许了一个权限比如(读取通讯权限),此刻去调用相机,弹出权限申请对话框,此刻点击拒绝,然后经过处理后弹出去设置 ...
- iOS中UIWebview中网页宽度自适应的问题
有的网页中会使用"<meta name="viewport" content="width=device-width, initial-scale=1.0 ...
- linux 命令——48 watch (转)
watch是一个非常实用的命令,基本所有的Linux发行版都带有这个小工具,如同名字一样,watch可以帮你监测一个命令的运行结果,省得你一遍遍的手动运行.在Linux下,watch是周期性的执行下个 ...
- IOS 设置子控件的frame(layoutSubviews and awakeFromNib)
如果控件是通过xib或者storyboard创建出来的就会调用该方法 - (void)awakeFromNib :该方法只会调用一次 // 如果控件是通过xib或者storyboard创建出来的就 ...
- ARM体系结构与编程-3
ARM存储系统:ARM中用于存储管理的系统控制协处理器CP15:包括16个32位寄存器,其编号为0到15.实际上对于某些编号的寄存器可能相应有多个物理寄存器. 訪问CP15寄存器的指令:MRC.MCR ...