Where there is a dream ,there is hope
C++博客
::
首頁
::
聯(lián)系
::
聚合
::
管理
64 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks
常用鏈接
我的隨筆
我的評(píng)論
我參與的隨筆
留言簿
(1)
給我留言
查看公開留言
查看私人留言
我參與的團(tuán)隊(duì)
隨筆分類
C#(2)
C/C++(19)
EFFECTIVE-STL學(xué)習(xí)筆記(3)
Mono
monodevelop
TCP/IP(1)
翻譯文章(4)
算法/數(shù)據(jù)結(jié)構(gòu)(1)
折騰UBUNTU(2)
職業(yè)人生(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#講師-設(shè)計(jì)模式-數(shù)據(jù)結(jié)構(gòu)
范懷宇
韓湘子
專門解決各種C++疑難雜癥
搜索
最新評(píng)論
1.?re: 匿名空間
.就空間看快樂
--何霞飛
2.?re: 匿名空間
u厲害
--何霞飛
3.?re: 服務(wù)器設(shè)計(jì)-轉(zhuǎn)
這種文章挺少的噢。不是做服務(wù)器的,多了解一些總是好的。設(shè)計(jì)真是一門有意思的學(xué)問。
--K.V
4.?re: josephon問題
不過這個(gè)模擬過程非常不好,對(duì)于100000以上的人數(shù)來說簡(jiǎn)直就是悲劇。。。
--Husiwa
5.?re: 簡(jiǎn)潔的字符串連接函數(shù)
@木頭奎
的確有缺點(diǎn),但這個(gè)函數(shù)的實(shí)現(xiàn)過程還是有其發(fā)作的
--Husiwa
閱讀排行榜
1.?轉(zhuǎn)載:vector find(2382)
2.?vector 查找指定元素(1777)
3.?C#結(jié)構(gòu)體序列化(1265)
4.?windows.h與winsock2.h的包含順序(1162)
5.?模板類靜態(tài)變量初始化(1123)
評(píng)論排行榜
1.?簡(jiǎn)潔的字符串連接函數(shù)(2)
2.?匿名空間(2)
3.?C++指針探討 (一)數(shù)據(jù)指針(1)
4.?josephon問題(1)
5.?服務(wù)器設(shè)計(jì)-轉(zhuǎn)(1)
josephon問題
看到首頁上有人寫,自己也寫了一個(gè)
名字起錯(cuò)了,其實(shí)寫個(gè)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菜鳥
閱讀(376)
評(píng)論(1)
編輯
收藏
引用
Feedback
#
re: josephon問題
2011-03-16 11:31
Husiwa
不過這個(gè)模擬過程非常不好,對(duì)于100000以上的人數(shù)來說簡(jiǎn)直就是悲劇。。。
回復(fù)
更多評(píng)論
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
【推薦】100%開源!大型工業(yè)跨平臺(tái)軟件C++源碼提供,建模,組態(tài)!
網(wǎng)站導(dǎo)航:
博客園
IT新聞
BlogJava
博問
Chat2DB
管理
Copyright @ IT菜鳥
Powered by:
.Text
and
ASP.NET
Theme by:
.NET Monster
蜜臀久久99精品久久久久久小说
|
久久久久国产精品嫩草影院
|
色偷偷88欧美精品久久久
|
久久影视综合亚洲
|
久久伊人五月丁香狠狠色
|
国产精品免费看久久久
|
色8激情欧美成人久久综合电
|
欧美黑人又粗又大久久久
|
久久婷婷色综合一区二区
|
欧洲人妻丰满av无码久久不卡
|
午夜精品久久久久成人
|
国产成人久久精品区一区二区
|
久久精品国产72国产精福利
|
粉嫩小泬无遮挡久久久久久
|
亚洲精品无码专区久久同性男
|
久久97精品久久久久久久不卡
|
久久99精品国产麻豆蜜芽
|
亚洲级αV无码毛片久久精品
|
久久国产一片免费观看
|
久久精品www人人爽人人
|
中文字幕无码久久久
|
精品国产热久久久福利
|
久久亚洲精品中文字幕三区
|
中文字幕无码精品亚洲资源网久久
|
久久国产精品偷99
|
久久99精品国产99久久6
|
久久精品国产亚洲麻豆
|
青青青伊人色综合久久
|
国产精品久久久久久吹潮
|
久久久无码人妻精品无码
|
亚洲女久久久噜噜噜熟女
|
亚洲国产精品无码久久98
|
亚洲AV无码一区东京热久久
|
色综合久久中文字幕无码
|
久久人人爽人人爽人人片AV麻烦
|
久久只有这精品99
|
亚洲精品无码久久久久去q
|
无码超乳爆乳中文字幕久久
|
久久久国产乱子伦精品作者
|
久久九九精品99国产精品
|
97久久综合精品久久久综合
|