读入之后先排序。

询问的时候可以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. 眼睛跟踪 java

    https://github.com/hosek/eyeTrackSample Simple sample, for eye tracking with OpenCV

  2. git简单使用教程

    git 的基本使用指令 我们先来简单熟悉一下 git 的简单使用的指令, 作为最基本的 git 指令一定要熟悉 12345678910111213141516171819202122232425262 ...

  3. /etc/rc.local 与 /etc/init.d Linux 开机自动运行程序

    1. /etc/rc.local 这是使用者自订开机启动程序,把需要开机自动运行的程序写在这个脚本里 --------引用---------------------- 在完成 run level 3 ...

  4. CocoaAsyncSocket框架的简单封装

    在iOS开发中使用socket(CFNetwork),一般都是用第三方库AsyncSocket. 参考博客:http://my.oschina.net/worldligang/blog/396881? ...

  5. max_%_connection参数详解

    对于连接数的设置,show variables里有三个参数可以对它进行控制,max_connections与max_user_connections以及max_connect_errors.下面对这三 ...

  6. FreeRTOS中断优先级配置(重要)

    FreeRTOS中断优先级配置(重要) 本章节为大家讲解FreeRTOS中断优先级配置,此章节非常重要,初学者经常在这里犯迷糊.对于初学者来说,本章节务必要整明白.12.1 NVIC基础知识12.2  ...

  7. sql server数据库中 INFORMATION_SCHEMA的用法

    1.查询数据库的所有表: select * from INFORMATION_SCHEMA.TABLES 2.查询表名为xxx的所有列的信息 select * from INFORMATION_SCH ...

  8. 拖动滚动条时某一处相对另一处固定不动(position:fixed)

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  9. codeforces 689B Mike and Shortcuts 最短路

    题目大意:给出n个点,两点间的常规路为双向路,路长为两点之间的差的绝对值,第二行为捷径,捷径为单向路(第i个点到ai点),距离为1.问1到各个点之间的最短距离. 题目思路:SPFA求最短路 #incl ...

  10. CentOS 下配置CUPS

    一.共享打印机的设置 1.在http://www.openprinting.org/printer/HP/HP-LaserJet_1010检查打印机的支持情况,两个企鹅以上表示Mostly,支持大部分 ...