62,614
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ysfh
{
class Program
{
public const int m = 23;
static void Main(string[] args)
{
int r = m,a=1,s=1;
List<int> poped=new List<int>();
List<int> n = new List<int>{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
while (n.Count > 1)
{
for (int j = s; j <= n.Count;j++ )
{
if (a != r)
{
s = 1;
a++;
}
else
{
poped.Add(n[j-1]);
n.Remove(n[j-1]);
s = j;
a = 1;
break;
}
}
}
Console.WriteLine("出圈序列");
foreach (int ss in poped)
{
Console.WriteLine(ss);
}
Console.WriteLine("最後一個人");
foreach (int w in n)
{
Console.WriteLine(w);
}
Console.ReadLine();
}
}
}
//算法思想:m为人数,n为步长,所有人出列要进行m轮,每轮过后已经出列的人,不在新的一轮的判断之内(过滤掉)
public class CycleMan {
public static void main(String[] args) {
play(10000, 137);
}
//用于过滤
private static boolean same(int[] p,int m,int n){
for(int i=0;i<m;i++){
if(p[i]==n){
return true;
}
}
return false;
}
//算法执行体
public static void play(int playerNum, int step){
int[] p=new int[playerNum];
int counter = 1;//走过步数:counter
while(true){
if(counter > playerNum*step){//退出while,根据走过的步数
break;
}
for(int i=1;i<=playerNum;i++){
//过滤
while(true){
if(same(p,playerNum,i)==false)
break;
else
i=i+1;
}
if(i > playerNum)break;//退出for
//根据走过的步数和步长判断此人是否应该出列,若是则输出此人,并将其存入出列队列中,若不是继续走下去
if(counter%step==0){//counter代表已经走过的步数
System.out.print(i+" ");
p[counter/step-1]=i;
}
counter+=1;
}
}
System.out.println();
}
}
public static void main(String[] args) {
int a[] = { 1, 2, 3, 4, 5, 6 };
int i = 0;
int c = 0;
int M = 2;
int count = 0;
boolean has = true;
while (has) {
i++;
i %= a.length;
int ad = i - 1 < 0 ? a.length - 1 : i - 1;
if (a[ad] < 0) {
continue;
}
c++;
c %= M;
if (c == 0) {
has = ++count < a.length;
a[ad] = -a[ad];
System.out.println(-a[ad]);
}
}
}
import java.util.ArrayList;
import java.util.*;
public class Test1{
public static void to(int total, int number) {
List<Integer> list = new ArrayList<Integer>(total);
for(int i=1;i<=total;i++) {
list.add(i);
}
int j = 1;
int l = 1;
while(total > 0)
{
int k = list.size();
if(k==1)
{
System.out.println(list.get(0));
break;
}else{
if(l <=k )
{
if(j == number)
{
Integer in = (Integer)list.get(l-1);
System.out.println(in);
list.remove(in);
j = 1;
total--;
}else{
l++;
j++;
}
}else{
l = 1;
if(j == number)
{
Integer in = (Integer)list.get(l-1);
System.out.println(in);
list.remove(in);
j = 1;
total--;
}else{
l++;
j++;
}
}
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
Test1.to(10, 5);
}
}