Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array(找规律)

大模型的安全发展与安全治理 2022 年底,OpenAI 推出的 ChatGPT 在文本生成领域实现了重大突破,引领了大模型技术的发展方向,推动了各式各样的基座大模型及行业大模型的发展,并逐步向多模态和具身化方向迅速演进。显然,大模型展现出的强大能力为人工智能通用化揭开了序幕。然而,大模型技术的安全性也面临着生成内容的安全性、伦理道德等重大挑战。只有积极确保大模型的安全性,才能更有效地推动其持续发展,进而更好地应对大模型技术变革所带来的机遇与挑战。 阅读详情

D. A Leapfrog in the Array
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm.

Let’s consider that initially array contains n numbers from 1 to n and the number i is located in the cell with the index 2i - 1 (Indices are numbered starting from one) and other cells of the array are empty. Each step Dima selects a non-empty array cell with the maximum index and moves the number written in it to the nearest empty cell to the left of the selected one. The process continues until all n numbers will appear in the first n cells of the array. For example if n = 4, the array is changing as follows:

You have to write a program that allows you to determine what number will be in the cell with index x (1 ≤ x ≤ n) after Dima’s algorithm finishes.
Input

The first line contains two integers n and q (1 ≤ n ≤ 1018, 1 ≤ q ≤ 200 000), the number of elements in the array and the number of queries for which it is needed to find the answer.

Next q lines contain integers xi (1 ≤ xi ≤ n), the indices of cells for which it is necessary to output their content after Dima’s algorithm finishes.
Output

For each of q queries output one integer number, the value that will appear in the corresponding array cell after Dima’s algorithm finishes.
Examples
Input
Copy

4 3
2
3
4

Output

3
2
4

Input
Copy

13 4
10
5
4
8

Output

13
3
8
9

Note

The first example is shown in the picture.

In the second example the final array is [1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7].

比赛时理解错题意了,以为询问的是数字最终的位置,最后写完了过第二个例子的时候才发现不是.
贴份代码纪念一下把(也不知道对不对0.0)

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
const int N=2e5+100;
int arr[N];
vector<int>G[N];
int main()
{
    ll n,q;
    cin>>n>>q;
    while(q--)
    {
        ll a;
        cin>>a;
        ll j=(n-a+1)*2;
        j-=1;
        ll pre=1;
        a=a*2-1;
        ll k=a;
        while(1)
        {
            if(k<=n)
            {
                cout<<k<<endl;
                break;
            }
            //cout<<pre+j<<endl;
            k=a-j-pre;
            pre=j+pre;
            j*=2;
        }
    }
    return 0;
}

正解:打表找规律,
这是一份打表的代码,还是比较容易写的

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
const int N=2e5+100;
int arr[N];
vector<int>G[N];
int main()
{
    ll n,q;
    cin>>n;
    // mx=n;
    memset(arr,-1,sizeof arr);
    rep(i,1,2*n)
    {
        if((i+1)%2==0)
            arr[i]=(i+1)/2;
    }
    int i=2*n-1,j=2*n-2;
    while(j>=1)
    {
        while(arr[j]!=-1&&j>=1)
            j--;
        arr[j]=arr[i];
        i--;
    }
    rep(i,1,2*n)
    cout<<arr[i]<<' ';
    cout<<endl;
     j=n;
    while(j)
    {
        cout<<j*2<<endl;
        rep(i,1,2*n)
        {
            if(arr[i]==j)
                cout<<2*j-i<<' ';
        }
        cout<<endl;
        j--;
    }

    return 0;
}

找过规律之后发现,奇数下标存放的数是不发生移动的,偶数的移动也是有规律的,刚开始是n-x/2,之后就是前者/2,所以代码就出来了

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
const int N=2e5+100;
int arr[N];
vector<int>G[N];
int main()
{
    ll n, q, x;
    cin >> n >> q;
    while(q--)
    {
        cin >> x;
        if (x % 2)
        {
            cout << x/2+1 << endl;
        }
        else
        {
            ll t = n - x/2;
            while(t % 2 == 0)
            {
                x += t;
                t /= 2;
            }
            cout << (x+t)/2+1 << endl;
        }
    }
    return 0;
}
基于深度确定性策略梯度的永磁同步电机强化学习控制方法 本文提出了一种基于深度确定性策略梯度(DDPG)的永磁同步电机(PMSM)电流内环智能控制方法。首先建立了PMSM在d-q坐标系下的数学模型,分析了传统矢量控制双闭环系统中PI控制器的局限性。针对电流内环控制问题,设计了包含电流跟踪误差、转速信息和历史控制量的状态空间,将电压输出作为动作空间,并构建了兼顾跟踪精度和响应速度的奖励函数。通过DDPG算法训练智能体,使其能够自适应调整控制策略。仿真结果表明,与固定参数的PI控制器相比,DDPG控制器在动态响应速度和抗干扰能力方面具有明显优势,为PMSM高性能控制 阅读详情

