Games

举报
辰chen 发表于 2022/06/15 00:29:29 2022/06/15
872 0 0
【摘要】 文章目录 一、Games总结 一、Games 本题链接:Games 题目: A. Games time limit per test1 second memory limit per...

文章目录


一、Games

本题链接Games

题目
A. Games
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 hi, ai (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

inputCopy
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).

本博客给出本题截图
在这里插入图片描述
在这里插入图片描述

题意:两个集合中出现一对元素相同就让结果加一,问有多少组结果

AC代码

#include <iostream>

using namespace std;

const int N = 40;

int h[N], a[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i ++ ) 
        cin >> h[i] >> a[i];

    int res = 0;
    for (int i = 0; i < n; i ++ )
        for (int j = 0; j < n; j ++ )
            if (h[i] == a[j])
                res ++;
    
    cout << res << endl;
    return 0;
}

  
 

总结

双指针优化版想了想没什么想法,以后补上.

文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。

原文链接:chen-ac.blog.csdn.net/article/details/117691198

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。