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
How many times, including the first, must this process be repeated before the deck is back in its original order?
#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 chifor(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;
}
转载于:https://www.cnblogs.com/zhchoutai/p/8525481.html
HDOJ 4259 Double Dealing相关推荐
- HDU 4259 Double Dealing【简单群置换】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4259 题目大意:给出n张卡片以及k个人,现在对卡片进行分堆,然后分发(这样卡片改变了顺序),依次这样问 ...
- HDU4259(简单群置换)
题目:Double Dealing #include <iostream> #include <string.h> #define LL long long const int ...
- 【HDOJ】4579 Random Walk
1. 题目描述 一个人沿着一条长度为n个链行走,给出了每秒钟由i到j的概率($i,j \in [1,n]$).求从1开始走到n个时间的期望. 2. 基本思路 显然是个DP.公式推导也相当容易.不妨设$ ...
- 【hdoj】3007 Buried memory 【计算几何--最小圆覆盖】
传送门:Buried memory 苍天饶过谁,第三次在hdoj上 交计算几何的题了,没一次是AC的. ┭┮﹏┭┮都是模板题啊,我都是抄板子的啊,为什么会这样,我怎么这么菜. 题意: 求最小圆覆盖 的 ...
- 二分搜索 HDOJ 2289 Cup
题目传送门 1 /* 2 二分搜索:枚举高度,计算体积与给出的比较. 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #in ...
- 双拓扑排序 HDOJ 5098 Smart Software Installer
题目传送门 1 /* 2 双拓扑排序:抄的,以后来补 3 详细解释:http://blog.csdn.net/u012774187/article/details/40736995 4 */ 5 #i ...
- BZOJ 4259: 残缺的字符串 [FFT]
4259: 残缺的字符串 题意:s,t,星号任意字符,匹配方案数 和上题一样 多乘上一个\(a_{j+i}\)就行了 #include <iostream> #include <cs ...
- 【HDOJ】【3853】LOOPS
概率DP/数学期望 kuangbin总结中的第7题 其实跟UVA 11762 Race To 1 那道题差不多--直接推下公式,然后倒推即可 Trick:有的点可能是p1[i][j]==1--这样的点 ...
- Hdoj 2671 Can't be easier
Hdoj 2671 Can't be easier 简单的数学问题: 如果两点异侧直接求距离,同侧则先求出其中一点的对称点后用距离公式 #include<iostream> #includ ...
最新文章
- 开发三年,如何摆脱日复一日的CRUD?
- python多个日志模块怎么隔离_在多个模块中使用Python日志logging
- 操作系统内存管理-Linux版
- spring_在Spring中使用多个动态缓存
- 黑马在线教育项目---5、使用填充器创建数据库数据
- matlab怎么在c 中调用,在C中调用Matlab (转)
- python三维数组怎么表示_python – numpy中的三维数组
- datatable如何生成级联数据_如何把Excel表数据批量生成条形码
- wxpython控件绑定事件_wxPython事件处理
- mtensor一个tensor计算库,支持cuda延迟计算
- java并发编程之HappenBefore
- html5+css3第一次作业_老娘我,饿死也不要陪孩子做手工作业,高考陪考真香!...
- 小白学习使用gitee问题产生汇总(持续更新)
- setfacl 权限导出_setfacl getfacl 将某个目录的访问权限赋值给某个用户
- 阿里巴巴设计大会PPT,出彩的设计让人惊叹
- 第1章 ADAMS/View 基础知识
- java在浏览器闪退_Edge浏览器闪退怎么办,Edge浏览器闪退如何修复
- html制作windows 10,Windows 10迎来Alpha版HTML编辑器应用
- 几何学五大公理_几何学的五个公理是什么?
- 超赞 不愧是美团内部的JVM学习手册,从头到尾全是精华