考虑在位置 \(p\) 的青蛙。

如果 \(p\) 是奇数,答案显然是 \((p+1)/2\)。

否则,由于未跳时 \(p\) 左边有 \(p/2\) 只,则 \(p\) 右边有 \(n-p/2\) 只,则这青蛙是从 \(p+n-p/2\) 处跳过来的。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int q;
ll n, uu;
ll f(ll x){
if(x&1) return (x+1)/2;
else return f(n+x/2);
}
int main(){
cin>>n>>q;
while(q--){
scanf("%I64d", &uu);
printf("%I64d\n", f(uu));
}
return 0;
}

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

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

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

  2. 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 ...

  3. B. A Leapfrog in the Array

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

  4. Codeforces 950 D. A Leapfrog in the Array

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

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

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

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

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

  7. CF949B A Leapfrog in the Array

    思路: 最终的时候,对于位置p,若p是奇数,则该位置的元素是(p + 1) / 2:若p是偶数,需要从p开始不断地迭代寻找上一次跳跃所处的位置(p = p + n - p / 2),直到p是奇数为止. ...

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

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

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

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

随机推荐

  1. C#的弱引用

    关于C#中的弱引用 一:什么是弱引用 了解弱引用之前,先了解一下什么是强引用 例如 : Object obj=new Object();     就是一个强引用,内存分配一份空间给用以存储Object ...

  2. 《javascript设计模式》笔记之第四章:继承

    一:首先,一个简单的继承实例: 首先是创建一个父类Person: function Person(name) { this.name = name; } Person.prototype.getNam ...

  3. 基于.net core封装的xml序列化,反序列化操作

    需求: 由于在.net core中去除了Xml序列化XmlSerializer操作类.因此,在于一此数据传输当中出,需要用到对xml格式字符串的处理问题.因此封装了一个xml序列化与反序列化操作的类库 ...

  4. dos命令安装windows服务

    以下两种方法都是通过dos命令创建windows服务 1.创建服务 sc create UploadRealVolumeService start= auto binpath= C:\Users\Ad ...

  5. mybatis实现使用原生的sql

    1.相应的xml文件中 <select id="selectByCategories" resultType="map" parameterType=&q ...

  6. webpack入门之最简单的例子 webpack4

    webpack在目前来说应该是前端用的比较多的打包工具了,那么对于之前没有接触过这块的该怎么办呢?答案很明显嘛,看资料,查文档,自己去琢磨,自己去敲一敲,跑一跑: 那么,这边我将以一个最基础的例子来将 ...

  7. Xcode 升级后,cocoaPod 问题

    当我从Xcode 6.3切换到Xcode6.4的时候,因为我是mac上安装了两个不同的版本,现在把Xcode 6.3卸掉了. 现在再次运行pod install命令的时候,提示如下错误:   Upda ...

  8. MongoDB数据清理命令

    #启动mongo命令/data/liudi/mongodb/bin/mongo --port 27010 #显示数据库show dbs; #使用tps_live数据库use tps_live; #显示 ...

  9. leecode 旋转数组

    描述 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数. 示例 1: 输入: [1,2,3,4,5,6,7] 和 k = 3 输出: [5,6,7,1,2,3,4] 解释: 向右旋 ...

  10. 第二次团队作业-PANTHER考勤系统需求分析

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 这个作业要求在哪里 https://edu.cnblo ...