PAT (Advanced Level) 1063. Set Similarity (25)
读入之后先排序。
询问的时候可以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)的更多相关文章
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT (Advanced Level) 1109. Group Photo (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1105. Spiral Matrix (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...
- PAT (Advanced Level) 1101. Quick Sort (25)
树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...
- PAT (Advanced Level) 1071. Speech Patterns (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1059. Prime Factors (25)
素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...
- PAT (Advanced Level) 1051. Pop Sequence (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT (Advanced Level) 1048. Find Coins (25)
先对序列排序,然后枚举较小值,二分较大值. #include<iostream> #include<cstring> #include<cmath> #includ ...
- PAT (Advanced Level) 1028. List Sorting (25)
时间卡的比较死,用string会超时. #include<cstdio> #include<cstring> #include<cmath> #include< ...
随机推荐
- js如何在指定页面跳转到另一指定页面
要实现从一个页面A跳到另一个页面B,js实现就在A的js代码加跳转代码 JS跳转大概有以下几种方式: 第一种:(跳转到b.html)<script language="javascri ...
- 第三十节,正则表达式re模块
正则表达式 正则表达式本身是一种小型的.高度专业化的编程语言,而在python中,通过内嵌集成re模块,程序员们可以直接调用来实现正则匹配.正则表达式模式被编译成一系列的字节码,然后由用C编写的匹配引 ...
- js 交换表单中值
<html> <head> <meta charset="utf-8" /> <script type="text/javasc ...
- Entity Framework技巧系列之三 - Tip 9 – 12
提示9. 怎样直接删除一个对象而无需检索它 问题 最常见的删除Entity Framework中实体的方式是将你要删除的实体传入Context中并像如下这样删除: 1 // 按ID查找一个类别 2 / ...
- 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 ...
- 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 ...
- Eclipse中配置weka,以及添加算法
Eclipse中配置weka 1 找到weka的安装位置,寻找weka的压缩文件weka-src.jar,将压缩文件解压,解压出的文件夹weka-src. 2 打开Eclipse,新建Java pro ...
- Global事件执行顺序
Global.asax 文件,有时候叫做 ASP.NET 应用程序文件,提供了一种在一个中心位置响应应用程序级或模块级事件的方法.你可以使用这个文件实现应用程序安全性以及其它一些任务.下面让我们详细看 ...
- 2016 ccpc 杭州赛区的总结
毕竟是在杭电比的,和之前大连的icpc不同,杭电毕竟是隔壁学校,来回吃住全都是在自家寝室,方便! 不过说到方便也是有点不方便,室友都喜欢玩游戏,即使我昨晚9.30就睡觉了,仍然是凌晨一点才睡着,233 ...
- 【裸最小生成树】 模板 poj 1258
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #def ...