思路:

找每一个数的循环节,注意优化!!

每次找一个数的循环节时,记录其路径,下次对应的数就不用再找了……

代码如下:

 #include<iostream>
#include<cstdio>
#include<stack>
#include<cstring>
#define ll __int64
using namespace std;
int vis[],to[],an[];
stack<int>p;
ll gcd(ll a,ll b)
{
if(a<b) swap(a,b);
while(b){
ll t=a;
a=b;
b=t%b;
}
return a;
}
int main()
{
int i,j,n,k,a,b;
ll ans,num;
while(scanf("%d%d",&n,&k)&&(n+k)){
j=;
while(!p.empty()) p.pop();
for(i=;i<=k;i++){
a=i;
while(a<=n){
p.push(a);
a+=k;
}
while(!p.empty()){
b=p.top();
to[b]=j++;
p.pop();
}
}
memset(vis,,sizeof(vis));
ans=;
for(i=;i<=n;i++){
if(vis[i]==){
num=;
a=to[i];
while(a!=i){
vis[a]=;
a=to[a];
num++;
}
ans=num/gcd(num,ans)*ans;
}
}
printf("%I64d\n",ans);
}
return ;
}

hdu 4259 Double Dealing的更多相关文章

  1. HDU 4259 - Double Dealing(求循环节)

    首先将扑克牌进行一次置换,然后分解出所有的循环节,所有循环节的扑克牌个数的最小公倍数即为答案 #include <stdio.h> #include <string.h> #i ...

  2. HDOJ 4259 Double Dealing

    找每一位的循环节.求lcm Double Dealing Time Limit: 50000/20000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  3. 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) ...

  4. hdu 4529 Double Dealing (置换群)

    # include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...

  5. hdu 1908 Double Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...

  6. HDU 1568 double 快速幂

    Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  7. 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 Descript ...

  8. HDU 1908 Double Queue(set)

    Problem Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in B ...

  9. HDU 4259

    虽然知道是置换,却很久没有思路.忽然想到,由初始状态A经过变换后回到A状态,应该是不停循环可重复的.于是,猜想数字的位置也是重复循环的.拿了个例子验证了一下,某然是这样.例如第二个10,3的例子有1- ...

随机推荐

  1. hdu 5146 Sequence

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5146 Sequence Description Today we have a number sequ ...

  2. umask设置导致的weblogic中的应用上传的文件没有权限打开

    去年,在公司的某一weblogic上部署的web应用上传文件后却没有读的权限.因为weblogic在Linux上部署,上传文件是mount到了一台安装了NFS的Windows Server上. 当时本 ...

  3. go again

    Introducation (1)How to organize go code (2)How to develope go package (3)How to use go tool How to ...

  4. 怎么解决/bin/sh: arm-linux-gcc: not found make

      1.arm-linux-gcc 环境变量没有设,所以找不到这个编译器 在/etc/profile里添加arm-linux-gcc的存放路径 sudo -s gedit /etc/profile 编 ...

  5. [转]IIS部署托管管道模式的集成和经典区别

    关于ESPS和SCSJ在Windows server 2008的问题总结 SCSJ出现的问题在于集成模式和经典模式的选择上,系统本身是没有问题的.我们在部署系统的时候,选择了集成模式,导致WebCon ...

  6. ALTERA MAX10官方评估板,新鲜出炉!

    刚刚拿到骏龙提供的ALTERA MAX10官方评估板,还热乎呢,呵呵!赶紧跟大家分享一下 板子很简单,把IO口都扩展出来了,其他功能基本上没有. FPGA型号是10M08SAE144C8GES,144 ...

  7. 20145129 《Java程序设计》第8周学习总结

    20145129 <Java程序设计>第8周学习总结 教材学习内容总结 NIO NIO使用频道(channel)来衔接数据节点,对数据区的标记提供了clear(),rewind(),fli ...

  8. 第三次作业,github的基本操作

    chengjiangtao@pc MINGW32 ~$ git config --global user.name "chengjiangtao" chengjiangtao@pc ...

  9. centos中设置apache显示目录列表

    apache中显示目录列表 在http.conf中加入如下代码(如有虚拟主机配置,加在虚拟主机配置段内),并把主目录内的index.pho,index.html,index.htm文件删除 复制代码  ...

  10. MySQL中表格各页面的注意和操作项