相关推荐

基于PlatformIO与CMSIS的STM32库函数开发实战:从环境搭建到外设驱动

本文详细介绍了基于PlatformIO与CMSIS的STM32库函数开发实战,从环境搭建到外设驱动实现。通过对比传统IDE,PlatformIO结合CMSIS框架在跨平台开发、代码可移植性和调试体验上更具优势。文章包含PlatformIO.ini配置详解、GPIO/USART驱动开发实例及常见问题解决方案,帮助开发者高效完成STM32项目开发。

weixin_29190169的博客 429

NYOJ - 擅长排列的小明 II

擅长排列的小明 II 时间限制:1000 ms  |           内存限制:65535 KB 难度:3 描述 小明十分聪明,而且十分擅长排列计算。 有一天小明心血来潮想考考你,他给了你一个正整数n,序列1,2,3,4,5......n满足以下情况的排列: 1、第一个数必须是1 2、相邻两个数之差不大于2 你的任务是给出排列的种数。 输入多组数据。每组数据中输

SevenMIT的专栏 1535

ENSP内使用wireshark进行抓包,并且解析icmp报文

前四位:54 89 98 e8 20 38 为ip报文包的mac地址也就是物理地址。一开始进行抓包是没有icmp报文的,需要我们在ensp中使用pc1请求联通pc9。协议编号后分别为:ip版本、ip首部报文长度、服务类型、ip报文总长度。最后为校验和 、源ip地址、目的ip、从08 00开始为真正的数据。我们需要实验的端口为:0/0/4,也就是抓包第三个交换机内的报文。其中显示的icmp报文就是我们需要解析的ip报文。源mac地址后跟着的就是协议编号: 08 00。根据ip报文包的结构我们进行解析。

2301_81713278的博客 2146

Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array【规律】

D. A Leapfrog in the Array time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Dima is a beginner programmer. D

Haipai1998的博客 326

webview腾讯x5内核离线安装

离线集成腾讯TBS浏览器服务,彻底解决官方下载限流问题,永久免费

观千剑而后识器,操千曲而后晓声。 7941

告别盲调!用Synopsys VIP搭建PCIe 5.0验证环境,手把手搞定链路训练与均衡调试

本文详细介绍了基于Synopsys VIP搭建PCIe 5.0验证环境的实战指南,重点解析了链路训练(LTSSM)与均衡调试的关键技术。通过配置VIP组件、设计验证平台架构及实战调试技巧,帮助工程师高效解决PCIe 5.0验证中的常见问题,提升芯片验证效率与可靠性。

weixin_28700411的博客 467

codeforces 950 #469 div2 D A Leapfrog in the Array

Problem codeforces.com/contest/950/problem/D Reference Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array (思维) Meaning 开始时将 n 个数 1 ~ n 放在一个数组里,数 i 放在下标为 2i−12i−12i-1 的格(下标从 1 开始)。 然后进行移...

iTom's blog 778

抖音小游戏上架避坑指南:从软著申请到ICP备案全流程解析

本文详细解析了抖音小游戏上架前必须完成的软著申请和ICP备案全流程,提供了清晰的时间线规划与实操避坑指南。文章重点阐述了个人与企业备案的区别、材料准备要点以及平台审核常见问题,旨在帮助独立开发者和小团队高效、合规地完成游戏上架,避免在行政流程中延误项目。

weixin_29276847的博客 1643

Codeforces Round #469 (Div. 2) D - A Leapfrog in the Array 推规律+递归

