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< ...
随机推荐
- Centos sudo添加用户
$ su - # vi /etc/sudoers 在root ALL=(ALL) ALL下 添加 username ALL=(ALL) ALL 输入wq!强制保存.
- java IO类图
- linux下shell命令trap
某些时候,在执行shell脚本(.sh)时,我们并不希望被打断.这时我们要用到trap命令. 例如: 在shell脚本中,忽略“终止”信号 trap ' ' TERM
- LeetCode OJ 202. Happy Number
Write an algorithm to determine if a number is "happy". A happy number is a number defined ...
- nefu 115 斐波那契的整除
Description 已知斐波那契数列有如下递归定义,f(1)=1,f(2)=1, 且n>=3,f(n)=f(n-1)+f(n-2),它的前几项可以表示为1, 1,2 ,3 ,5 ,8,13, ...
- OpenCV ——背景建模之CodeBook(2)
1,CodeBook的来源 先考虑平均背景的建模方法.该方法是针对每一个像素,累积若干帧的像素值,然后计算平均值和方差,以此来建立背景模型,相当于模型的每一个像素含有两个特征值,这两个特征值只是单纯的 ...
- java和.net的类比
原文地址在http://www.seguetech.com/blog/2013/06/03/dotnet-vs-java-how-to-pick
- shell之路【第三篇】流程控制
if语句 if ... fi 语句: if ... else ... fi 语句: if ... elif ... else ... fi 语句. 注意: expression 和方括号([ ])之间 ...
- Centos下 Nginx安装与配置
网上找了好多资料.都很难找全,这里以这个目录为主,进行备注. Nginx是一款轻量级的网页服务器.反向代理服务器.相较于Apache.lighttpd具有占有内存少,稳定性高等优势.它最常的用途是提供 ...
- web前端与后端
Web前端: 1)精通HTML,能够书写语义合理,结构清晰,易维护的HTML结构. 2)精通CSS,能够还原视觉设计,并兼容业界承认的主流浏览器. 3)熟悉JavaScript ...