题目链接: POJ  1012: id=1012">http://poj.org/problem?id=1012 HDU 1443: pid=1443">http://acm.hdu.edu.cn/showproblem.php? pid=1443 约瑟夫环(百度百科): fr=aladdin" target="_blank">http://baike.baidu.com/view/717633.htm?fr=aladdin Descri…
题目 题意:一共有2k个人,分别为k个好人和k个坏人,现在我们需要每隔m个人把坏人挑出来,但是条件是最后一个坏人挑出来前不能有好人被挑出来..问最小的m是多少 约瑟夫环问题,通常解决这类问题时我们把编号设为从0~n-1. 求出每一轮出列的人:start = (start + m - 1) % n 模拟过程如下(以六个人,第五为例): 1 2 3 4 5 6 易发现start1 = (0 + 5 - 1)% 6 = 4, 即a[4] = 5这个人出列 #include <stdio.h> #in…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3089 题目大意:一共n人.从1号开始,每k个人T掉.问最后的人.n超大. 解题思路: 除去超大的n之外.就是个约瑟夫环的裸题. 约瑟夫环递推公式,n为人数,k为步长. f(1)=0 f(n)=[f(n-1)+k]%i  i∈[2,n] f(n)还要经过起始位置修正,设起始位置为s,即ans=[f(n)+s]%n. 基本约瑟夫环优化就是当k=1的时候,每次递推就是在+1,可以直接算出来快速跳过,f(…
Joseph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1512    Accepted Submission(s): 948 Problem Description   The Joseph's problem is notoriously known. For those who are not familiar with th…
简单说一下约瑟夫环:约瑟夫环是一个数学的应用问题:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到m的那个人出列:他的下一个人又从1开始报数,数到m的那个人又出列:依此规律重复下去,直到圆桌周围的人全部出列. 想要求出最后剩下的那个人的在初始的时候的编号的话. f[1]=0; f[i]=(f[i-1]+m)%i;  (i>1) 可以推出剩下i个人内叫到m的时候的编号.注意这是逆推.推到最后初始的时候的情况 #include<stdio.h>…
经典约瑟夫环 }; ; i<=n; i++) { f[i] = (f[i-] + k) % i; } 变形:k是变化的 #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <stdlib.h> #include <queue> #include <map> using namespace st…
首先看到这题脑子里立刻跳出链表..后来继续看如家的分析说,链表法时间复杂度为O(n*k),肯定会TLE,自己才意识到果然自个儿又头脑简单了 T^T. 看如家的分析没怎么看懂,后来发现这篇自己理解起来更容易(...)共享一下~http://blog.csdn.net/chenguolinblog/article/details/8873444 问题描述:n个人(编号0~(n-1)),从0开始报数,报到(m-1)的退出,剩下的人继续从0开始报数.求胜利者的编号. 编号0~(n-1)是有意义的,因为要…
Description Recently you must have experienced that when too many people use the BBS simultaneously, the net becomes very, very slow.To put an end to this problem, the Sysop has developed a contingency scheme for times of peak load to cut off net acc…
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…
/* * POJ_1591_2.cpp * * Created on: 2013年10月31日 * Author: Administrator */ #include <iostream> #include <cstdio> using namespace std; const int maxn = 55; int cards[25]; bool position[maxn]; int main(){ int participants,lucky; int counter = 1;…