您当前的位置: 首页 > 

MangataTS

暂无认证

  • 6浏览

    0关注

    423博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

L2-005 集合相似度(STL+暴力)

MangataTS 发布时间:2022-03-24 19:17:50 ,浏览量:6

题目连接

https://pintia.cn/problem-sets/994805046380707840/problems/994805070149828608

视频讲解

https://www.bilibili.com/video/BV1sS4y1N7cU

思路

这道题其实难点在于理解题意,其中的 N c N_c Nc​ 其实就是两个集合的交集的元素个数, N t N_t Nt​ 就是两个集合合并后的元素个数(去重),那么我们利用set 或者 map就能很好的实现这个操作,我们定义 Nset 然后我们查找 lr的重复度的时候直接选取一个集合作为操作集合查找一下两个集合中元素的重复个数就得到了 N c N_c Nc​ ,然后再用两个集合的元素的个数减去 N c N_c Nc​ 就得到了 N t N_t Nt​

代码 set
#include
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair
#define INF 0x3f3f3f3f

const int N = 55;
int n,m;

set mp[N];
double ans[N][N];

double compare(int l,int r) {
	double nc,nt;
	nc = 0;
	nt = double(mp[l].size() + mp[r].size());
	for(auto it : mp[l]){
		if(mp[r].find(it) != mp[r].end()) 
			nc += 1.0;
	}
	nt -= nc;
	return (nc/nt) * 100.0;
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	int k;
	for(int i = 1;i >m;
		for(int j = 1;j >k;
			mp[i].insert(k);
		}
	}
	cin>>m;
	while(m--){
		int l,r;
		cin>>l>>r;
		coutr;
		cout            
关注
打赏
1665836431
查看更多评论
0.0362s