思路:

最终的时候,对于位置p,若p是奇数,则该位置的元素是(p + 1) / 2;若p是偶数,需要从p开始不断地迭代寻找上一次跳跃所处的位置(p = p + n - p / 2),直到p是奇数为止。这个过程直观上看是log(n)的,因为每次跳跃的长度都在n / 2级别。

实现:

 #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n, q, x;
cin >> n >> q;
while (q--)
{
cin >> x;
while (!(x & )) x += n - x / ;
cout << (x + >> ) << endl;
}
return ;
}

CF949B A Leapfrog in the Array的更多相关文章

  1. CF949B A Leapfrog in the Array 思维题,推理

    题意: Dima是一名初级程序员. 在他的工作中,他经常不断地重复以下操作:从数组中删除每个第二个元素. 有一天,他对这个问题的解决方案感到厌倦,他提出了以下华丽的算法. 假设有一长度为2n的数组,最 ...

  2. Codeforces 950D A Leapfrog in the Array (思维)

    题目链接:A Leapfrog in the Array 题意:给出1-n的n个数,从小到大每隔一个位置放一个数.现在从大到小把数往前移动,每次把最右边的数移动最靠右边的空格处直到n个数都在前n个位置 ...

  3. codeforces 949B A Leapfrog in the Array

    B. A Leapfrog in the Array time limit per test 2 seconds memory limit per test 512 megabytes input s ...

  4. B. A Leapfrog in the Array

    http://codeforces.com/problemset/problem/949/B Dima is a beginner programmer. During his working pro ...

  5. Codeforces 950 D. A Leapfrog in the Array

    http://codeforces.com/contest/950/problem/D 前n/2个格子的奇数下标的数没有参与移动 候n/2个格子的奇数下标的数一定是一路移向偶数下标移 所以还原数的初始 ...

  6. CodeForces - 950D A Leapfrog in the Array 玄学题

    题意:n个数1~n(n<=1e18)依次放在一个数组中,第i个数位置为2i-1,其它地方是空的.现在重复以下操作:将最右边的数放到离其左边最近的空的位置,直到所有数移到前一半的位置中.有q< ...

  7. codeforce469DIV2——D. A Leapfrog in the Array

    题意: 给出1<=n<=10^18和1<=q<=200000,有一个长度为2*n-1的数组,初始时单数位置存(i+1)/2,双数位置是空的.每次找出最右边的一个数将它跳到离它最 ...

  8. cf950d A Leapfrog in the Array

    考虑在位置 \(p\) 的青蛙. 如果 \(p\) 是奇数,答案显然是 \((p+1)/2\). 否则,由于未跳时 \(p\) 左边有 \(p/2\) 只,则 \(p\) 右边有 \(n-p/2\) ...

  9. Codeforces 950D A Leapfrog in the Array ( 思维 && 模拟 )

    题意 : 给出 N 表示有标号 1~N 的 N 个数,然后从下标 1 开始将这 N 个数每隔一位放置一个,直到 N 个数被安排完,现在有一个操作就是每次将数列中最右边的数向离其左边最近的空缺处填上,一 ...

随机推荐

  1. VMware 虚拟机添加硬盘以及为新添加的硬盘创建Samba共享 (转)

    一.为VMware虚拟机添加硬盘 1. 首先在VMware虚拟机的VM->Setting子菜单中为虚拟机添加一块15G大小的SCSI类型的硬盘(注意:如果原来为IDE硬盘,SCSI类型的硬盘可能 ...

  2. pip 安装速度慢解决办法

    https://blog.csdn.net/liujingclan/article/details/50176597 https://blog.csdn.net/rytyy/article/detai ...

  3. C# 敏感词过滤

    public class BadWordFilter { #region 变量 private HashSet<string> hash = new HashSet<string&g ...

  4. 为Windows Live Writer添加Code插件

    1.插件效果展示 1: void CDemoDlg::OnBnClickedNmdlg() 2: { 3: CNonModeDlg *pDlg = new CNonModeDlg();// 创建一个C ...

  5. 浅谈cookie 和session 的区别

    具体来说 cookie 是保存在“客户端”的,而session是保存在“服务端”的 cookie 是通过扩展http协议实现的 cookie 主要包括 :名字,值,过期时间,路径和域: 如果cooki ...

  6. Fri Jul 28 16:28:52 CST 2017 WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection mus

    Fri Jul 28 16:28:52 CST 2017 WARN: Establishing SSL connection without server’s identity verificatio ...

  7. caioj1275&&hdu4035: 概率期望值6:迷宫

    期望的大难题,%%ZZZ大佬的解释,不得不说这是一道好题(然而膜题解都没完全看懂,然后就去烦ZZZ大佬) 简单补充几句吧,tmp的理解是个难点,除以tmp的原因是,当我们化简时,子节点也有一个B*f[ ...

  8. POJ2533 Longest Ordered Subsequence —— DP 最长上升子序列(LIS)

    题目链接:http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 6 ...

  9. YTU 2414: C语言习题 字符串排序

    2414: C语言习题 字符串排序 时间限制: 1 Sec  内存限制: 128 MB 提交: 656  解决: 305 题目描述 输入n个字符串,将它们按字母由小到大的顺序排列并输出.编写三个函数实 ...

  10. YTU 2920: Shape系列-7

    2921: Shape系列-7 时间限制: 1 Sec  内存限制: 128 MB 提交: 156  解决: 129 题目描述 小强做的Shape类在本次的测试中出了点状况,发现原来是其中的area函 ...