标题:NKOJ 1144: 洗牌问题
只看楼主
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1026
专家分:177
注 册:2007-5-10
得分:0 
回复:(crystaljing)leeco 你讲的我都不懂啊,能不能...
你去看一下置换群啊
2007-07-28 21:19
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
得分:0 

我那个这么好明白怎么不采纳下,一样的通过了。


Fight  to win  or  die...
2007-07-28 22:29
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
得分:0 
以下是引用aipb2007在2007-7-28 22:29:05的发言:

我那个这么好明白怎么不采纳下,一样的通过了。


女侠,约吗?
2007-07-28 22:46
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1026
专家分:177
注 册:2007-5-10
得分:0 
回复:(aipb2007)我那个这么好明白怎么不采纳下,一...

我觉得你上面的思路有错啊,p位置的牌经过k次洗牌后回到p位置,不能证明所有的牌都回到了原来的位置。

2007-07-29 00:56
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
得分:0 
回复:(leeco)回复:(aipb2007)我那个这么好明白怎...

Yes, that is true. You need to prove it --- a math problem.

Thus for this problem, you only need to consider the nuber 1 --- see how it goes.


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-07-29 05:42
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
得分:0 
回复:(crystaljing)NKOJ 1144: 洗牌问题

My submitted C code. I think it should be ranked #1 there.

=================================

main()
{
int n, a, c;

while(scanf("%d", &n)!=-1)
{
a = 2;
c = 1;

while(a!=1)
{
if(a<=n)
a<<=1;
else
a=2*(a-n)-1;
++c;
}

printf("%d\n", c);
}
}


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-07-29 05:47
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
得分:0 
回复:(crystaljing)NKOJ 1144: 洗牌问题

My accepted C++ code --- completely simulates the shuffling process.

=================================================
#include <iostream>
using namespace std;

int a[200001], b[200001];

void shuffle(int*a, int *b, int n)
{
int i, i2;
for(i=1; i<=n; ++i)
{
i2=(i<<1);
b[i2] = a[i];
b[i2-1] = a[n+i];
}
}

int count(int n)
{
int i, c=0, n2=(n<<1);
bool bOrig = false;

for(i=1; i<=n2; ++i)
a[i] = i;

while(!bOrig)
{
shuffle(a, b, n);
++c;
bOrig = true;
for(i=1; i<=n2; ++i)
{
if(b[i] != i)
{
bOrig = false;
break;
}
}
if(bOrig)
break;

shuffle(b, a, n);
++c;
bOrig = true;
for(i=1; i<=n2; ++i)
{
if(a[i] != i)
{
bOrig = false;
break;
}
}
}

return c;
}

int main()
{
int n;

while(cin>>n)
cout<<count(n)<<endl;

return 0;
}


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-07-29 05:49
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
得分:0 
以下是引用HJin在2007-7-29 5:47:59的发言:

My submitted C code. I think it should be ranked #1 there.

=================================

main()
{
int n, a, c;

while(scanf("%d", &n)!=-1)
{
a = 2;
c = 1;

while(a!=1)
{
if(a<=n)
a<<=1;
else
a=2*(a-n)-1;
++c;
}

printf("%d\n", c);
}
}

NICE...


女侠,约吗?
2007-07-29 09:19
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
得分:0 
以下是引用HJin在2007-7-29 5:47:59的发言:

My submitted C code. I think it should be ranked #1 there.

=================================

main()
{
int n, a, c;

while(scanf("%d", &n)!=-1)
{
a = 2;
c = 1;

while(a!=1)
{
if(a<=n)
a<<=1;
else
a=2*(a-n)-1;
++c;
}

printf("%d\n", c);
}
}


Fight  to win  or  die...
2007-07-29 11:03
medicihophy
Rank: 1
等 级:新手上路
威 望:1
帖 子:102
专家分:0
注 册:2007-7-28
得分:0 
这个问题的置换群不好写啊,关键是所有置换都是定向的,怎么编谁教教,谢谢了!!!!

2007-07-29 11:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-158622-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049105 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved