• Codeforces Round #164 (Div. 2) A. Games【暴力/模拟/每个球队分主场和客场,所有球队两两之间进行一场比赛,要求双方球服颜色不能相同】


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

    Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.

    There are n teams taking part in the national championship. The championship consists of n·(n - 1)games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.

    You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.

    Input

    The first line contains an integer n (2 ≤ n ≤ 30). Each of the following n lines contains a pair of distinct space-separated integers hiai (1 ≤ hi, ai ≤ 100) — the colors of the i-th team's home and guest uniforms, respectively.

    Output

    In a single line print the number of games where the host team is going to play in the guest uniform.

    Examples
    input
    3
    1 2
    2 4
    3 4
    output
    1
    input
    4
    100 42
    42 100
    5 42
    100 5
    output
    5
    input
    2
    1 2
    1 2
    output
    0
    Note

    In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.

    In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).

    【代码】:

    #include <bits/stdc++.h>
    /*
    题意:有n个球队,每个球队分主场和客场
    所有球队两两之间进行一场比赛,要求双方球服颜色不能相同
    问你需要准备多少种球服。
    */
    using namespace std;
    const int N = 150;
    int cnt=0;
    int n;
    int a[N],b[N];
    int main()
    {
        while(cin>>n)
        {
            for(int i=1;i<=n;i++)
                cin>>a[i]>>b[i];
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)//当了主场 又在客场出现
                    if(a[i]==b[j])
                        cnt++;
            cout<<cnt<<endl;
        }
        return 0;
    }
    傻逼模拟
  • 相关阅读:
    bzoj 1444: [Jsoi2009]有趣的游戏【AC自动机+dp+高斯消元】
    bzoj 3270: 博物馆【dp+高斯消元】
    bzoj 3105: [cqoi2013]新Nim游戏【线性基+贪心】
    bzoj 1923: [Sdoi2010]外星千足虫【高斯消元】
    bzoj 3629: [JLOI2014]聪明的燕姿【线性筛+dfs】
    bzoj 1296: [SCOI2009]粉刷匠【dp+背包dp】
    bzoj 3329: Xorequ【数位dp+矩阵乘法】
    bzoj 1306: [CQOI2009]match循环赛【dfs+剪枝】
    bzoj 4720: [Noip2016]换教室【期望dp】
    bzoj 2257: [Jsoi2009]瓶子和燃料【裴蜀定理+gcd】
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7931809.html
Copyright © 2020-2023  润新知