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左右的点也求最 ...
随机推荐
- HTML5——动画延迟的另外一种方式
https://www.cnblogs.com/hhhhhh/p/5758167.html
- Harris角点检测原理详解
http://blog.csdn.net/lwzkiller/article/details/54633670 关于角点的应用在图像处理上比较广泛,如图像匹配(FPM特征点匹配).相机标定等.网上也有 ...
- 套接字、UDP通信、TCP通信、TCP/IP协议簇
一.套接字(socket) 1.英语单词socket:n.插座:穴:v.插入插座 2.套接字就是源IP地址和目的IP地址.源端口号和目的端口号的组合,是通过传输层进行通信的.IP指定电脑,端口指定某一 ...
- 结对项目--黄金点游戏(邓乐&曾亮)
#include<stdio.h> #include<stdlib.h> #include<Windows.h> int result[100][1000000]; ...
- 迅为电子4.3寸CAN总线工业平板电脑简介
型号:iTOP-HMI043-C 4.3寸CAN总线工业平板电脑支持CAN通讯显示器,显示:显示尺寸:4.3英寸:分辨率:480×272 TFT液晶 65536色 :接口:支持CAN 2.0B:USB ...
- oracle数据库使用hint来让模糊查询走索引
在没有创建数据直方图之前,查询优化器是cbo,可能不会选择代价最低(效率最高)的方式查询. 先创建表 --日语假名表 CREATE TABLE JAPANESE_SOUNDMARK ( ID INTE ...
- tomcat修改编码格式
在TOMCAT中的conf文件夹下server.xml中的 <Connector中添加两个设置useBodyEncodingForURI="true" //设置POST和GE ...
- print reverse <> 是打印全部的文件内容 ?
reverse 是倒置 <> 则是 把 @ARGV 参数列表里面的文件都读取出来 ? print <> 就是和 cat 的功能一样了. 脚本语言交流.数据处理 QQ群:66 ...
- CentOS 初体验十四:阿里云安装Gitlab
网址:https://about.gitlab.com/install/#centos-7 https://blog.csdn.net/zhaoyanjun6/article/details/7914 ...
- jenkins构建项目记录1
jenkins安装见上篇随笔 1.新建任务 2.构建一个自由风格的软件项目 3.源码管理设置 4.构建环境 5.构建 6.构建后操作