Codeforces Round #384 B. Chloe and the sequence
来源:互联网 发布:linux chmod nobody 编辑:程序博客网 时间:2024/06/05 09:31
Chloe and the sequence
原题链接:http://codeforces.com/problemset/problem/743/B
题目大意:
假设现在的数列是a,那么在a的背后放一个最小的没出现过的整数,然后再把a重复的放在后面。
然后现在问你k位置是什么
(注意坑点,,用long long)
较为零乱的代码:(找规律)
#include<stdio.h>#define ll long long intll a[55];int main(){ a[0]=0; a[1]=1; ll i,cnt,n,k; for(i=2; i<53; i++) a[i]=2*a[i-1]+1; scanf("%lld%lld",&n,&k); if(k&1)//奇数为1 printf("1\n"); else { int flag=1; while(flag) { ll ans; for(i=52; i>=0; i--) if(a[i]<k) { cnt=k-a[i]-1;//规律在此,当cnt为0时,当前的i+1就是所需要的答案了 if(cnt==0) { ans=i+1; flag=0; break; } else k=cnt; } printf("%lld\n",ans); } } return 0;}
大神的理解:实际上就是这个数字k的二进制最小的1的位数的位置。
代码:
#include<bits/stdc++.h>using namespace std;long long n,p;int main(){ scanf("%lld%lld",&n,&p); cout<<log2(p&(-p))+1<<endl;}
最重要的还是思想啊。啊
1 0
- Codeforces Round #384 (Div. 2) B Chloe and the sequence
- Codeforces Round #384 B. Chloe and the sequence
- Codeforces Round #384 (Div. 2) B. Chloe and the sequence
- Codeforces Round #384(Div. 2)B. Chloe and the sequence【思维+lowbit】
- Codeforces Round #384 (Div. 2) B. Chloe and the sequence 找规律
- Codeforces Round #384 (Div. 2) 743B Chloe and the sequence
- Codeforces 743B Chloe and the sequence
- 743B. Chloe and the sequence codeforces
- Codeforces 743B-Chloe and the sequence
- ***CodeForces - 743B Chloe and the sequence
- Chloe and the sequence CodeForces
- Chloe and the sequence CodeForces
- B. Chloe and the sequence
- 【47.40%】【codeforces 743B】Chloe and the sequence
- codeforces 743 B Chloe and the sequence(递归)
- codeforces 743 B. Chloe and the sequence (规律题)
- Chloe and the sequence
- Codeforces-743B-Chloe and the sequence(二进制思维题)
- 视觉项目中评估图像质量的关键指标
- Java通过Class的对象来获取泛型的class示例
- 计算机权限 用户组 system everyone 深入理解
- 统计基本知识-1
- 【LeetCode】 003. Longest Substring Without Repeating Characters
- Codeforces Round #384 B. Chloe and the sequence
- Intent意图
- ubuntu 16.04学习笔记之安装Vim以及基本配置
- Node中的HTTP
- LeetCode:ZigZag Conversion
- 实现一个学生的成绩的录入与查询成绩(不算原创,也不算转载,是根据他人代码改动而来)
- 使用border 画三角形
- 优雅编程之这样使用CollectionUtils,你就“正常”了(三十五)
- [AHK]一个按键顶三个