模拟 - L2-028 秀恩爱分得快 - 天梯赛
19分代码,实在找不出哪里问题
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#define x first
#define y second
using namespace std;
const int N = 1010;
int n, m, k;
string a, b;
unordered_set<string> id[N];
unordered_map<string, double> A;
unordered_map<string, double> B;
vector<string> ans[2];
bool diff(string a, string b)
{
return a[0] == '-' && b[0] != '-' || a[0] != '-' && b[0] == '-';
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>k;
string x;
for(int j=0;j<k;j++) cin>>x, id[i].insert(x);
}
cin>>a>>b;
for(int i=0;i<m;i++)
{
if(id[i].count(a))
{
int s = id[i].size();
for(auto u : id[i])
if(u != a && diff(u, a))
A[u] += (double)1/s;
}
if(id[i].count(b))
{
int s = id[i].size();
for(auto u : id[i])
if(u != b && diff(u, b))
B[u] += (double)1/s;
}
}
double m1 = 0, m2 = 0;
for(auto u : A) m1 = max(m1, u.y);
for(auto u : B) m2 = max(m2, u.y);
if(A[b] == m1 && B[a] == m2) cout<<a<<' '<<b<<endl;
else
{
for(auto u : A)
if(u.y == m1)
ans[0].push_back(u.x);
sort(ans[0].begin(), ans[0].end());
for(int i=0;i<ans[0].size();i++) cout<<a<<' '<<ans[0][i]<<endl;
for(auto u : B)
if(u.y == m2)
ans[1].push_back(u.x);
sort(ans[1].begin(), ans[1].end());
for(int i=0;i<ans[1].size();i++) cout<<b<<' '<<ans[1][i]<<endl;
}
return 0;
}