思路:

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

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

代码如下:

 #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 3836 Equivalent Sets

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3836 Equivalent Sets Description To prove two sets A ...

  2. Learning note for Binding and validation

    Summary of my learning note for WPF Binding Binding to DataSet. when we want to add new record, we s ...

  3. 6.Inout双向端口信号处理方法

    Verilog中inout端口的使用方法 (本文中所有Verilog描述仅为展示inout端口的用法,实际描述则需要更丰富的功能描述) Inout端口的使用 在芯片中为了管脚复用,很多管脚都是双向的, ...

  4. UISegmentedControl swift

    // // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...

  5. 利用while(code!=EOF){}来实现“无限”循环

    #include <stdio.h>int main(){    char a,b,c;    char t;    while(scanf("%c%c%c",& ...

  6. JavaScript插入节点

    1. document.write("<p>This is inserted.</p>"); 该方法必须加在HTML文档内,违背了结构行为分离原则,不推荐. ...

  7. 微软职位内部推荐-Software Engineer II-Web app

    微软近期Open的职位: The Office App Services team is working on the powerful Office Web Apps including Word ...

  8. 小组开发项目针对性的NABC分析

    单独就我们团队开发项目——重力解锁的功能特点而言,我们解决了智能手机屏幕解锁的乏味和繁琐的特点,显得更有趣味性和独特性,更符合现代人追随时尚的潮流:我们根据个人的不同喜好和便利性来设定一些动作,利用重 ...

  9. android开发支付宝接口开发流程(密钥篇)

    参考博客:http://blog.it985.com/12276.html 官方下载地址:http://download.alipay.com/public/api/base/WS_MOBILE_PA ...

  10. android开发 实现同时显示png/jpg 等bitmap图片还可以显示gif图片,有效防止OOM

    本来使用第三方jar包 GifView.jar  发现使用的时候不能显示png图片,而且多次setgifimage的时候还会OOM: 现在使用了一个新的第三方,demo是别人的, 下载链接:http: ...