codeforce469DIV2——D. A Leapfrog in the Array
题意:
给出1<=n<=10^18和1<=q<=200000,有一个长度为2*n-1的数组,初始时单数位置存(i+1)/2,双数位置是空的。每次找出最右边的一个数将它跳到离它最近的左边的空格,反复操作直到前n个数被充满 。q个询问,每个询问给出一个数x<=n,输出最终的序列x位置的数是什么。
分析:
一看数据规模和这个题就大概想到是数学题,然后试着找规律推式子。按照蒟蒻我的惯例这种题先写暴力找规律。然后发现,每次跳,第一次跳跳一个,再一次跳两个,一直到跳到n-1个。 那么从左往右,第i个位置f(i)=f(n+i/2),当i%2==1时,f(i)=(i+1)/2。我们发现那个函数的复杂度很小具体我不太会算大概Logn?
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std;
typedef unsigned long long ull; ull n,q; ull f(ull pos){
if(pos%){
return (pos+)/;
}
ull p=n-pos/;
return f(pos+p);
}
int main(){
cin>>n>>q;
ull x;
for(int i=;i<=q;i++){
cin>>x;
cout<<f(x)<<endl;
}
return ;
}
codeforce469DIV2——D. A Leapfrog in the Array的更多相关文章
- Codeforces 950D A Leapfrog in the Array (思维)
题目链接:A Leapfrog in the Array 题意:给出1-n的n个数,从小到大每隔一个位置放一个数.现在从大到小把数往前移动,每次把最右边的数移动最靠右边的空格处直到n个数都在前n个位置 ...
- 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 ...
- B. A Leapfrog in the Array
http://codeforces.com/problemset/problem/949/B Dima is a beginner programmer. During his working pro ...
- Codeforces 950 D. A Leapfrog in the Array
http://codeforces.com/contest/950/problem/D 前n/2个格子的奇数下标的数没有参与移动 候n/2个格子的奇数下标的数一定是一路移向偶数下标移 所以还原数的初始 ...
- CodeForces - 950D A Leapfrog in the Array 玄学题
题意:n个数1~n(n<=1e18)依次放在一个数组中,第i个数位置为2i-1,其它地方是空的.现在重复以下操作:将最右边的数放到离其左边最近的空的位置,直到所有数移到前一半的位置中.有q< ...
- cf950d A Leapfrog in the Array
考虑在位置 \(p\) 的青蛙. 如果 \(p\) 是奇数,答案显然是 \((p+1)/2\). 否则,由于未跳时 \(p\) 左边有 \(p/2\) 只,则 \(p\) 右边有 \(n-p/2\) ...
- CF949B A Leapfrog in the Array
思路: 最终的时候,对于位置p,若p是奇数,则该位置的元素是(p + 1) / 2:若p是偶数,需要从p开始不断地迭代寻找上一次跳跃所处的位置(p = p + n - p / 2),直到p是奇数为止. ...
- CF949B A Leapfrog in the Array 思维题,推理
题意: Dima是一名初级程序员. 在他的工作中,他经常不断地重复以下操作:从数组中删除每个第二个元素. 有一天,他对这个问题的解决方案感到厌倦,他提出了以下华丽的算法. 假设有一长度为2n的数组,最 ...
- Codeforces 950D A Leapfrog in the Array ( 思维 && 模拟 )
题意 : 给出 N 表示有标号 1~N 的 N 个数,然后从下标 1 开始将这 N 个数每隔一位放置一个,直到 N 个数被安排完,现在有一个操作就是每次将数列中最右边的数向离其左边最近的空缺处填上,一 ...
随机推荐
- windows获取屏幕显示比例 读取注册表法
static int GetDesktopScale() { ; HINSTANCE hUser32 = LoadLibrary(L"user32.dll"); if (hUser ...
- nodejs express project
user root install express npm install express -g install express... npm install express-generator -g ...
- 压缩感知Compressive sensing(一)
compressive sensing(CS) 又称 compressived sensing ,compressived sample,大意是在采集信号的时候(模拟到数字),同时完成对信号压缩之意. ...
- 【转】C# Socket编程(3)编码和解码
[转自:https://www.cnblogs.com/IPrograming/archive/2012/10/13/CSharp_Socket_3.html] 在网络通信中,很多情况下:比如说QQ聊 ...
- k8s api server ha 连接配置问题
常见的lb 负载有硬件的f5 big-ip ,同时对于互联网公司大家常用的是nginx haproxy 了解k8s 集群高可用的都知道 api server 是无状态的(etcd 解决了),但是 ...
- Redis、Memcache和MongoDB
一.Memcached Memcached的优点:Memcached可以利用多核优势,单实例吞吐量极高,可以达到几十万QPS(取决于key.value的字节大小以及服务器硬件性能,日常环境中QPS高峰 ...
- 记一次RESTful调试过程
1. 为什么前台怎么调用后台,都是跳到页面不存在. 因为已经改为RESTful,保存按钮的type还是submit: 2. 改成buttong之后,设置onclick="update()“, ...
- css学习笔记之图像
图像与文本的对齐方式: vertical-align:text-top;表示的意思是图像的顶部和同一行的文本对齐,但文本不会超出图片的上边线. vertical-align:middle;表示的意思是 ...
- 如何让公司从SVN改到Git?
把公司的SVN迁移到GitLab CE(GitLab社区版)原因主要有下面几个: 年青的新人进来,喜欢用git的越来越多 GitLab CE提供了优美的 web 界面,图形化分支结构,更直观的代码审查 ...
- PS相关技术
PS相关长时间不用就忘记了,做个笔记,记录下来 (1)复制图层,可以将图层复制到另外的图层里去,这样,多个图层就可以编辑了 (2)通过建立选区,可以选择右键,通过剪切的图层,通过复制的图层将图片抠出来 ...