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 }
所以我是不是个傻逼。。。
是。。
NBUT 1225 NEW RDSP MODE I 2010辽宁省赛的更多相关文章
- NBUT 1218 You are my brother 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Little A gets to know a new friend, Little B, recently. On ...
- NBUT 1225 NEW RDSP MODE I
找出循环周期即可了 #include<bits/stdc++.h> using namespace std; int N,M,X; int time(int x,int y,int z) ...
- NBUT 1221 Intermediary 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ...
- NBUT 1224 Happiness Hotel 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The life of Little A is good, and, he managed to get enoug ...
- NBUT 1222 English Game 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB This English game is a simple English words connection gam ...
- NBUT 1220 SPY 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The National Intelligence Council of X Nation receives a ...
- NBUT 1219 Time 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Digital clock use 4 digits to express time, each digit ...
- NBUT 1223 Friends number 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Paula and Tai are couple. There are many stories betwee ...
- NBUT 1217 Dinner 2010辽宁省赛
Time limit 1000 ms Memory limit 32768 kB Little A is one member of ACM team. He had just won the g ...
随机推荐
- List<T>随机返回一个
/// <summary> /// 随机返回一条数据 /// </summary> /// <param name="list"></pa ...
- python 正则表达式匹配特定浮点数
def is_decimal(num): import re #以数字开头,小数点后保留1位数字或两位数字或者没有小数部分 dnumre = re.compile(r""" ...
- 刚创建的maven项目,pom.xml的第一行就报错
刚创建的maven项目,马上pom.xml的第一行就报错这是第一行:<project xmlns="http://maven.apache.org/POM/4.0.0" xm ...
- 【Golang】解决Go test执行单个测试文件提示未定义问题
背景 很多人记录过怎么执行Go test单个文件或者单个函数,但是要么对执行单文件用例存在函数或变量引用的场景避而不谈,要么提示调用了其它文件中的模块会报错.其实了解了go test命令的机制之后,这 ...
- Codeforces 447D - DZY Loves Modification
447D - DZY Loves Modification 思路:将行和列分开考虑.用优先队列,计算出行操作i次的幸福值r[i],再计算出列操作i次的幸福值c[i].然后将行取i次操作和列取k-i次操 ...
- Java 常用对象-System类
2017-11-02 21:41:06 System类:System 类包含一些有用的类字段和方法.它不能被实例化. *常用方法 public static void gc() 运行垃圾回收器. 调用 ...
- 枚举1--求小于n的最大素数
枚举1--求小于n的最大素数 总结: 素数是不能被比它小的素数整除. /* 枚举就是基于已有知识镜像答案猜测的一种问题求解策略 问题:求小于n的最大素数 分析: 找不到一个数学公式,使得根据N就可以计 ...
- React 介绍
ttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind The sm ...
- JavaScript的深拷贝和浅拷贝总结
深拷贝和浅拷贝 深拷贝:拷贝实例:浅拷贝:拷贝引用(原对象). 说深拷贝和浅拷贝之前,我先去了解了下高程书上的JavaScript的变量类型: 基本类型:undefined.null.Boolean. ...
- 『cs231n』绪论
笔记链接 cs231n系列所有图片笔记均拷贝自网络,链接如上,特此声明,后篇不再重复. 计算机视觉历史 总结出视觉两个重要结论:1.基础的视觉神经识别的是简单的边缘&轮廓2.视觉是分层的 数据 ...