使用c++的解题代码如下
#include <cstdio>
#include <string.h>
#include <stdlib.h>
#include <set>
using namespace std;
int main(){
int n = 0, m=0, x = 0;
double cnt = 0;
int i = 0, j=0, k=0;
scanf("%d", &n);
set< int >zu[60]; //创建60组set,分别储存
for(i = 1; i <= n; i++){
scanf("%d",&m);
for(j = 0;j < m; j++) {
scanf("%d",&x);
zu[i].insert(x);
}
}
scanf("%d", &n);
for(k=0; k < n; k++){
cnt=0;
scanf("%d %d", &m, &x);
set<int>::iterator one=zu[m].begin();
set<int>::iterator two=zu[x].begin();
while(one != zu[m].end() && two != zu[x].end()){
if(*one < *two){
one++;
}else if(*one > *two){
two++; //两组的数字不同则分别左右移动指针
}else{
cnt++; //若两组的数字相同则cnt加一,
one++;two++;
}
}
cnt = 100.0*cnt/(1.0* (zu[m].size()+zu[x].size()-cnt));
printf("%0.1f%%\n",cnt);
}
return 0;
}
//printf("%%"); printf函数中,%用于格式控制,如果想输出文本%,则%%
还请大家多多指出代码冗余之处,转载请注明出处。