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
player 1, and so on. Then pick up the cards – place player 1′s cards on top, then player 2, and so on, so that player k’s cards are on the bottom. Each player’s cards are in reverse order – the last card that they were dealt is on the top,
and the first on the bottom.
How many times, including the first, must this process be repeated before the deck is back in its original order?
answers which will fit in a signed 64-bit integer.
10 3
52 4
0 0
4
13
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector> using namespace std; int n,m; typedef long long int LL; int next[880],to[880];
bool vis[880]; LL gcd(LL a,LL b)
{
if(b==0) return a;
return gcd(b,a%b);
} LL lcm(LL a,LL b)
{
return a/gcd(a,b)*b;
} int get_int()
{
char ch;
int ret=0;
while(ch=getchar())
{
if(ch>='0'&&ch<='9')
{
ret=ret*10+ch-'0';
}
else break;
}
return ret;
} int main()
{
while(true)
{
n=get_int();m=get_int();
if(n==0&&m==0) break;
if(n<=m)
{
puts("1"); continue;
}
///mo ni yi chi
for(int i=1;i<=n;i++)
next[i]=i;
for(int i=1;i<=m;i++)
{
to[i]=n/m;
if(i<=n%m) to[i]++;
to[i]+=to[i-1];
}
for(int i=1;i<=n;i++)
{
next[i]=to[(i-1)%m+1]--;
}
LL ans=1;
memset(vis,false,sizeof(vis));
for(int i=1;i<=n;i++)
{
if(vis[i]) continue;
int t=next[i];
LL temp=1;
while(t!=i)
{
vis[t]=true;
t=next[t];
temp++;
}
ans=lcm(ans,temp);
}
printf("%I64d\n",ans);
}
return 0;
}
HDOJ 4259 Double Dealing的更多相关文章
- hdu 4259 Double Dealing
思路: 找每一个数的循环节,注意优化!! 每次找一个数的循环节时,记录其路径,下次对应的数就不用再找了…… 代码如下: #include<iostream> #include<cst ...
- HDU 4259 - Double Dealing(求循环节)
首先将扑克牌进行一次置换,然后分解出所有的循环节,所有循环节的扑克牌个数的最小公倍数即为答案 #include <stdio.h> #include <string.h> #i ...
- 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) ...
- hdu 4529 Double Dealing (置换群)
# include <stdio.h> # include <algorithm> # include <string.h> using namespace std ...
- JVM Specification 9th Edition (4) Chapter 4. The class File Format
Chapter 4. The class File Format Table of Contents 4.1. The ClassFile Structure 4.2. Names 4.2.1. Bi ...
- 【HDOJ】1908 Double Queue
双端队列+二分. #include <cstdio> #define MAXN 1000005 typedef struct { int id; int p; } node_st; nod ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
- 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design
题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...
随机推荐
- Node.js——req、res对象
requset对象类型<http.IncomingMessage>,继承stream.Readable类 requset对象: req.headers req.rawHeaders req ...
- leetcode_357. Count Numbers with Unique Digits
https://leetcode.com/problems/count-numbers-with-unique-digits/ 给定一个n,计算[0,10^n]中十进制中每一位都不相同的数的数目. c ...
- CAD参数绘制椭圆(com接口)
在CAD设计时,需要绘制椭圆,用户可以设置椭圆的基本属性. 主要用到函数说明: _DMxDrawX::DrawEllipse 绘制椭圆.详细说明如下: 参数 说明 DOUBLE dCenterX 椭圆 ...
- Laravel Homestead的安装和使用(照搬)
原文:https://blog.csdn.net/woqianduo/article/details/81091154/ 1.简介 1.1.Homestead是什么 Laravel Homestead ...
- mysql 使用ip地址连接不上;MySQL 可以用localhost 连接,但不能用IP连接的问题,局域网192.168.*.* 无法连接mysql
原因: Mysql 默认是没有开启这个权限的(只允许使用 host:localhost,或者 host:127.0.0.1),如果想用 host:192.168.1.* (IP地址),来访问mysql ...
- JavaSE-17 泛型
学习要点 泛型接口 泛型类 泛型方法 多参数泛型类 泛型类的继承 泛型的定义 允许在定义类.接口.方法时使用类型形参,类型形参将会在声明变量.创建对象或者调用方法时候动态指定. 泛型接口 1 定义 ...
- android ViewPager实现的轮播图广告自定义视图,网络获取图片和数据
public class SlideShowAdView extends FrameLayout { //轮播图图片数量 private static int IMAGE_COUNT = 3; ...
- Python飞机大战实例有感——pygame如何实现“切歌”以及多曲重奏?
目录 pygame如何实现"切歌"以及多曲重奏? 一.pygame实现切歌 初始化路径 尝试一 尝试二 尝试三 成功 总结 二.如何在python多线程顺序执行的情况下实现音乐和音 ...
- 零基础入门学习Python(24)--递归:汉诺塔
知识点 这节课主要讲解用递归的方法,实现汉诺塔的解答 对于游戏的玩法,我们可以简单分解为三个步骤: 1) 将前63个盘子从X移动到Y上. 2) 将最底下的第64个盘子从X移动到Z上. 3) 将Y上的6 ...
- pop(),del A[:], a[:] = b[:]/'str'/可迭代的
s = ['a','ma','shi','ge'] s0 = s.pop(0) #---> 有返回值 print(s,s0) s1 = s.remove('shi') #---> 无返回值 ...