PTA_A1063
AC代码:
#include <iostream> #include <cstdio> #include <set> using namespace std; const long N=55; set<long long> vi[N]; /* void hanshu(int a,int b) { int len = vi[a].size()+vi[b].size(); set<long long>::iterator it; for(it = vi[a].begin();it != vi[a].end();it++){ vt.insert(*it); } for(it = vi[b].begin();it != vi[b].end();it++){ vt.insert(*it); } double nt = vt.size(); vt.clear(); double nc=len-nt; double str=nc/nt; printf("%.1lf%\n",str*100); } */ void hanshu(int a, int b) { int nt=vi[b].size(),nc=0; for(set<long long>::iterator it=vi[a].begin();it!=vi[a].end();it++){ if(vi[b].find(*it) != vi[b].end()) nc++; else nt++; } printf("%.1lf%\n",nc*100.0/nt); } int main(void) { freopen("in.txt","r",stdin); int n,m,k; long long tmp; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&m); for(int j=0;j<m;j++){ scanf("%lld",&tmp); vi[i+1].insert(tmp); } } scanf("%d",&k); for(int i=0;i<k;i++){ int a,b; double count; scanf("%d%d",&a,&b); hanshu(a,b); } fclose(stdin); return 0; }