可恶的模拟,借鉴了别人的思路,这样写很清晰
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
int n,q,m;
vector<int>a,b;
double g[1010][1010];
double maxn[1010];
set<int>c,d;
void solve()
{
cin>>n>>m;
while(m--){
a.clear(),b.clear();
int t;cin>>t;
for(int i=1;i<=t;++i){
string s;cin>>s;
if(s[0]=='-'){
a.push_back(abs(stoi(s)));
c.insert(abs(stoi(s)));
}else{
b.push_back(abs(stoi(s)));
d.insert(abs(stoi(s)));
}
}
for(auto &t1:a){
for(auto &t2:b){
g[t1][t2]+=1.0/t;
g[t2][t1]+=1.0/t;
maxn[t1] = max(maxn[t1],g[t1][t2]);
maxn[t2] = max(maxn[t2],g[t2][t1]);
}
}
}
string qa,qb;cin>>qa>>qb;
int tema,temb;
tema = abs(stoi(qa));
temb = abs(stoi(qb));
if(g[tema][temb]==maxn[tema]&&g[tema][temb]==maxn[temb]){
cout<<qa<<" "<<qb;return;
}
if(qa[0]=='-'){
for(auto &t:d){
if(g[tema][t]==maxn[tema]){
cout<<qa<<" "<<t<<"\n";
}
}
}else{
for(auto &t:c){
if(g[tema][t]==maxn[tema]){
cout<<qa<<" "<<"-"<<t<<"\n";
}
}
}
if(qb[0]=='-'){
for(auto &t:d){
if(g[temb][t]==maxn[temb]){
cout<<qb<<" "<<t<<"\n";
}
}
}else{
for(auto &t:c){
if(g[temb][t]==maxn[temb]){
cout<<qb<<" "<<"-"<<t<<"\n";
}
}
}
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _;
//cin>>_;
_ = 1;
while(_--)solve();
return 0;
}
标签:恩爱,t2,t1,int,abs,maxn,stoi,L2,028
From: https://blog.csdn.net/m0_60921016/article/details/137007857