• Codeforces Round #246 (Div. 2):B. Football Kit


    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).

    In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.

    Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.

    Input

    The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xiyi (1 ≤ xi, yi ≤ 105xi ≠ yi) — the color numbers for the home and away kits of the i-th team.

    Output

    For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.

    Sample test(s)
    input
    2
    1 2
    2 1
    
    output
    2 0
    2 0
    
    input
    3
    1 2
    2 1
    1 3
    
    output
    3 1
    4 0
    2 2
    两个for循环肯定超时,注意优化。


    
    #include<cstdio>
    #include<algorithm>
    #include<iostream>
    #include<cstring>
    
    using namespace std;
    
    #define M 100005
    int  x[M];
    int  y[M];
    int  a[M];
    int  b[M];
    
    int main()
    {
        int n, i;
        while(~scanf("%d", &n))
        {
           memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            for(i=0;i<n;i++)
            {
                scanf("%d%d",&x[i],&y[i]);
                a[x[i]]++;b[y[i]]++;
            }
            for(i=0;i<n;i++)
            {
                printf("%d %d
    ",((n-1)+a[y[i]]),((n-1)-a[y[i]]));
            }
    
        }
    
        return 0;
    }


  • 相关阅读:
    acwing 164. 可达性统计(拓扑排序+位运算,bitset使用)
    csp 2020062 稀疏向量(双指针)
    acwing 二分图的最大匹配(匈牙利算法)
    acwing 860. 染色法判定二分图(dfs,bfs)
    acwing 1140. 最短网络(prim)
    acwing 3745. 牛的学术圈 I(构造)
    CF585F Digits of Number Pi
    剩余系建图
    P5445 [APIO2019]路灯
    P8097 [USACO22JAN] Farm Updates G
  • 原文地址:https://www.cnblogs.com/twodog/p/12140573.html
Copyright © 2020-2023  润新知