PageRank,HUST Monthly 2011.04.09 之 A,1431
PageRank
Time Limit: 10 Sec Memory Limit: 256 MBSubmissions: 168 Solved: 8
Description
Google is famous over the world, much of the reason for their success lies with the effective search result for their user. In the final, support this effective is the technique called PageRank which largely used the huge url link network. A simple example is a hyperlink in Page A linked to Page B is viewed as A give a vote of support to B.
For us, PageRank is a complex technique, to simplify the problem, let’s analysis a simple model first. For every hyperlink, we just give 2 kind of attribute, the tag on the hyperlink, and the target url hyperlink point. So a hyperlink is viewed as a tag vote to an url.
As a user of search engine, each time we search, we will offer an keywork. Now the problem is for each given keywork, check all given hyperlink, if the tag on hyperlink contain this keywork, we count it’s a effective vote, then list the top 10 most voted url. (if 2 urls get the same votes, we sort it with lexicographic order)
Input
First line is N, indicate N hyperlinks. (1<=N<=20000)
Next N lines:
Each line contain two string, the first is the tag of hyperlink and the second is the url.
We guarantee that tags just contain lowcase and the length is less than 7, and urls just not contain blank characters(blank spaces, tabs and line break characters), the length of urls is less than 30.
Next line is Q, indicate Q times search. (1<=Q<=50000)
Next Q lines:
Each line just contain a string, indicate the keyword offered by user.
Output
For each search, list the top10 most voted urls, and a blankspace and the vote number.(if less then 10 urls be voted, just list all). If no url get votes, just output “Sorry, no result satisfied." In a single line.
For the answer of difference search, output a blank line between them.(Never leave a redundant blank line before the end of file)
Important hint, huge output, printf is recommended.
Sample Input
10 hustacm http://acm.hust.edu.cn acmicpc http://acm.hust.edu.cn acm http://acm.hust.edu.cn hoj http://acm.hust.edu.cn/thx vjudge http://acm.hust.edu.cn/vt forum http://acm.hust.edu.cn/forum hhoj http://acm.hust.edu.cn/vt isun http://acm.hust.edu.cn/vt sempr http://acm.hust.edu.cn/thx gaewah http://acm.hust.edu.cn/forum 6 acm m hoj zy j h
Sample Output
http://acm.hust.edu.cn 3
http://acm.hust.edu.cn 3 http://acm.hust.edu.cn/forum 1 http://acm.hust.edu.cn/thx 1
http://acm.hust.edu.cn/thx 1 http://acm.hust.edu.cn/vt 1
Sorry, no result satisfied.
http://acm.hust.edu.cn/vt 2 http://acm.hust.edu.cn/thx 1
http://acm.hust.edu.cn 1 http://acm.hust.edu.cn/forum 1 http://acm.hust.edu.cn/thx 1 http://acm.hust.edu.cn/vt 1
HINT
Source
HONG Zehua / HUST Monthly 2011.04.09
繁瑣的字符串插入查找,Trie 靈活應用,因為空間問題,用了一級指針,二級指針,鏈表。
預先開一個字符串buffer,用于存儲 tag 和 url,其它保存 url 的地方只保存相應指針。
先根據 url 字典序將輸入的 < tag,url > 排序,利用 Trie 統計對于同一個 url 的所有tag的所有子串對此 url 的 vote,同一tag的相同子串不要重復計數,通過在 Trie 中加入mask實現。
Trie 中節點只保存本關鍵字投票的 Vote 鏈表的指針,若此節點對某 url 有投票,則 Vote 鏈表非空,且只保存得票最高的前 10 名。
程序用時 1932 MS。

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20



21

22

23

24

25



26

27

28

29

30

31

32

33

34

35



36

37

38

39

40

41

42

43

44

45

46

47



48

49

50

51

52

53

54

55

56

57

58



59

60

61

62

63

64

65

66

67

68

69



70

71

72

73

74

75



76



77



78

79

80



81

82

83

84



85



86

87

88

89

90

91

92

93

94



95



96



97

98

99



100

101

102

103



104

105

106

107

108

109

110



111



112



113

114

115



116

117

118

119



120

121



122

123

124

125

126

127

128

129



130

131

132

133

134

135

136

137

138

139

140



141



142



143

144

145

146

147

148

149

150

151

152



153

154

155

156

157



158

159

160



161

162

163

164

165

166

167

168

169



170



171



172

173

174



175

176

177

178



179

180

181

182

183

184



185

186

187



188

189

190

191



192

193

194

195

196



197

198

199

200

201

202

203

204

205



206

207

208

209

210

211

212

213



214



215

216

217

218



219

220



221



222

223

224

225

226

227

228

229



230

231



232



233

234

235

236



237

238

239

240

241

242

243

244

245

246

247



248

249

250



251

252

253

254

255

256

posted on 2011-04-10 21:23 coreBugZJ 閱讀(322) 評論(0) 編輯 收藏 引用 所屬分類: ACM