NBUT
来源:互联网 发布:centos下载apache 编辑:程序博客网 时间:2024/04/29 15:20
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.
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.
5 1 25 2 2
2 44 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 Oneis 2,4,1,3,5. After the second operation, the sequence One is 4,3,2,1,5.So,output 4 3.
题意:n代表n个数1-n,经过m次把奇数位放在偶数位的后面的变化,输出经过m次变换后前X位。
思路:由于m比较大我们需要求出经过k次变化又变为原数列的周期T,然后由于X比较小所以我们更新的时候只需更新前X个就行了。
代码:
#include <iostream>#include<stdio.h>#include<cstdio>#include<iostream>#include<algorithm>#include<math.h>#include<string.h>#include<map>#include<vector>#include<deque>#define ll long long#define inf 0x3f3f3f3f#define mem(a,b) memset(a,b,sizeof(a))using namespace std;int a[1000001],n;int find_T(int x)//求周期T{ int pos=1; int k=0; while(1) { k++; if(x%2==1)//如果是奇数的话前面有偶数x/2个,奇数n+1/2个 { x=(x+n+1)/2; } else x=x/2;//偶数的话前面只有x/2个数 if(x==1)break; } return k;}int main(){ int m,k; while(~scanf("%d%d%d",&n,&m,&k)) { int T=find_T(1); m%=T; for(int i=1;i<=n;i++) { a[i]=i; } for(int i=1;i<=k;i++) { if(i!=1) printf(" "); for(int j=1;j<=m;j++) { if(a[i]*2<=n)//放偶数 { a[i]=2*a[i]; } else { a[i]=(a[i]-n/2)*2-1;//放奇数 } } printf("%d",a[i]); } printf("\n"); }}
- NBUT
- NBUT
- NBUT
- NBUT
- NBUT
- 【NBUT
- NBUT
- NBUT
- NBUT
- NBUT
- NBUT
- nbut 1475
- NBUT 1481
- NBUT 1552
- NBUT 1477
- NBUT 1450
- NBUT 1665
- NBUT 1647
- 开源的GIS
- 约束理论的聚焦五步骤
- java设计模式六大原则(6):开闭原则
- 指针的输入特性和输出特性
- 170409 汇编-转移指令,OD配置
- NBUT
- java编程思想-字符串
- SVN工具使用技巧
- python 中float转为4字节array存储
- 汇编12--端口
- MWC(2) Multiwii初学者详细准备
- 互联网协议入门(一)
- JDK 8 函数式编程入门
- Linux命令行与shell脚本编程大全