Codeforces Round #647 (Div. 2) - Thanks, Algo Muse! C. Johnny and Another Rating Drop (规律,二进制)
题意:有一个正整数\(n\),要求写出所有\(1\)~\(n\)的二进制数,统计相邻的两个二进制同位置上不同数的个数.
题解:打表找规律,不难发现:
\(00000\)
\(00001\)
\(00010\)
\(00011\)
\(00100\)
\(00101\)
当最低位时,每次都变换,由低位向高位,每\(2*i\)次变换一次,直接位运算暴力即可.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL; int t;
ll n; int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin>>t;
while(t--){
cin>>n;
ll now=n;
ll ans=0,p=1;
while(now){
ans+=n/p;
p*=2;
now>>=1;
}
printf("%lld\n",ans);
} return 0;
}
Codeforces Round #647 (Div. 2) - Thanks, Algo Muse! C. Johnny and Another Rating Drop (规律,二进制)的更多相关文章
- Codeforces Round #647 (Div. 2) - Thanks, Algo Muse! D. Johnny and Contribution (贪心,模拟)
题意:有\(n\)个点,\(m\)条边,现在要给这些点赋值,,每次只能赋给某一点的四周(所连边)的最小没出现过的值.如果不能按照所给的数赋值,输出\(-1\),否则输出赋值顺序. 题解:我们用\(pa ...
- Codeforces Round #647 (Div. 2) - Thanks, Algo Muse! A、Johnny and Ancient Computer B、Johnny and His Hobbies C、Johnny and Another Rating Drop
题目链接:A.Johnny and Ancient Computer 题意: 给你两个数a,b.问你可不可以通过左移位运算或者右移位运算使得它们两个相等.可以的话输出操作次数,不可以输出-1 一次操作 ...
- Codeforces Round #647 (Div. 2) C. Johnny and Another Rating Drop(数学)
题目链接:https://codeforces.com/contest/1362/problem/C 题意 计算从 $0$ 到 $n$ 相邻的数二进制下共有多少位不同,考虑二进制下的前导 $0$ .( ...
- Codeforces Round #647 (Div. 2)
Problem A https://codeforces.com/contest/1362/problem/A 判断x/y是不是2的k次方, 如果是 k/3 + (k%3)/2 + (k%3%2)即为 ...
- Codeforces Round #647 (Div. 2) D. Johnny and Contribution(BFS)
题目链接:https://codeforces.com/contest/1362/problem/D 题意 有一个 $n$ 点 $m$ 边的图,每个结点有一个从 $1 \sim n$ 的指定数字,每个 ...
- Codeforces Round #647 (Div. 2) B. Johnny and His Hobbies(枚举)
题目链接:https://codeforces.com/contest/1362/problem/B 题意 有一个大小及元素值均不超过 $1024$ 的正整数集合,求最小正整数 $k$,使得集合中的每 ...
- Codeforces Round #647 (Div. 2) A. Johnny and Ancient Computer
题目链接:https://codeforces.com/contest/1362/problem/A 题意 有一个正整数 $a$,可选择的操作如下: $a \times 2$ $a \times 4$ ...
- Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题
A. Little Pony and Expected Maximum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...
- Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final) A. Kids Seating (规律)
题意:给你一个正整数\(n\),在\([1,4n]\)中找出\(n\)个数,使得这\(n\)个数中的任意两个数不互质且不能两两整除. 题解:这题我是找的规律,从\(4n\)开始,往前取\(n\)个偶数 ...
随机推荐
- UVA - 387 A Puzzling Problem
题目链接: https://vjudge.net/problem/UVA-387 思路: 非常有意思的拼图,深搜+回溯, 输出硬伤:除了第一次之外,每次先输空格,再输出结果, 以及可能给的数据拼不成4 ...
- ctfhub技能树—信息泄露—git泄露—index
打开靶机 查看页面信息 使用dirsearch进行扫描 使用githack工具处理git泄露情况 使用git log命令查看历史记录 与 add flag 9b5b58-- 这次提交进行比对 即可拿到 ...
- CTFshow萌新赛-千字文
打开靶机 下载完成后,为一张二维码图片 使用StegSolve 解出隐写图像 保存后使用PS或其他工具去除白边 然后使用脚本分割这个图像(25*25) from PIL import Image im ...
- npm i 报错 'match' of undefined 错误以及删除node_modules失败
简单粗暴的解决办法就是一个字'删', 1.先把node_modules给删了 手动删除的话,window系统经常会有部分删不了,说需要个权限什么的,直接用rimraf 就能解决 先安装npm inst ...
- ABAP-ALV-如何去掉OO方法中的ALV的标准按钮
SAP在做报表开发中,不同公司对报表的风格往往各异,为此经常在使用OO方法做ALV报表中需要去掉自带的工具栏而自行添加一些工具按钮,下面将简单介绍一些其实现过程与原理: 步骤一: DATA : gt_ ...
- 手动验证MySQL Innodb RR级别加锁 需要注意的几个点
记录几个坑 优化器在表行数比较少的时候 会使用全表扫描,会造成全表所有的行加锁,所以需要使用force index 强制使用索引 来实现gap-lock(间隙锁)的应用 next-lock 加锁 会锁 ...
- COLMAP简易教程(命令行模式)
完整的 multi view stereo pipeline 会有以下步骤 structure from motion(SfM)==> camera parameters, sparse poi ...
- hive搜索报错
在自己搭建的集群上执行hive搜索语句 select count(*) from ods_event_log where dt='2019-12-14' group by dt; 报错如下: Stat ...
- Coded UI
Coded UI Test是Visual Studio 2010对于Testing Project(测试工程)提供的关于UI自动化测试的框架,支持Win32,Web,WPF等UI的自动化测试,是一个非 ...
- Python学习【第2篇】:基本数据类型(详解)
1.数字 2.字符串中的方法 str test = "xiaoxing"#首字母大写v = test.capitalize()print(v)运行后结果如下Xiaoxing tes ...