https://pintia.cn/problem-sets/994805342720868352/problems/994805409175420928
可以很容易的写出一个最暴力的写法。可以骗21分

#include<bits/stdc++.h>
using namespace std;
const int N=55;
vector<int>ve[N];
int n,m,k,x,a,b;
int main(void)
{cin>>n;for(int i=1;i<=n;i++){scanf("%d",&m);for(int j=0;j<m;j++) scanf("%d",&x),ve[i].push_back(x);}cin>>k;while(k--){scanf("%d%d",&a,&b);unordered_map<int,int>mp;//统计不同的数量unordered_map<int,int>st;//统计b中出现的int cnt=0;for(int i=0;i<ve[a].size();i++) mp[ve[a][i]]++;for(int i=0;i<ve[b].size();i++){if(st[ve[b][i]]) continue;if(mp[ve[b][i]]) cnt++;mp[ve[b][i]]++;st[ve[b][i]]=1;}printf("%.1lf%%\n",cnt*100.0/mp.size());}return 0;
}

用set来优化,set可以自动的去重。
unordered_set的count的平均复杂度为O(1),set的count复杂度为O(logn)

#include<bits/stdc++.h>
using namespace std;
set<int>s[55];
int n,m,k,x,a,b;
int main(void)
{cin>>n;for(int i=1;i<=n;i++){cin>>m;for(int j=0;j<m;j++) scanf("%d",&x),s[i].insert(x);}cin>>k;while(k--){scanf("%d%d",&a,&b);int cnt=0;for(auto i=s[a].begin();i!=s[a].end();i++) if(s[b].count(*i)) cnt++;printf("%.1lf%%\n",cnt*100.0/(s[a].size()+s[b].size()-cnt));}return 0;
}

1063 Set Similarity (25 分)【难度: 一般 / 知识点: STL中set的应用】相关推荐

  1. 【最后测试点超时】1063 Set Similarity (25 分)_22行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given two sets of integers, the similarity of the sets is defined ...

  2. 1063 Set Similarity (25 分) java 题解

    Given two sets of integers, the similarity of the sets is defined to be Nc​/Nt​×100%, where Nc​ is t ...

  3. 1063. Set Similarity (25)

    题目例如以下: Given two sets of integers, the similarity of the sets is defined to be Nc/Nt*100%, where Nc ...

  4. 1127 ZigZagging on a Tree (30 分)【难度: 一般 / 知识点: 根据中序遍历 后序遍历建树】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805349394006016 PAT甲级中算是很传统的题了,就是建树,然后 ...

  5. 1066 Root of AVL Tree (25 分)【难 / 知识点: 平衡树 未完成】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805404939173888 平衡树之前学过,不过有忘完了,有时间补吧

  6. 1063 Set Similarity

    1063 Set Similarity (25 分) Given two sets of integers, the similarity of the sets is defined to be N ...

  7. 【PAT乙】1080 MOOC期终成绩 (25分)

    problem 1080 MOOC期终成绩 (25分) 对于在中国大学MOOC(http://www.icourse163.org/ )学习"数据结构"课程的学生,想要获得一张合格 ...

  8. PTA 1015 德才论 (25分) ,满分代码 + 测试点报错解决

    知识点 构造sort的排序函数时,string类型可直接比较大小 面对函数的栈器存储空间有限,当出现栈溢出问题时,可将变量命名为全局变量. 测试点2.3.4错误的原因,第一次误以为是由于数据过大,导致 ...

  9. L2-028 秀恩爱分得快 (25 分) 两种解法,详细分析

    L2-028 秀恩爱分得快 (25 分) 古人云:秀恩爱,分得快. 互联网上每天都有大量人发布大量照片,我们通过分析这些照片,可以分析人与人之间的亲密度.如果一张照片上出现了 K 个人,这些人两两间的 ...

最新文章

  1. python接口测试-认识GET请求
  2. Chrome浏览器插件安装位置
  3. 2017派卧底去阿里、京东、美团、滴滴带回来的面试题
  4. POJ1328Radar Installation
  5. linux指令 标题,Linux基础题目整理
  6. HDU 2545 树上战争(并查集)
  7. (20200108)matlab弹出对话框形式打开和读取指定文件,不用提前输入文件名——uigetfile
  8. ACM-ICPC 2018 焦作赛区网络预赛 L Poor God Water(BM算法)
  9. haas506 2.0开发教程-hota(仅支持2.2以上版本)
  10. Pycharm2018永久破解方法
  11. vue在一个方法执行完后执行另一个方法
  12. keras模型转TensorFlow模型-tensorrt UFF格式
  13. 20多岁,你迷茫又着急。你想要房子你想要汽车,你想要旅行你想要享受生活。 你那么年轻却窥觑整个世界
  14. 《一万年以后》一段充满癫狂想象力的奇幻之旅
  15. docker的下载与安装
  16. java中Bigdecimal加减乘除运算
  17. Office安装出错的解决方法,如“Microsoft Office Professional Plus 2013在安装过程中出错”。
  18. CoreData + CloudKit 支持的 App 在导出(export)新建托管对象时内存飙升导致被杀死的解决
  19. 路由器下层设备可以直接访问路由器上层交换机的设备
  20. 雾霾警醒世人,智慧城市加速刻不容缓

热门文章

  1. MySQL读取Binlog日志常见的3种错误
  2. Jenkins构建自动化脚本执行无界面解决方法
  3. JavaScript作用域闭包简述
  4. Android 动画机制与使用技巧
  5. NYOJ 108士兵杀敌(一)
  6. 如何编写一份软件工程实验报告
  7. [Linux].netrc或者_netrc使用可以
  8. 由浅到深了解JavaScript类
  9. nrf52832 之 gpio配置方法
  10. stm32f103c8t6芯片IAP升级填坑记