读入之后先排序。

询问的时候可以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. ShellExecute, WinExec, CreateProcess区别

    ShellExecute ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件.打开一个目录.打印一个文件等等),并对外部程序有一定的控制. 有几个API函数都可以实现这些功能 ...

  2. 我的定时关机程序(MFC实现) .

    原理: 利用定时器去检查,如输入的是多少分钟后关机,就根据输入的分钟数产生一个COUNT计数器,计数器一直递减,直到1,然后执行关机.如输入的是几时几分关机,那么定时器会每次都检查系统的时间和你输入的 ...

  3. Eclipse的WorkingSet使用(转载)

    Eclipse作为一款流行的JavaIDE开发工具,其有很多好用的功能为我们的开发提供帮助.但我们的工作空间中有很多项目时,管理起来就很头疼了. 但是我们又不想更换工作区间,所以我们需要一个更加有效的 ...

  4. json 数组 对象 xml 之间转换(待补充)

    json 数组  xml 对象   之间转换(待补充) 1 把对象的类型或者数组转换成字符串类型(或者更确切的说是json类型的). 此处参考链接http://www.jb51.net/article ...

  5. AIR使用文件对象操作文件和目录

    文件对象是啥?文件对象(File对象)是在文件系统中指向文件或目录的指针.由于安全原因,只在AIR中可用. 文件对象能做啥? 获取特定目录,包括用户目录.用户文档目录.该应用程序启动的目录和程序目录 ...

  6. 将undefault和null的数据转换成bool类型的数据 使用!!

    <script> var o={}; var a=null; console.info(!!o.name); </script> 输出false 此方法是将undefault和 ...

  7. background和background-position相关笔记

    background 可在一个声明中设置background-color,background-image,background-repeat,background-attachment,backgr ...

  8. java实现类似qq的窗口对聊

    Swing实现界面,socket实现通信 package com.learn.talk; import java.awt.BorderLayout; import java.awt.Dimension ...

  9. linux 进程命令

    Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那些进程.ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻的那些进程,如果想要动态的显示进程信 ...

  10. Net Protocol Related

    Data used to deliver through net should be encapsulated. General encapsulation include 4 layer of he ...