zoukankan      html  css  js  c++  java
  • 团体程序设计天梯赛 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;
    }
    
  • 相关阅读:
    DNS 查询长度
    WebSocket
    Overview of cookie persistence
    Linux Cluster
    keepalived + nginx 主主模式
    MIME 类型
    IaaS,PaaS,SaaS 的区别
    Linux下"负载均衡+高可用"集群的考虑点 以及 高可用方案说明(Keepalive/Heartbeat)
    交换机链路聚合与Linux的bond模式对照
    DHCP 中继
  • 原文地址:https://www.cnblogs.com/yuhan-blog/p/12308654.html
Copyright © 2011-2022 走看看