NBUT 1225 NEW RDSP MODE I 2010辽宁省赛
Time limit 1000 ms
Memory limit 131072 kB
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.
Input
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.
Output
Sample Input
5 1 2
5 2 2
Sample Output
2 4
4 3
Hint
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. 题意是每次操作都会把偶数位置的数提出放到最前面来,然后操作次数很大,求操作后的序列前几位 先看一下我傻逼一样的超时代码
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std; struct node
{
int num;
int id;
}a[]; bool cmp(node b,node c)
{
return b.id<c.id;
} int main()
{
int n,m,k;
int i,j;
while(~scanf("%d%d%d",&n,&m,&k))
{
for(i=;i<=n;i++)
{
a[i].num=i;
a[i].id=i;
}
//找循环结
bool flag=true;
for(i=;i<=m;i++)
{
for(j=;j<=n;j+=)
a[j].id/=;
for(j=;j<=n;j+=)
a[j].id=(a[j].id+)/+n/;
sort(a+,a++n,cmp);
flag=true;
for(j=;j<=n;j++)
{
if(a[j].num!=j)
{
flag=false;
break;
}
}
if(flag)
break;
}
//取余
if(m!=i-)
{
m%=i;
//最后操作
for(i=;i<=n;i++)
{
a[i].num=i;
a[i].id=i;
}
for(i=;i<=m;i++)
{
for(j=;j<=n;j+=)
a[j].id/=;
for(j=;j<=n;j+=)
a[j].id=(a[j].id+)/+n/;
sort(a+,a++n,cmp);
}
printf("%d",a[].num);
for(i=;i<=k;i++)
printf(" %d",a[i].num);
printf("\n");
}
else
{
printf("%d",a[].num);
for(i=;i<=k;i++)
printf(" %d",a[i].num);
printf("\n");
}
}
return ;
}
再看一下我们女队楼主的超强代码
#include <iostream>
#include<stdio.h>
using namespace std;
#define maxn 1000000
int n;
int ci;
int a[maxn+];
int k;
int T(int x)
{
int c=;
int cnt=;
do{
if(c*<=n)
{
c*=;
}
else
{
c=(c-n/)*-;
}
cnt++;
}while(c!=);
return cnt;
}
int main()
{
while(~scanf("%d%d%d",&n,&ci,&k))
{
ci%=T(n);
for(int i=;i<=n;i++)a[i]=i;
for(int i=;i<=k;i++)
{ for(int j=;j<=ci;j++)
{
if(a[i]*<=n)
{
a[i]=*a[i];
}
else{
a[i]=(a[i]-n/)*-;
}
}
if(i==)cout<<a[i];
else cout<<" "<<a[i];
}
cout<<endl; }
return ;
52 }
所以我是不是个傻逼。。。
是。。
最新文章
- 现代3D图形编程学习-基础简介(1) (译)
- (转载)phpcms v9两步实现专题栏目生成路径去掉html和special
- 实现一个小目标,动动小指,分享可得iphone7/ipad/U盘|奥威软件
- 在不安装mysql-connector-net的情况下使用FluentData框架
- spring核心框架体系结构
- 手机Fildder抓包_监控应用请求
- 【PHP设计模式 03_JianDanGongChang.php】 简单工厂
- openfire消息通知推送
- BF-KMP 算法
- IOS UIView子类UIScrollView
- android发送/接收Json包含中文的处理
- 桂电在线-转变成bootstrap版
- Android Studio学习随笔-UI线程阻塞以及优化
- 打包静默安装参数(nsis,msi,InstallShield,InnoSetup)[转]
- Pyhon之常用操作符 - 零基础入门学习Python006
- Control character in cookie value, consider BASE64 encoding your value-Cookie保存中文出错[转]
- 移动端地图技术分享-- 百度高德SDK
- T——SQL基础语句(定义变量,赋值,取值,分支,循环,存储过程)
- vue学习笔记 样式 class style(五)
- Python分页组件
热门文章
- React native 的DatePickerIOS组件
- C# 集合-并发处理-锁OR线程 (转载)
- Could NOT find SDL (missing: SDL_LIBRARY SDL_INCLUDE_DIR)
- python - HTMLTestRunner 测试报告模板设置
- 关于C#中的日期的一个简单总结
- UEditor自动调节宽度
- Solaris 11, gcc 的安装
- [转]TOMCAT启动提示NB: JAVA_HOME should point to a JDK not a JRE解决
- 微信小程序自定义模态框(字体图标)
- 二、为什么要用MapReduce