L2-028 秀恩爱分得快

可恶的模拟,借鉴了别人的思路,这样写很清晰

#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;
}

  • 25
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值