读入之后先排序。

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

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<queue>
  5. #include<vector>
  6. #include<string>
  7. #include<stack>
  8. #include<map>
  9. #include<algorithm>
  10. using namespace std;
  11.  
  12. struct X
  13. {
  14. int m;
  15. int a[+];
  16. }s[];
  17. int n;
  18.  
  19. struct Arr
  20. {
  21. int f;
  22. int num;
  23. }h[+];
  24.  
  25. int main()
  26. {
  27. scanf("%d",&n);
  28. for(int i=;i<=n;i++)
  29. {
  30. scanf("%d",&s[i].m);
  31. for(int j=;j<=s[i].m;j++) scanf("%d",&s[i].a[j]);
  32. sort(s[i].a+,s[i].a++s[i].m);
  33. s[i].a[s[i].m+]=0x7FFFFFFF;
  34. }
  35. int k; scanf("%d",&k);
  36. for(int i=;i<=k;i++)
  37. {
  38. int A,B; scanf("%d%d",&A,&B);
  39. int z1=,z2=;
  40. int tot=;
  41. while()
  42. {
  43. if(tot==s[A].m+s[B].m) break;
  44. if(s[A].a[z1]<s[B].a[z2])
  45. {
  46. h[++tot].f=;
  47. h[tot].num=s[A].a[z1];
  48. z1++;
  49. }
  50. else if(s[A].a[z1]>s[B].a[z2])
  51. {
  52. h[++tot].f=;
  53. h[tot].num=s[B].a[z2];
  54. z2++;
  55. }
  56. else
  57. {
  58. h[++tot].f=;
  59. h[tot].num=s[A].a[z1];
  60. z1++;
  61. }
  62. }
  63. h[].num=-;
  64. int nc=,nt=;
  65. for(int i=;i<=tot;i++) if(h[i].num!=h[i-].num) nt++;
  66. int pos=;
  67. while()
  68. {
  69. if(pos>tot) break;
  70. int yuan;
  71. for(int i=pos;i<=tot;i++)
  72. {
  73. if(h[i].num==h[pos].num) yuan=i;
  74. else break;
  75. }
  76.  
  77. if(h[pos].f!=h[yuan].f) nc++;
  78. pos=yuan+;
  79. }
  80. printf("%.1lf%%\n",1.0*nc/nt*);
  81. }
  82. return ;
  83. }

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. js如何在指定页面跳转到另一指定页面

    要实现从一个页面A跳到另一个页面B,js实现就在A的js代码加跳转代码 JS跳转大概有以下几种方式: 第一种:(跳转到b.html)<script language="javascri ...

  2. 第三十节,正则表达式re模块

    正则表达式 正则表达式本身是一种小型的.高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序员们可以直接调用来实现正则匹配.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引 ...

  3. js 交换表单中值

    <html> <head> <meta charset="utf-8" /> <script type="text/javasc ...

  4. Entity Framework技巧系列之三 - Tip 9 – 12

    提示9. 怎样直接删除一个对象而无需检索它 问题 最常见的删除Entity Framework中实体的方式是将你要删除的实体传入Context中并像如下这样删除: 1 // 按ID查找一个类别 2 / ...

  5. LeetCode OJ 100. Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  6. LeetCode OJ 142. Linked List Cycle II

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note ...

  7. Eclipse中配置weka,以及添加算法

    Eclipse中配置weka 1 找到weka的安装位置,寻找weka的压缩文件weka-src.jar,将压缩文件解压,解压出的文件夹weka-src. 2 打开Eclipse,新建Java pro ...

  8. Global事件执行顺序

    Global.asax 文件,有时候叫做 ASP.NET 应用程序文件,提供了一种在一个中心位置响应应用程序级或模块级事件的方法.你可以使用这个文件实现应用程序安全性以及其它一些任务.下面让我们详细看 ...

  9. 2016 ccpc 杭州赛区的总结

    毕竟是在杭电比的,和之前大连的icpc不同,杭电毕竟是隔壁学校,来回吃住全都是在自家寝室,方便! 不过说到方便也是有点不方便,室友都喜欢玩游戏,即使我昨晚9.30就睡觉了,仍然是凌晨一点才睡着,233 ...

  10. 【裸最小生成树】 模板 poj 1258

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #def ...