思路:根据题意推规律,发现最初前面的(n/2)个数字的位置不变,也就是最后时候奇数下标位置的数字还是原来顺序的;后面的(n/2)个数字相当于在后面变化得到最终结果后平移到前面的空缺位置处,稍微一推会发现,n个数字进行题中变化,跟1~n进行变化数字相对位置是一样的,可以递归求解;至于n是奇数还是偶数时,可以再推出递归n的大小,题解后面有推导样例;#include&lt;bits/stdc++.h&g...

床前明月光 306

工具变量三连检全解析:识别不足、弱工具变量与过度识别

因果推断是实证研究的核心追求,而工具变量法则是在内生性困扰下获取可信因果效应的关键武器。在实际操作中,研究者常借助Stata软件执行两阶段最小二乘估计,但面对输出结果中繁杂的统计量,如何解读识别不足检验、弱工具变量诊断与过度识别限制检验,成为区分严谨实证与“跑回归”的分水岭。理解这些检验的统计学原理:识别不足检验通过LM统计量考察工具变量与内生变量的相关性;弱工具变量诊断借助CDW统计量评估第一阶段解释力;过度识别检验利用Hansen J统计量判断多余工具变量的外生性。掌握它们在异方差、聚类稳健标准误下的适

weixin_30119911的博客 268

基于PointNet++网络的点云数据分类仿真分析

局部特征学习模块用于学习点云中每个点的局部特征表示,而全局特征学习模块用于学习整个点云的全局特征表示。点云数据分类是指将点云数据分为不同的类别或标签。PointNet++是一种用于点云数据处理的深度学习网络,它能够有效地学习点云数据的特征表示并实现高精度的分类。在本文中,我们将使用MATLAB实现基于PointNet++网络的点云数据分类仿真分析,并提供相应的源代码。然后,我们使用splitEachLabel函数将数据划分为训练集和测试集,其中80%的数据用于训练,20%的数据用于测试。

HackDashX的博客 212

Codeforces Round #469 D. A Leapfrog in the Array【思维】

题目链接 题意 一个序列初始为 1_2_3_..._n−1_n1\_2\_3\_...\_n-1\_n1_2_3_..._n−1_n(_为空),每次操作会把最后一个数往左移到第一个空,操作持续到无法移动为止(即1~n把前面全占满,没有空了), qqq 次询问位置 PPP 的值 (1≤P≤n1\le P \le n1≤P≤n) 操作如下图所示 题解 感性的理解一下,操作到最后,1~n 奇数位上的数是没有移动过的,因为 处理到 n2\cfrac{n}{2}2n​ 时,序列长这样:1_2_3_.._n2abcd

qq_50554695的博客 182

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array (思维)

题目大意:最开始n个数字中的数字i在位置2*i-1,之后从右向左依次用数字将该列填充。最后q个query问你pos为Xi该填上什么数字。 解析:首先n范围1e18,直接模拟肯定不行,但肯定有什么规律在里面,我们自己写写看n=6的时候,1~6位置分别为1 4 2 6 3 5,n=3的时候1~3位置分别为1 3 2,这里我们可以明显的发现,当Xi&amp;1时,该位置最后的数字就是Xi/2+1。...

喵喵喵? 1256

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array(思维+math)

D. A Leapfrog in the Arraytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDima is a beginner programmer. During his working process, he regularly ...

sher杨的博客 198

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Codeforces Round #469 (Div. 2) D题 A Leapfrog in the Array (思维)

题目 样例 题意 一个长度为2*n的数组,奇数位上依次是1 2 3 4 5 6……,也就是每放一个数字空一个格子,然后每次操作我们都会把最右边的一个数字,放到最右边的一个被两个数字夹着的空格,直到没有被夹着的空格存在为止。 然后问你,停止后,数组上pos位置的数字是多少。 思路 2*n长度的数组,n个数字,最后停下来,肯定是前n的空格被占用,后n个不被占用。 ① 对于这前n个数字,我们知道如果p...

Authur_gyc 196

Codeforces Round #469 (Div. 2) D A Leapfrog in the Array

题意:给出1-n数字它们的位置都是奇数索引,之后最右边的数字填入空白索引,直至1-n数字之间无空白索引思路:对于一个询问q,如果q是奇数,那么答案就是(q-1)/2,否则将不断q=q/2+n即可 来源:http://blog.csdn.net/xiangAccepted/article/details/79506332#include &lt;bits/stdc++.h&gt; typedef ...

