天梯赛 - L2-005 集合相似度
2024-09-03 05:41:28
题目链接:https://www.patest.cn/contests/gplt/L2-005
这个题理解是个大问题啊,“给定两个整数集合,它们的相似度定义为:Nc/Nt*100%。其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数。你的任务就是计算任意一对给定集合的相似度。” 理解了很久,用set来去重。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
const int maxn = ;
set<int> gather[maxn];
int main()
{
int n = ,m = ;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&m);
for(int j=;j<m;j++)
{
int x;
scanf("%d",&x);
gather[i].insert(x);
}
}
int k = ;
scanf("%d",&k);
int l = ,r = ;
while(k--)
{
scanf("%d %d",&l,&r);
int Count = ;
set<int>::iterator it;
for(it=gather[l].begin();it!=gather[l].end();it++)
{
if(gather[r].count(*(it)))
{
Count++;
}
// printf("%d\n",*it);
}
printf("%.2f%%\n",(double)Count/(double)(gather[l].size()+gather[r].size()-Count)*100.0);
}
return ;
}
最新文章
- 关于.NET异常处理的思考
- 业务中是否有必要让所有的ViewController统一继承抽象类
- .net 附加W3wp进程
- MessageDigest消息摘要
- Spark小课堂Week1 Hello Spark
- Android 主题动态切换框架:Prism
- iOS Crash文件的解析
- 企业生产环境中linux系统分区的几种方案
- 完整导出IntelliJ IDEA的快捷键
- AIX误删除LV后如何进行现场保护和数据恢复工作
- org.springframework.data.redis.serializer.SerializationException: Cannot serialize;
- TestNG entryset的用法及遍历map的用法
- 取消layUI中日期选择控件默认填充日期
- TCP 服务端接收数据解析工具类
- FFT ip core
- Android-Java-类与对象的关系
- C# 实现简单仿QQ登陆注册功能
- [CF1060E]Sergey and Subway[树dp]
- 程序中try、throw、catch三者之间的关系
- 2、Python特征
热门文章
- 01创建线程CreateThread和_beginthreadex
- 记一次header跨域与cookie共享
- [译]The Python Tutorial#6. Modules
- STM32CUBEMX入门学习笔记2:关于STM32芯片使用内部flash
- Linux交换分区swap
- 【15】ES6 for Humans: The Latest Standard of JavaScript: ES2015 and Beyond
- day04_03 题目判断三个数字中的最大值
- 【Istio】error initializing configuration &#39;/etc/istio/proxy/envoy-rev0.json&#39;: malformed IP address: istio-statsd-prom-bridge
- js多少时间之前
- Bash Command 1: find