Joseph cicyle's algorithm】的更多相关文章

约瑟夫环问题: 输入:1)总共人数:2)每次被杀的序号数: 输出:最后一个活着的序号 python代码如下: n=int (input('please input the number of people:') ) k=int (input('please input the discard number:')) a=[] for i in range(n): a.append(i+1) print 'all the serial number of people:' print a i=0 j…
Joseph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2240    Accepted Submission(s): 1361 Problem Description The Joseph's problem is notoriously known. For those who are not familiar with the…
题意: 给出n, k,求 分析: 假设,则k mod (i+1) = k - (i+1)*p = k - i*p - p = k mod i - p 则对于某个区间,i∈[l, r],k/i的整数部分p相同,则其余数成等差数列,公差为-p 然后我想到了做莫比乌斯反演时候有个分块加速,在区间[i, n / (n / i)],n/i的整数部分相同,于是有了这份代码. #include <cstdio> #include <algorithm> using namespace std;…
Joseph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1652    Accepted Submission(s): 1031 Problem Description The Joseph's problem is notoriously known. For those who are not familiar with th…
Joseph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2094    Accepted Submission(s): 1273 Problem Description The Joseph's problem is notoriously known. For those who are not familiar with the…
Joseph问题似乎是入门题,就是那个报数出圈的问题,不过它暴力模拟的复杂度是O(nm)的,如果题目的数据范围达到了30000,那就超时了.怎么用线段树维护呢? 我们可以这么考虑,每次我们其实要查询在当前这个点过了m个人是哪一个人.我们需要维护一下当前序列中一共有多少人,还需要维护每个人实际的位置在哪(因为人们出圈了之后他就不占位置了) 我们可以用一棵权值线段树来完成. 首先是修改,这个没什么好说的,直接单点修改改成0就行,然后同时返回修改的位置,这是一个人出圈的位置.不过怎么找到这个位置呢?我…
题目传送门 /* 数学:约瑟夫环问题的变形,首先定义f[i]表示剩下i个人时,最后一个选出的人,有个公式:f[i] = (f[i-1] + m) % i f[1] = 0(编号从0开始),那么类似最后一个数的求法,先找到剩2个人和剩3个人时,最后的编号,然后跟着最后一个的一起递推 */ /************************************************ * Author :Running_Time * Created Time :2015-8-8 14:26:38…
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 50068   Accepted: 19020 Description The Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, . . ., n,…
链接:https://vjudge.net/problem/UVA-1363 题意:给出n  k,当 i 属于 1~n 时 ,求解 n% i 的和 n 和 k 的范围都是 1 到 10^9; 商相同 的余数数列 是 公差为商 的 递减等差数列 应该让k / i相等的一连串k % i相加,举个例子: 100 / 34 = 2 ... 32 100 / 35 = 2 ... 30 100 / 36 = 2 ... 28 ... 100 / 50 = 2 ... 0 递减等差数列通项公式:an=a1-…
Joseph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2126    Accepted Submission(s): 1291 Problem Description The Joseph's problem is notoriously known. For those who are not familiar with th…