zoukankan      html  css  js  c++  java
  • Codeforces Round #246 (Div. 2) B. Football Kit

    <传送门>

    http://codeforces.com/contest/432/problem/B

    B. Football Kit
     

    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 ≤ 105; xi ≠ 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

    【题目大意】
    N个足球队要打比赛,每支队伍都要和其他N-1支队伍打两场,一场主场一场客场,每支队伍的衣服颜色都有分主场x和y,并且x!=y。原则上主场就穿主场颜色的衣服,客场就穿客场颜色的。但是如果一支队伍的是打客场,并且客场颜色刚好跟对方主场颜色一样,为了可以区分,这支客场的队伍需要穿他们主场的衣服。

    问题就是要我们计算出,在所有比赛结束后,每个队伍的主场和客场衣服各穿了多少次。

    【题目分析】

    首先,每支队伍都要打自己主场的比赛n-1次,所以他们主场颜色的衣服至少是N-1次,剩下的就是n-1次客场作战的比赛中,看他们客场衣服跟其他队主场的冲突次数了。由于颜色使用整数表示,并且不超过100000,所以我们可以直接开个100001大小的数组来统计每种主场颜色出现的次数,这样就可以知道每个队伍的客场跟别人的主场冲突的次数了,相应的客场衣服的次数也就能求出来了。

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<bits/stdc++.h>
    #define MAX 100005
    using namespace std;
    int x[MAX];
    int y[MAX];
    int f[MAX];
    int main()
    {
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&x[i],&y[i]);
            f[x[i]]++;
        }
        int a,b;
        for(int i=0;i<n;i++)
        {
            a=n-1+f[y[i]];
            b=n-1-f[y[i]];
            cout<<a<<" "<<b<<endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    sizeof()使用错例:sizeof(i++)
    修改linux命令符和解决命令符太长的问题
    【转载】阻止拷贝的三种方式
    git命令几个总结
    scp用法
    RAII
    a linked list
    c++11之函数式编程实例
    [转]基于SAML的单点登录介绍
    [转]OAuth、OAuth2与OpenID区别和联系
  • 原文地址:https://www.cnblogs.com/crazyacking/p/3811133.html
Copyright © 2011-2022 走看看