CodeForces 743B Chloe and the sequence (递归)

时间:2022-10-31 16:09:31

题意:给定n和k,求第n个序列中第k个数是多少,序列是这样构造,原来只有1,然后再copy一遍放在到后面再在中间放上一个没有出现过的最小整数,就变成了

121,下次就成了1213121。

析:很明显是用递归来做,如果k在前半部分,那么就再递归,如果是在后半部分,那么就是先减一半再递归。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = (1<<20) + 5;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
LL dfs(LL k, LL n){
if(n == 1) return n;
LL t = (1LL<<(n-1));
if(k == t) return n;
if(k > t) return dfs(k-t, n-1);
return dfs(k, n-1);
} int main(){
LL k, n;
while(cin >> n >> k){
printf("%I64d\n", dfs(k, n));
}
return 0;
}

CodeForces 743B Chloe and the sequence (递归)的更多相关文章

  1. CodeForces - 743B Chloe and the sequence

    暴力肯定是无法做的 当时做的时候 当成一道递推来做的 用到分治的思想 想象一串长度为2n+1的列 那么前n个为前一串数 后n个是前一串数的reverse 第n+1个数 为第几串的编号 例如 第几串 中 ...

  2. Codeforces Round &num;384 &lpar;Div&period; 2&rpar;B&period; Chloe and the sequence 数学

    B. Chloe and the sequence 题目链接 http://codeforces.com/contest/743/problem/B 题面 Chloe, the same as Vla ...

  3. Codeforces Beta Round &num;13 C&period; Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  4. 【47&period;40&percnt;】【codeforces 743B】Chloe and the sequence

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. Codeforces Round &num;384 &lpar;Div&period; 2&rpar; B&period; Chloe and the sequence(规律题)

    传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems ...

  6. Codeforces 438D The Child and Sequence - 线段树

    At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...

  7. Educational Codeforces Round 7 A&period; Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  8. Codeforces 743D Chloe and pleasant prizes&lpar;树型DP&rpar;

                                                                D. Chloe and pleasant prizes             ...

  9. CodeForces - 743D Chloe and pleasant prizes

    Chloe and pleasant prizes time limit per test 2 seconds memory limit per test 256 megabytes input st ...

随机推荐

  1. Oracle的自动统计信息不收集直方图的信息

    Oracle的自动统计信息不收集直方图的信息 在oracle9i中,默认的统计信息收集是不收集直方图信息的,也就是说默认的MOTHOD_OPT模式为FOR ALL COLUMNS SIZE 1 在10 ...

  2. (11)UI布局和分辨率适配

    一.Cocos编辑器 自动布局系统主要涉及固定与拉伸属性:   如图,总共可以修改控件的上下左右四个图钉和中间的两个拉伸条六个属性. 效果   1.当打开其中的任意一个图钉时,当前节点与父节点的对应边 ...

  3. parseInt在IE8转换返回不相等(parseInt&lpar;&quot&semi;08&quot&semi;&rpar;返回0等以0开头大于7的数字串)

    描述 在IE8内核下parseInt("08")返回0,等以0开头大于7的数字串返回的值不相等 解决方法 parseInt当不指定radix时,当以0x开头时,s按照十六进制计算的 ...

  4. tcp粘包和拆包的处理方案

    随着智能硬件越来越流行,很多后端开发人员都有可能接触到socket编程.而很多情况下,服务器与端上需要保证数据的有序,稳定到达,自然而然就会选择基于tcp/ip协议的socekt开发.开发过程中,经常 ...

  5. bzoj 3191&colon; &lbrack;JLOI2013&rsqb;卡牌游戏

    Description N个人坐成一圈玩游戏.一开始我们把所有玩家按顺时针从1到N编号.首先第一回合是玩家1作为庄家.每个回合庄家都会随机(即按相等的概率)从卡牌堆里选择一张卡片,假设卡片上的数字为X ...

  6. Dynamics CRM2013 定制你的系统登录后的首页面

    在2013中个性设置中又多了一个新的,更好的增强了用户体验,对于特定的用户而言只需要使用系统的一小块功能,所以很多用户进入 系统只需要显示跟自己业务相关的功能页面即可. 点右上角的齿轮进入选项,在常规 ...

  7. HashMap在JDK1&period;7中可能出现的并发问题

    在JDK1.7及以前中,如果在并发环境中使用HashMap保存数据,有可能会产生死循环的问题,造成cpu的使用率飙升.之所以会发生该问题,实际上就是因为HashMap中的扩容问题. HashMap的实 ...

  8. 添加一个pv到vg后,误删新加入的pv,报 pv &ast; not found or rejected by a filter

    问题如下 将某一pv加入vg vgextend cl /dev/xvdb1 然后进入fdisk将xvdb1分区删掉,重新创建pv 使用lvdisplay报警告 [root@localhost ~]# ...

  9. 在分析nginx日志时常用命令总结【转】

    1. 利用grep ,wc命令统计某个请求或字符串出现的次数 比如统计GET /app/kevinContent接口在某天的调用次数,则可以使用如下命令: [root@Fastdfs_storage_ ...

  10. F5负载均衡原理(转载)

    https://blog.csdn.net/panxueji/article/details/42647193 一. 负载均衡技术 负载均衡技术在现有网络结构之上提供了一种廉价.有效.透明的方法,来扩 ...