Where there is a dream ,there is hope
C++博客
::
首頁
::
聯系
::
聚合
::
管理
64 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks
常用鏈接
我的隨筆
我的評論
我參與的隨筆
留言簿
(1)
給我留言
查看公開留言
查看私人留言
我參與的團隊
隨筆分類
C#(2)
C/C++(19)
EFFECTIVE-STL學習筆記(3)
Mono
monodevelop
TCP/IP(1)
翻譯文章(4)
算法/數據結構(1)
折騰UBUNTU(2)
職業人生(1)
隨筆檔案
2011年11月 (1)
2011年10月 (7)
2011年9月 (2)
2011年8月 (7)
2011年7月 (3)
2011年6月 (5)
2011年4月 (2)
2011年3月 (5)
2011年2月 (8)
2011年1月 (1)
2010年12月 (7)
2010年11月 (9)
2010年10月 (4)
2010年7月 (3)
收藏夾
生活思考(1)
C++
C#講師-設計模式-數據結構
范懷宇
韓湘子
專門解決各種C++疑難雜癥
搜索
最新評論
1.?re: 匿名空間
.就空間看快樂
--何霞飛
2.?re: 匿名空間
u厲害
--何霞飛
3.?re: 服務器設計-轉
這種文章挺少的噢。不是做服務器的,多了解一些總是好的。設計真是一門有意思的學問。
--K.V
4.?re: josephon問題
不過這個模擬過程非常不好,對于100000以上的人數來說簡直就是悲劇。。。
--Husiwa
5.?re: 簡潔的字符串連接函數
@木頭奎
的確有缺點,但這個函數的實現過程還是有其發作的
--Husiwa
閱讀排行榜
1.?轉載:vector find(2386)
2.?vector 查找指定元素(1783)
3.?C#結構體序列化(1275)
4.?windows.h與winsock2.h的包含順序(1168)
5.?模板類靜態變量初始化(1129)
評論排行榜
1.?簡潔的字符串連接函數(2)
2.?匿名空間(2)
3.?C++指針探討 (一)數據指針(1)
4.?josephon問題(1)
5.?服務器設計-轉(1)
josephon問題
看到首頁上有人寫,自己也寫了一個
名字起錯了,其實寫個stack更合適
//
!Node information
//
!
struct
Node
{
int
serialNumber;
int
flag;
struct
Node
*
next;
}
;
struct
List
{
Node
*
head;
List()
{
head
=
NULL;
}
~
List()
{
if
(head
==
NULL)
{
return
;
}
Node
*
p
=
head;
Node
*
q
=
head
->
next;
while
(q
!=
NULL)
{
delete p;
p
=
q;
q
=
q
->
next;
}
delete p;
p
=
NULL;
}
void
init(
int
size)
{
int
i
=
1
;
while
(i
<=
size)
{
push(size
-
i
+
1
);
i
++
;
}
}
//
! the last one is the head
void
push(
int
i)
{
Node
*
pNew
=
new
Node();
pNew
->
serialNumber
=
i;
pNew
->
flag
=
1
;
pNew
->
next
=
head;
head
=
pNew;
}
void
showAll()
{
if
(head
==
NULL)
{
return
;
}
Node
*
temp
=
head;
while
(temp)
{
if
(temp
->
flag
==
1
)
{
printf(
"
%d
"
, temp
->
serialNumber);
}
temp
=
temp
->
next;
}
printf(
"
\n
"
);
}
int
pop()
{
int
result
=
0
;
if
(head
==
NULL)
{
return
result;
}
Node
*
temp
=
head;
result
=
head
->
serialNumber;
head
=
head
->
next;
delete temp;
return
result;
}
void
kickOut(
int
circleNum,
int
liveNum)
{
Node
*
temp
=
head;
while
( lenLive()
>
liveNum )
{
for
(
int
i
=
0
; i
<
circleNum;i
++
)
{
if
(temp
->
flag
==
0
)
{
i
--
;
}
if
(i
==
( circleNum
-
1
)
&&
temp
->
flag
==
1
)
{
temp
->
flag
=
0
;
}
temp
=
temp
->
next;
if
(temp
==
NULL)
{
temp
=
head;
}
}
showAll();
printf(
"
\n
"
);
}
}
int
len()
{
if
(head
==
NULL)
{
return
0
;
}
Node
*
temp
=
head;
int
count
=
0
;
while
(temp)
{
count
++
;
temp
=
temp
->
next;
}
return
count;
}
int
lenLive()
{
if
(head
==
NULL)
{
return
0
;
}
Node
*
temp
=
head;
int
count
=
0
;
while
(temp)
{
if
(temp
->
flag
==
1
)
{
count
++
;
}
temp
=
temp
->
next;
}
return
count;
}
}
;
//
main.cpp
#include
<
stdio.h
>
#include
<
stdlib.h
>
#include
"
list.h
"
int
main()
{
int
size
=
0
;
while
(
true
)
{
List liveList;
scanf(
"
%d
"
,
&
size);
liveList.init(size);
printf(
"
liveList len: %d \n
"
, liveList.len());
liveList.kickOut(
3
,
2
);
liveList.showAll();
}
return
0
;
}
posted on 2011-03-16 10:58
IT菜鳥
閱讀(379)
評論(1)
編輯
收藏
引用
Feedback
#
re: josephon問題
2011-03-16 11:31
Husiwa
不過這個模擬過程非常不好,對于100000以上的人數來說簡直就是悲劇。。。
回復
更多評論
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
【推薦】100%開源!大型工業跨平臺軟件C++源碼提供,建模,組態!
網站導航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
Copyright @ IT菜鳥
Powered by:
.Text
and
ASP.NET
Theme by:
.NET Monster
2020久久精品亚洲热综合一本
|
天堂无码久久综合东京热
|
91久久精一区二区三区大全
|
国产精品久久久久久久久
|
久久久91人妻无码精品蜜桃HD
|
亚洲中文字幕无码一久久区
|
精品乱码久久久久久夜夜嗨
|
狠狠色婷婷久久综合频道日韩
|
香蕉久久夜色精品国产小说
|
777午夜精品久久av蜜臀
|
99久久精品国产综合一区
|
精品国产婷婷久久久
|
久久综合精品国产二区无码
|
久久久久久久亚洲精品
|
91精品国产色综合久久
|
无码任你躁久久久久久老妇
|
91精品观看91久久久久久
|
麻豆一区二区99久久久久
|
免费精品国产日韩热久久
|
国产精品女同一区二区久久
|
久久精品国产99久久久
|
久久亚洲中文字幕精品一区
|
久久综合成人网
|
国产亚洲精久久久久久无码AV
|
AV色综合久久天堂AV色综合在
|
天堂久久天堂AV色综合
|
久久人妻少妇嫩草AV蜜桃
|
亚洲欧美日韩久久精品
|
久久久久久久综合综合狠狠
|
久久九九久精品国产
|
久久久久国产精品麻豆AR影院
|
久久99精品久久久久久9蜜桃
|
夜夜亚洲天天久久
|
久久精品人人做人人爽电影
|
久久精品国产福利国产秒
|
人妻无码久久一区二区三区免费
|
国产精品久久精品
|
亚洲乱亚洲乱淫久久
|
国产免费久久精品99久久
|
久久国产成人亚洲精品影院
|
热综合一本伊人久久精品
|