读入之后先排序。

询问的时候可以o(m)效率得到答案。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<string>
#include<stack>
#include<map>
#include<algorithm>
using namespace std; struct X
{
int m;
int a[+];
}s[];
int n; struct Arr
{
int f;
int num;
}h[+]; int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&s[i].m);
for(int j=;j<=s[i].m;j++) scanf("%d",&s[i].a[j]);
sort(s[i].a+,s[i].a++s[i].m);
s[i].a[s[i].m+]=0x7FFFFFFF;
}
int k; scanf("%d",&k);
for(int i=;i<=k;i++)
{
int A,B; scanf("%d%d",&A,&B);
int z1=,z2=;
int tot=;
while()
{
if(tot==s[A].m+s[B].m) break;
if(s[A].a[z1]<s[B].a[z2])
{
h[++tot].f=;
h[tot].num=s[A].a[z1];
z1++;
}
else if(s[A].a[z1]>s[B].a[z2])
{
h[++tot].f=;
h[tot].num=s[B].a[z2];
z2++;
}
else
{
h[++tot].f=;
h[tot].num=s[A].a[z1];
z1++;
}
}
h[].num=-;
int nc=,nt=;
for(int i=;i<=tot;i++) if(h[i].num!=h[i-].num) nt++;
int pos=;
while()
{
if(pos>tot) break;
int yuan;
for(int i=pos;i<=tot;i++)
{
if(h[i].num==h[pos].num) yuan=i;
else break;
} if(h[pos].f!=h[yuan].f) nc++;
pos=yuan+;
}
printf("%.1lf%%\n",1.0*nc/nt*);
}
return ;
}

PAT (Advanced Level) 1063. Set Similarity (25)的更多相关文章

  1. PAT (Advanced Level) 1114. Family Property (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  2. PAT (Advanced Level) 1109. Group Photo (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  3. PAT (Advanced Level) 1105. Spiral Matrix (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...

  4. PAT (Advanced Level) 1101. Quick Sort (25)

    树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...

  5. PAT (Advanced Level) 1071. Speech Patterns (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  6. PAT (Advanced Level) 1059. Prime Factors (25)

    素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

  7. PAT (Advanced Level) 1051. Pop Sequence (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  8. PAT (Advanced Level) 1048. Find Coins (25)

    先对序列排序,然后枚举较小值,二分较大值. #include<iostream> #include<cstring> #include<cmath> #includ ...

  9. PAT (Advanced Level) 1028. List Sorting (25)

    时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...

随机推荐

  1. Chapter 1 First Sight——28

    "Which one is the boy with the reddish brown hair?" 那个红褐色头发的男孩是谁? I asked. I peeked at him ...

  2. hdu_5274_Dylans loves tree(树剖)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5274 题意:给一棵树和叶子的值,然后有单点修改操作和询问区间操作,询问的是每一个值出现的奇偶次数,如果 ...

  3. away 3d的一些问题

    不能成功draw m3u8视频流问题: Texture2DBase.as return context.createRectangleTexture(_width, _height, Context3 ...

  4. 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D

    http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...

  5. no ia32-libs

    sudo apt-get install lib32stdc++6 sudo apt-get install lib32z1 http://blog.csdn.net/wangbin_jxust/ar ...

  6. androidstudio 问题

    Error:(1, 1) A problem occurred evaluating project ':app'. > Failed to apply plugin [id 'com.andr ...

  7. git 提交到github时不用每次都输入用户名,密码

    Permanently authenticating with Git repositories, Run following command to enable credential caching ...

  8. 【转】configure/make/make install的使用说明

    这些都是典型的使用GNU的AUTOCONF和AUTOMAKE产生的程序的安装步骤. ./configure是用来检测你的安装平台的目标特征的.比如它会检测你是不是有CC或GCC,并不是需要CC或GCC ...

  9. cmd实用指令

    具体可参考:http://www.jb51.net/os/windows/36986.html 以下是本人总结的一些比较实用的指令,仅仅只是自己的实战笔记 f: 进入F盘 同理 c: 进入C盘 cd ...

  10. Android Matrix类以及ColorMatri

    引自:http://www.chinabaike.com/t/37396/2014/0624/2556217.html Android Matrix类以及ColorMatrix类详解 最近在系统学习了 ...