深海沧澜的博客 235

Codeforces Round #469 (Div. 2) D 数学递归 E SCC缩点

Codeforces Round #469 (Div. 2) D. A Leapfrog in the Array 题意:n 个数,一开始按图1 放置,每次操作可以把最后的一个数移到最后的一个空格里。有 q 个询问,每次询问有 xi,问最后不能移动时,第 xi 个位置是什么数。 tags:从 xi 位置往后面推,每次移到奇数位置或偶数位置。 // 469 D #includ...

weixin_30871701的博客 146

D. A Leapfrog in the Array Codeforces Round #469 (Div. 2)

题目链接:http://codeforces.com/contest/950/problem/D 参考链接:https://blog.csdn.net/xiangAccepted/article/details/79506332 所得:我原本是找单个样例的规律,但是找出来后发现还是会超时,看了上面的参考链接后发现,原来最省事的规律是在一系列样例之间找规律 #include &lt;bits/...

凝望的博客 214

Codeforces Round #469 (Div. 2) ——D. A Leapfrog in the Array

题意:1~n的数按顺序间隔排列,(1  2  3  4  ...  n) 中间的空格也要占一位,现在有一种操作,每次把序列最后面那个数移到离它最近的空格里面,直到前n个位置都被填满,没有空格了。给出q次查询,每次输入一个数 Xi,要求输出按照所给操作完成后的Xi位置上的数是多少。 题解:题目上给的数据范围超级大(1e18),所以肯定是不能模拟的,一定有什么规律在里面。首先很容易发现,不是根本不用...

wookaikaiko的博客 259

Codeforces Round #469 (Div. 1) B. A Leapfrog in the Array(dfs)

题目链接:http://codeforces.com/contest/949/problem/B理性分析之后,发现直接dfs就可以了代码:#include&lt;bits/stdc++.h&gt; using namespace std; typedef long long ll; ll n; ll dfs(ll now) { if(now&amp;1==1) return (now+1)/...

bibibibi的博客 246

Codeforces Round #469 (Div. 2)D. A Leapfrog in the Array(递推)

D. A Leapfrog in the Array time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard output Dima is a beginner programmer. During his working process, he r

swust5120160705的博客 312

Codeforces Round #469 (Div. 2)A,B,C,D

A. Left-handers, Right-handers and Ambidexterstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are at a water bowling training. There are l peop...

坚持迟早会有收获的!!! 744

Manthan, Codefest 16 633C Spy Syndrome 2

题目链接 大意:给出一个字符串, 还原这个字符串为原句, 将此字符串拆分为一个个的单词, 如果与下面给出的m个单词相匹配, 则该单词为原句单词, 要求原字符串全部匹配. 解析: dfs有两种思路:第一种代码如下 #include #define ll long long #define pb push_back #define inf 0x3f3f3f3f using namespa

城南的花 798

Codeforces Round #297 (Div. 2) 525E Anya and Cubes(折半查找+map)

题目链接 题意:给出n个棍子, k个魔法棒, 目标数s. 魔法棒可以使得棍子长度变为棍子长度的阶乘, 问木棒和为s的方案数. 预处理求出阶乘, 根据s范围可知木棒最长是18, 而后进行dfs, dfs时, 分为三种情况, 取这根木棒, 不取这根木棒, 以及取这根木棒的阶乘. 进行两次dfs, 折半存储结果.,这次map开了两维,其实这种思想用的很多,比如区间求中位数,以后多多注意下。 详

城南的花 698

Codeforces 920F - SUM and REPLACE(线段树)

题意:给你n个数,进行m次操作,分别是将区间[l,r]内的所有数替换成自己的因子数 和 对区间[l,r]进行求和。 题解: 调试了一下午,原来是运算符号优先级的问题。或运算符和+不要一起用 解析:线段树问题,但是直接做的话会超时,所以要加一个优化,可以发现2的因子个数还是2,1的因子个数还是1,所以如果某个数被更新成1或者2之后就不需要再进行更新了。 这里给张线段树的图 代码: #

城南的花 665
上一篇: Bandwidth UVA - 140(next_premutation)
下一篇: Educational Codeforces Round 39 (Rated for Div. 2) D. Timetable(动态规划)
ffgcc
博客等级 码龄9年 32粉丝 296原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值