zoukankan
html css js c++ java
用C#实现约瑟夫问题
using
System;
namespace
heut
{
class
Class1
{
public
static
void
Main()
{
int
[]a
=
new
int
[
8
];
int
sum
=
8
;
//
共有8个人;
int
k
=
3
;
//
每次数到3就退出;
int
count
=
0
;
//
记录退出的人数;
int
i
=
0
,j
=
0
;
for
(
int
m
=
0
;m
<
sum;m
++
)
a[m]
=
1
;
//
数组元素全部初始化为1;
while
(count
<
sum
-
1
)
{
if
(a[i]
!=
0
)
j
++
;
if
(j
==
k)
{
a[i]
=
0
;
count
++
;
j
=
0
;
//
重新开始,找下一个值!
}
i
++
;
if
(i
==
sum)
i
=
0
;
//
实现环(即围成一圈);
}
for
(
int
m
=
0
;m
<
sum;m
++
)
if
(a[m]
!=
0
)
Console.Write (m
+
1
+
"
\n
"
);
}
}
}
查看全文
相关阅读:
hdu-4123 Bob’s Race(树形dp+RMQ)
hdu-4126 Genghis Khan the Conqueror(最小生成树+树形dp)
hdu-4081 Qin Shi Huang's National Road System(最小生成树+bfs)
hdu-1233 还是畅通工程(最小生成树)
hdu-1102 Constructing Roads(最小生成树)
codeforces 569D D. Symmetric and Transitive(bell数+dp)
codeforces 569C C. Primes or Palindromes?(素数筛+dp)
codeforces 569B B. Inventory(水题)
修改ftp用户的目录
安装ftp服务器
原文地址:https://www.cnblogs.com/gmq/p/399885.html
最新文章
对于centos的运用ssh远程连接
修改自己的centos输入法
linux的centos设置静态网络
linux随笔2
linux开机随笔
linux一些目录功能
etc这个目录
对于静态变量和动态变量
Framework 的GC(垃圾回收机制)
Framework底层知识和概念
热门文章
B-TREE+(自平衡树)
JS-作用域链
JS-提高JS代码质量
JS(JQ)-实现图片横向滑动效果
js中arguments的用法
JS-数组操作
JS-面向对象-继承
JS-apply-call的使用
codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)
hdu-5358 First One(尺取法)
Copyright © 2011-2022 走看看