CF268A.Games
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
Manao 在一家体育电视台工作。他花了大量时间观看某国的足球比赛。一段时间后,他开始注意到一些规律。例如,每支队伍都有两套队服:主场队服和客场队服。当一支队伍在本方主场进行比赛时,球员们穿着主场队服;当一支队伍作为客队在其他球队的体育场比赛时,球员们则穿着客场队服。该规则唯一的例外是:当主队的主场队服颜色与客队的客场队服颜色相同时,主队也需改穿其客场队服。对每支队伍而言,其主场队服与客场队服的颜色均不相同。
共有 n 支队伍参加全国锦标赛。锦标赛共包含 n⋅(n−1) 场比赛:每支队伍均需邀请其余每支队伍到本方主场各进行一场比赛。此时 Manao 想知道:在整个锦标赛期间,主队需要穿客场队服的比赛场次共有多少?注意,比赛的先后顺序并不影响该总数。
你已知每支队伍主场队服与客场队服的颜色。为简化起见,颜色用整数编号,且任意两种不同颜色的编号互不相同。请帮助 Manao 解答这一问题。
输入格式
The first line contains an integer n (2 ≤ n ≤ 30). Each of the following n lines contains a pair of distinct space-separated integers h__i, a__i (1 ≤ h__i, a__i ≤ 100) — the colors of the i-th team's home and guest uniforms, respectively.
第一行包含一个整数 n(2≤n≤30)。接下来的 n 行中,每行包含一对由空格分隔的互不相同的整数 hi、ai(1≤hi,ai≤100),分别表示第 i 支队伍主场和客场队服的颜色。
输出格式
In a single line print the number of games where the host team is going to play in the guest uniform.
在一行中输出主队将穿着客队队服比赛的场次数。
输入输出样例
输入#1
3 1 2 2 4 3 4
输出#1
1
输入#2
4 100 42 42 100 5 42 100 5
输出#2
5
输入#3
2 1 2 1 2
输出#3
0
说明/提示
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).
在第一个测试用例中,锦标赛共包含 6 场比赛。唯一发生所讨论事件的比赛是球队 2 与球队 1 之间在球队 2 的主场进行的比赛。
在第二个测试样例中,主队需在以下比赛(主队列于前面)中穿着客场队服:球队 1 对球队 2、球队 2 对球队 1、球队 2 对球队 3、球队 3 对球队 4、球队 4 对球队 2。
输入解题思路,AI测评打分。不知道怎么写?