• 团体程序设计天梯赛 L2-028 秀恩爱分得快 (25分)


    题目链接:

    L2-028 秀恩爱分得快 (25分)

    思路:

    此题大体思路就是排序,然后判断输出;
    但需要注意两个点:
    1.需要注意0编号人是男生还是女生,输入输出都需要注意;
    2.我们只需要考虑和a、b有关的人,无需考虑其他人的亲密度;

    代码:

    #include<bits/stdc++.h>
    
    using namespace std;
    
    #define fi first
    #define sc second
    typedef pair<double, int> P;
    const int maxn = 1005;
    int n, m, sex[maxn], a, b;
    vector<int> p[maxn];
    double rx[maxn], ry[maxn];
    
    inline int read() {
    	int x = 0, f = 1; char c = getchar();
    	while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
    	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    	sex[x] = f;
    	return x;
    }
    inline void out(int x) { if(x > 9) out(x/10); putchar(x % 10 + '0'); }
    inline void put(int & x,int & y) { 
    	if(sex[x] < 0) putchar('-'); out(x); putchar(' '); 
    	if(sex[y] < 0) putchar('-'); out(y); putchar('
    ');
    }
    bool cmp(const P & x, const P & y) {
    	if(x.fi == y.fi) {
    		if(x.sc == a || x.sc == b) return true;
    		if(y.sc== a || y.sc == b) return false;
    		return x.sc < y.sc;
    	}
    	return x.fi > y.fi;	
    }
    inline void deal(int x, vector<P> & v) {
    	for(int i = 0; i < v.size(); i++) {
    		if(i && v[i].fi < v[i - 1].fi) break;
    		put(x, v[i].sc);
    	}
    }
    
    int main() {
    #ifdef MyTest
    	freopen("Sakura.txt", "r", stdin);
    #endif
    	scanf("%d %d", &n, &m);
    	for(int i = 0; i < m; i++) {
    		int k; scanf("%d", &k);
    		p[i].resize(k);
    		for(int j = 0; j < k; j++) p[i][j] = read();
    	}
    	a = read(), b = read(); 
    	for(int i = 0; i < m; i++) for(int & x : p[i]) {
    		if(x == a) for(int & y : p[i]) rx[y] += 1.0 / p[i].size();
    		if(x == b) for(int & y : p[i]) ry[y] += 1.0 / p[i].size();
    	}
    	vector<P> pa, pb;
    	for(int i = 0; i < n; i++) {
    		if((sex[i] ^ sex[a]) < 0) pa.push_back(P(rx[i], i));
    		if((sex[i] ^ sex[b]) < 0) pb.push_back(P(ry[i], i));
    	}
    	sort(pa.begin(), pa.end(), cmp);
    	sort(pb.begin(), pb.end(), cmp);
    	if(pa.size() && pb.size() && pa[0].sc == b && pb[0].sc == a) put(a, b);
    	else { deal(a, pa); deal(b, pb); }
    	return 0;
    }
    
  • 相关阅读:
    密码控件安全技术浅析及攻击实例
    一个QQ木马的逆向分析浅谈(附带源码)
    菜鸟开始学习SSDT HOOK((附带源码)
    leetcode229
    leetcode1401
    leetcode1400
    leetcode1399
    leetcode228
    leetcode223
    leetcode222
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308654.html
Copyright © 2020-2023  润新知