读入之后先排序。

询问的时候可以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. hdu_1728_逃离迷宫(bfs)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题意:走迷宫,找最小的拐角 题解:对BFS有了新的理解,DFS+剪枝应该也能过,用BFS就要以拐 ...

  2. Entity Framework技巧系列之二 - Tip 6 - 8

    提示6. 如何及何时使用贪婪加载 什么时候你需要使用贪婪加载? 通常在你的程序中你知道对查询到的实体将要进行怎样的操作. 例如,如果你查询一个订单以便为一个客户重新打印,你知道没有组成订单的项目即产品 ...

  3. how to write a struct to a file directly?

    Using write and read system call. Following is an example: blk.h: #include <stdlib.h> #include ...

  4. java 集合中将元素倒序排列

    方法一:实现Comparable接口排序package collsort.comparable; package com.cvicse.sort.comparable; public class Ca ...

  5. Shell脚本,自动化发布tomcat项目【转载】

    Shell脚本,自动化发布tomcat项目脚本. 1. vko2c_auto_build_by_scp.sh 文件内容: #---------------------start------------ ...

  6. 这一招让 Word 帮你自动生成文件目录,也能自动更新

    学生的研究报告或是公司员工的提案企划书,为了务求严明详尽,往往是洋洋洒洒数十页或甚至上百页之多,像这样大篇幅的文件,在结构上通常会划分为好几个部分,比如像论文就会区分为封面.摘要.内文章节.参考文献等 ...

  7. jsonarray和jsonobject

    JSONArray ja = new JSONArray(); ja.put("11"); ja.put("22"); ja.put("33" ...

  8. OC中的野指针,空指针,nil,Nil,NULL,NSNULL小结

    周末与一个老朋友吃饭聊天,因为他正在培训班学习iOS开发,就随便聊了几句,发现自己OC基础上的欠缺和一些知识点的混淆.特此整理如下. 1.空指针 没有存储任何内存地址的指针就称为空指针(NULL指针) ...

  9. label自适应

    //label自适应 self.label = [UILabel new]; self.label.font = [UIFont systemFontOfSize:14]; NSString *tit ...

  10. Windsock套接字I/O模型学习 --- 第三章

    1. WSAAsyncSelect 模型 WSAAsyncSelect 模型比较简单,是为了适应Windows的消息驱动环境而设置的,WSAAsyncSelect 函数自动把套接字设为非阻塞模式.MF ...