题目:http://pat.zju.edu.cn/contests/pat-a-practise/1063
代码:https://github.com/kunth/evernote/blob/master/pat1063
//accepted
#include<cstdio>
#include<algorithm>
using namespace std;
int num[51][10001];
int main()
{
int N, M, K, A, B;
//freopen("in.txt", "r", stdin);
scanf("%d", &N);
for(int i = 1; i <= N; ++i)
{
scanf("%d", &M);
for(int j=1; j<=M; ++j)
scanf("%d", &num[i][j]);
num[i][0] = M;
}
scanf("%d", &K);
for(int i = 0; i<K;++i)
{
scanf("%d %d", &A, &B);
sort(num[A]+1, num[A] + 1 + num[A][0]);
sort(num[B]+1, num[B] + 1 + num[B][0]);
int pa=1, pb=1, cnt=0, sum=0;
while(pa<=num[A][0] && pb<=num[B][0])
{
if(num[A][pa] < num[B][pb])
{
++pa;
}
else if(num[A][pa] > num[B][pb])
{
++pb;
}
else
{
++pa;
++pb;
++cnt;
}
++sum;
while(pa > 1 && num[A][pa] == num[A][pa-1])
++pa;
while(pb > 1 && num[B][pb] == num[B][pb-1])
++pb;
}
if(num[A][num[A][0]] != num[B][num[B][0]])
++sum;
printf("%.1f%%\n", 100*(float)cnt/sum);
}
return 0;
}