L2-005. 集合相似度
题目地址 https://www.patest.cn/contests/gplt/L2-005
>>>**********************************************************************>>>
其实就是一个如何去重的问题。 又是实数, 直接桶排序的思想做,回超内存(char ans[1000000001] )。去重那就排序,排序不如跳舞,不对,是不如优先队列。 还有一件事, 处理完一个集合, 去重的结果要记起来。
Hint: 优先队列不会用的: http://www.cnblogs.com/heqinghui/p/3225407.html
>>>**********************************************************************>>>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <queue>
using namespace std;
priority_queue <int> q;
int n, m, a, b, k, chong, unique, temp, point;
int maps[52][10002], wing[10002];
int main(){
// freopen("in.txt", "r", stdin);
scanf("%d", &n);
for(int i=0; i<n; ++i){
scanf("%d", &maps[i][0]);
m = maps[i][0];
for(int j=1; j<=m; ++j){
scanf("%d", &temp);
q.push(temp);
}
point = 1;
chong = 0;
maps[i][point++] = q.top();
q.pop();
while(!q.empty()){
if(maps[i][point-1] != q.top()){
maps[i][point++] = q.top();
}else{
chong++;
}
q.pop();
}
maps[i][0] -= chong;
}
//cout << "test 1111\n";
scanf("%d", &k);
for(int i=0; i<k; ++i){
scanf("%d%d", &a, &b);
a--;
b--;
chong = 0;
unique = 0;
for(int i=1; i<=maps[a][0]; ++i){
q.push(maps[a][i]);
}
for(int i=1; i<=maps[b][0]; ++i){
q.push(maps[b][i]);
}
//cout << "test 2222\n";
point = 0;
chong = 0;
wing[point++] = q.top();
q.pop();
while(!q.empty()){
if(wing[point-1] != q.top()){
wing[point ++] = q.top();
}else{
chong ++;
}
q.pop();
}
double res = (double) chong / (maps[a][0] + maps[b][0] - chong) * 100.00;
printf("%.2lf%%\n", res);
}
return 0;
}
#include <string.h>
#include <iostream>
#include <queue>
using namespace std;
priority_queue <int> q;
int n, m, a, b, k, chong, unique, temp, point;
int maps[52][10002], wing[10002];
int main(){
// freopen("in.txt", "r", stdin);
scanf("%d", &n);
for(int i=0; i<n; ++i){
scanf("%d", &maps[i][0]);
m = maps[i][0];
for(int j=1; j<=m; ++j){
scanf("%d", &temp);
q.push(temp);
}
point = 1;
chong = 0;
maps[i][point++] = q.top();
q.pop();
while(!q.empty()){
if(maps[i][point-1] != q.top()){
maps[i][point++] = q.top();
}else{
chong++;
}
q.pop();
}
maps[i][0] -= chong;
}
//cout << "test 1111\n";
scanf("%d", &k);
for(int i=0; i<k; ++i){
scanf("%d%d", &a, &b);
a--;
b--;
chong = 0;
unique = 0;
for(int i=1; i<=maps[a][0]; ++i){
q.push(maps[a][i]);
}
for(int i=1; i<=maps[b][0]; ++i){
q.push(maps[b][i]);
}
//cout << "test 2222\n";
point = 0;
chong = 0;
wing[point++] = q.top();
q.pop();
while(!q.empty()){
if(wing[point-1] != q.top()){
wing[point ++] = q.top();
}else{
chong ++;
}
q.pop();
}
double res = (double) chong / (maps[a][0] + maps[b][0] - chong) * 100.00;
printf("%.2lf%%\n", res);
}
return 0;
}