Codeforces Round #164 (Div. 2) A. Games 【水题】

博客分析了Codeforces Round #164中A. Games的问题,指出每支队伍在主场时,只有当主队和客队的球衣颜色相同时,主队才会穿客队球衣。文章通过举例说明,并给出了一种解决方案,求解在整个锦标赛中主队需要穿客队球衣的比赛次数。内容包括问题描述、数据范围和输入输出格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
0 5
5 42
1 0
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).



题意:有n个球队,每个球队分主场和客场,所有球队两两之间进行一场比赛,要求双方球服颜色不能相同,问你需要准备多少种球服。

AC代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{

    int a[31],b[31];
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
            cin>>a[i]>>b[i];
        int ans=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i!=j&&a[i]==b[j])
                    ans++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

尊重原创,转载请注明出处:http://blog.youkuaiyun.com/hurmishine
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值