http://ac.jobdu.com/problem.php?pid=1156
题目1156:谁是你的潜在朋友1.用结构体来记录读者i-1最喜欢的图书的编号P(其实可以理解为读者i)
2.利用Hash函数来构造读者i-1最喜欢的图书的编号P一一对应的关系
1
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
|
#include<iostream>
#include<cstdio>
#include<cstring>
using
namespace
std;
struct
H{
int
num;
int
P;
};
int
main(){
int
n,m,i;
H Hash[210];
while
(
scanf
(
"%d%d"
,&n,&m)!=EOF){
memset
(Hash,0,
sizeof
(Hash));
int
x;
for
(i=1;i<=n;i++){
scanf
(
"%d"
,&Hash[i].P);
Hash[Hash[i].P].num++;
}
for
(i=1;i<=n;i++){
if
(Hash[Hash[i].P].num>1){
printf
(
"%d\n"
,Hash[Hash[i].P].num-1);
}
else
printf
(
"BeiJu\n"
);
}
}
return
0;
}
/**************************************************************
Problem: 1156
User: lanjiangzhou
Language: C++
Result: Accepted
Time:10 ms
Memory:1520 kb
****************************************************************/
|