NBUT 1225 NEW RDSP MODE I (规律+快速幂)
[1225] NEW RDSP MODE I
- 时间限制: 1000 ms 内存限制: 131072 K
- 问题描述
Little A has became fascinated with the game Dota recently, but he is not a good player. In all the modes, the rdsp Mode is popular on online, in this mode, little A always loses games if he gets strange heroes, because, the heroes are distributed randomly.
Little A wants to win the game, so he cracks the code of the rdsp mode with his talent on programming. The following description is about the rdsp mode:
There are N heroes in the game, and they all have a unique number between 1 and N. At the beginning of game, all heroes will be sorted by the number in ascending order. So, all heroes form a sequence One.
These heroes will be operated by the following stages M times:
1.Get out the heroes in odd position of sequence One to form a new sequence Two;
2.Let the remaining heroes in even position to form a new sequence Three;
3.Add the sequence Two to the back of sequence Three to form a new sequence One.
After M times' operation, the X heroes in the front of new sequence One will be chosen to be Little A's heroes. The problem for you is to tell little A the numbers of his heroes.
- 输入
- There are several test cases.
Each case contains three integers N (1<=N<1,000,000), M (1<=M<100,000,000), X(1<=X<=20).
Proceed to the end of file. - 输出
- For each test case, output X integers indicate the number of heroes. There is a space between two numbers. The output of one test case occupied exactly one line.
- 样例输入
5 1 2 5 2 2
- 样例输出
2 4 4 3
- 提示
In case two: N=5,M=2,X=2,the initial sequence One is 1,2,3,4,5.After the first operation, the sequence One is 2,4,1,3,5. After the second operation, the sequence One is 4,3,2,1,5.So,output 4 3.
- 来源
辽宁省赛2010
题意:1~N个数字组成数组A,将数组中奇数位组成一个数组B,偶数位组成一个数组C,然后将B连接到C后面,求执行M次,输出最后的前X位数。
分析:这道题可以理解成求一个数在M次变换之后最后的位置,那么首先就从两次变换的关系开始推导
假设本次的位置为X,分为偶数和奇数两种情况:
如果X为偶数,那么X下一次的坐标就会是X'=X/2,可以理解成前面有一半的奇数被拿走了,变换一下 X=2*X'
如果X为奇数,那么X下一次的坐标就会是X'=N/2+X/2,可以理解成前面有N/2个偶数,然后还有X/2个奇数排在X前面,变换一下 X=2*X' - N
可以发现,无论是奇数还是偶数,都是 X=2*X 之后对N取模,那么经过M次变换可以看成2的M次幂,这里写一个快速幂就行了。
还要注意,当N为偶数的时候要+1,因为N为偶数的时候,取模后下标可能为0,当N为奇数时,第N位数在变换中位置是不变的,所以情况和N-1一样。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<string> #include<iostream> #include<cstring> #include<cmath> #include<stack> #include<queue> #include<vector> #include<map> #include<stdlib.h> #include<algorithm> #define LL __int64 #define FIN freopen("in.txt","r",stdin) using namespace std; LL N,M,X; LL ans,tmp; LL pow(LL x,LL n,LL MOD) {LL res=1;while(n){if(n&1) res=(x*res)%MOD;x=(x*x)%MOD;n>>=1;}return res; } int main() {while(scanf("%I64d %I64d %I64d",&N,&M,&X)!=EOF){if(N%2==0) N++;tmp=pow(2,M,N);ans=tmp;printf("%I64d",tmp);for(int i=2;i<=X;i++){ans+=tmp;ans%=N;printf(" %I64d",ans);}printf("\n");}return 0; }
View Code
转载于:https://www.cnblogs.com/clliff/p/4738703.html
NBUT 1225 NEW RDSP MODE I (规律+快速幂)相关推荐
- NBUT - 1225~NEW RDSP MODE I(快速幂+倒推)
[1225] NEW RDSP MODE I 时间限制: 1000 ms 内存限制: 131072 K 问题描述 Little A has became fascinated with the gam ...
- NBUT 1225 NEW RDSP MODE I(找规律)(快速幂)
NEW RDSP MODE I 问题描述 Little A has became fascinated with the game Dota recently, but he is not a goo ...
- NBUT 1225 NEW RDSP MODE I
[1225] NEW RDSP MODE I 时间限制: 1000 ms 内存限制: 131072 K 问题描述 Little A has became fascinated with the gam ...
- NEW RDSP MODE I (快速幂)
题目: 问题 : NEW RDSP MODE I 题目描述 Little A has became fascinated with the game Dota recently, but he is ...
- Freda的访客 【找规律+快速幂】
题目描述 N 只小猫来到了Freda 的城堡做客!Freda 很高兴,拿出了蛋糕和饼干来招待它们,每一只小猫都可以吃到蛋糕或者饼干,当然,每只小猫具体拿到的是蛋糕还是饼干是由Freda 决定的. 小猫 ...
- NBUT1225 NEW RDSP MODE I(快速幂,规律):
G - NEW RDSP MODE I NBUT - 1225 题意: 给你三个数n,n,n,mmm,xxx.代表刚开始有1到n1 到n1到n刚好n个数,现在让你将序列变换mmm次,问你变换mmm ...
- NBUT1225 NEW RDSP MODE I(快速幂,规律)
题目: [1225] NEW RDSP MODE I 时间限制: 1000 ms 内存限制: 131072 K 问题描述 Little A has became fascinated with the ...
- 保研机试——2数学问题(简单数学、最大公约/最小公倍、分数运算、素数、质因子分解、快速幂、高精度问题、常见数学公式总结、规律神器OEIS)
1 简单数学 2 最大公约/最小公倍 3 分数运算 4 素数 5 快速幂 5 高精度问题 6 常见数学公式总结 7 规律神器OEIS 1 简单数学 (1)同余模定理:所谓的同余,顾名思义,就是许多的数 ...
- ZOJ3785 What day is that day? 快速幂+找规律
点击打开链接 It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are multi ...
最新文章
- 使用 Python 和 OpenCV 构建 SET 求解器
- Android View 测量流程(Measure)完全解析
- Android4.0.3 USB OTG底层插入上报过程分析(1)
- struts 模块化开发学习
- 架构师能力升级:掌握JVM科学调优
- CoreOS裸机安装步骤(亲测)
- 2019山东省赛总结
- 计算机之父图灵成为新50英镑“代言人”,吴恩达发推:Wonderful!
- PhotoShop CC 2017软件工具面板使用---快速选择工具
- 618大促,我把知识星球的价格调错了……
- 计算机网络之面试常考
- Problem A: 判断是否是素数
- 从Bugreport 解读 Android电量统计原理
- 微信小程序解密手机号码异常
- 开发人员不可不看的 OBD通讯协议知识
- 从头开始学习React
- ASP.NET MVC程序设计实验一:布局页和主页设计
- 小米时间选择控件_上海非凡教育分享UI组件设计解析之—— 单元控件
- 站外SEO从反向链接开始
- 【移动机器人|课程设计】Turtlebot3科大讯飞语音导航实现
热门文章
- Google-Guava(Utilites)
- github:master提交项目到远程仓库出现“There isn’t anything to compare.”
- switch的简单举例
- 十五数码难题 A*算法及深度优先算法实现
- 91sp.vido.ws index.php_Vidows
- 计算机高级 论文怎么考,干货丨如何在一个月内通过高级软考证
- MySQL入门学习的第一节(SQL语句)
- 【C语言】排序(8种排序方法)
- 【详细】小程序发微博功能实现
- 大数据、云计算、区块链、人工智能!你选择哪个?