hdu 4529 Double Dealing (置换群)

# include <stdio.h>
# include <algorithm>
# include <string.h>
using namespace std;
__int64 gcd(__int64 a,__int64 b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int main()
{
    int n,k,i,j,vis[810],m,num[810],x;
    __int64 res,cot;
    while(~scanf("%d%d",&n,&k),n+k)
    {
        m=1;
        for(i=1; i<=k&&i<=n; i++) //第一次分完牌
            for(j=(n-i)/k*k+i; j>0; j-=k)
                num[m++]=j;
        res=1;
        memset(vis,0,sizeof(vis));
        for(i=1; i<=n; i++)
        {
            if(vis[i])
                continue;
            x=i;
            cot=0;
            while(1)
            {
                vis[x]=1;
                cot++;
                x=num[x];
                if(i==x)
                    break;
            }
            res=res/gcd(res,cot)*cot;
        }
        printf("%I64d\n",res);
    }
    return 0;
}

时间: 2024-08-29 02:34:19

hdu 4529 Double Dealing (置换群)的相关文章

HDU 4259 Double Dealing(置换群啊)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4259 Problem Description Take a deck of n unique cards. Deal the entire deck out to k players in the usual way: the top card to player 1, the next to player 2, the kth to player k, the k+1st to player 1,

HDU 4259 Double Dealing【简单群置换】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4259 题目大意:给出n张卡片以及k个人,现在对卡片进行分堆,然后分发(这样卡片改变了顺序),依次这样问多少次后卡片顺序回到原来一样. 比如给出的10,3. 第一次分堆是这样的 第一人:1,4,7,10 第二人:2,5,8 第三人:3,6,9 其顺序由1 2 3 4 5 6 7 8 9 10 变成了 10 7 4 1 8 5 2 9 6 3 即: 10 3 第一次 10 7 4 1 8 5 2 9 6

HDOJ 4259 Double Dealing(置换群)

Double Dealing Time Limit: 50000/20000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1893    Accepted Submission(s): 672 Problem Description Take a deck of n unique cards. Deal the entire deck out to k players in

HDU 4259(Double Dealing-lcm(x1..xn)=lcm(x1,lcm(x2..xn))

Double Dealing Time Limit: 50000/20000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1924    Accepted Submission(s): 679 Problem Description Take a deck of n unique cards. Deal the entire deck out to k players in

HDU 1908 Double Queue&lt;Set&gt;

Problem Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of th

HDOJ 4259 Double Dealing

找每一位的循环节,求lcm Double Dealing Time Limit: 50000/20000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1806    Accepted Submission(s): 622 Problem Description Take a deck of n unique cards. Deal the entire deck out to

hdu 1908 Double Queue

题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using mod

POJ 3481 &amp; HDU 1908 Double Queue (map运用)

题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by

hdu 1908 double queues

http://acm.hdu.edu.cn/showproblem.php?pid=1908 看到有两个优先级,然后题目中又有queue...就想到了优先队列... 但是优先队列的cmp函数没搞懂,因为比较的是结构体,好像要重载< 什么的. 然而并不会. 其实用map就可以做... map在插入的时候可以自动按关键字排序,简直好评如潮! #include <algorithm> #include <cstdio> #include <iostream> #incl