欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

|sex[]_sum[],G_ans|L2-028 秀恩爱分得快

程序员文章站 2022-06-01 23:22:34
...

r
|sex[]_sum[],G_ans|L2-028 秀恩爱分得快

bool cmp(int a, int b) {
	if (abs(a) == 1000)return true;//??????
	if (abs(b) == 1000)return false;
	return abs(a) < abs(b);
}
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

bool cmp(int a, int b) {
	if (abs(b) == 1000)return true;//??????
	if (abs(a) == 1000)return false;
	return abs(a) < abs(b);
}
------------------------------------------
int main()
{
    int a[10]={1,3,999,222,888,1000};
    sort(a,a+10,cmp);
    for(int i=0;i<10;i++)
        cout<<a[i]<<" ";//1000 0 0 0 0 1 3 222 888 999//true
        //0 0 0 0 1 3 222 888 999 1000//false
    return 0;
}

//模拟
/*
10 4
4 -1 2 -3 4
4 2 -3 -5 -6
3 2 4 -5
3 -6 0 2
-3 2
*/

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
const int N = 10010;

int n, m;
vector<int>G[N];
int sex[N] = { 0 };

string s;
int love[3] = { 0 };

double sum[N] = { 0 };//遍历每张照片,把男主女主对应的异性亲密度用sum数字累加起来
//并维护maxn[1],maxn[2]为男女主的最亲密度值
double maxn[3] = { 0 };
//ans[1]和ans[2]为最亲密异性id
vector<int>ans[N];

bool cmp(int a, int b) {
	if (abs(a) == 1000)return true;
	if (abs(b) == 1000)return false;
	return abs(a) < abs(b);
}


int main() {
	cin >> n >> m;//10 4
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			//0 -0
			if (s == "0")s = "1000";
			if (s == "-0")s = "-1000";
			int num = stoi(s);
			sex[abs(num)] = num;
			G[i].push_back(num);
		}
	}
	for (int i = 1; i <= 2; i++) {
		cin >> s;
		if (s == "0")s = "1000";
		if (s == "-0")s = "-1000";
		love[i] = stoi(s);//整理 用love[i]存储自己的编号
	}
	for (int k = 1; k <= 2; k++) {
		for (int i = 0; i < m; i++) {//每一行中,找给出的第1或2个的对象在不在
			int flag = 0;
			for (int j = 0; j < G[i].size(); j++) {
				if (G[i][j] == love[k]) {
					flag = 1;//在的话就标记 找到了
					break;
				}
			}
			if (flag == 1) {//在这一行找到了对象
				for (int j = 0; j < G[i].size(); j++) {
					if (love[k] * G[i][j] < 0) {//妙啊,找异性,我的编号*你的编号<0
						sum[abs(G[i][j])] += 1.0 / G[i].size();//我碰过的都操作=======
					}
				}
			}
		}
	}
	maxn[1] = maxn[2] = -1;
	for (int k = 1; k <= 2; k++) {
		for (int i = 1; i <= 1000; i++) {
			if (love[k] * sex[i] < 0) {
				if (sum[i] > maxn[k]) {//max[1]//max[2]sum[i]=
					maxn[k] = sum[i];
					ans[k].clear();
					ans[k].push_back(sex[i]);
				}
				else if (sum[i] == maxn[k])
					ans[k].push_back(sex[i]);
			}
		}
	}
	if (maxn[1] == sum[abs(love[2]) && maxn[2] == sum[abs(love[1])]]) {
		string s1 = to_string(love[1]), s2 = to_string(love[2]);
		if (love[1] == 1000)s1 = "0";
		if (love[1] == -1000)s1 = "-0";
		if (love[2] == 1000)s2 = "0";
		if (love[2] == -1000)s2 = "-0";
		cout << s1 << " " << s2 << endl;
		return 0;//判断男主女主是否互为最亲密,如果是,输出并return 0
	}
	for (int k = 1; k <= 2; k++) {
		sort(ans[k].begin(), ans[k].end(), cmp);//排序,让0号(1000)排在第一个
		for (int i = 0; i < ans[k].size(); i++) {
			string s1 = to_string(love[k]), s2 = to_string(ans[k][i]);//亲密度从小到大ans
			if (love[k] == 1000)s1 = "0";
			if (love[k] == -1000)s1 = "-0";
			if (ans[k][i] == 1000)s2 = "0";
			if (ans[k][i] == -1000)s2 = "-0";
			cout << s1 << " " << s2 << endl;//否则分别输出他们的最亲密好友
		}
	}
	return 0;
}
相关标签: 天梯