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 = ;
int cnt=;
int n;
int a[N],b[N];
int main()
{
while(cin>>n)
{
for(int i=;i<=n;i++)
cin>>a[i]>>b[i];
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)//当了主场 又在客场出现
if(a[i]==b[j])
cnt++;
cout<<cnt<<endl;
}
return ;
}

傻逼模拟

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

  1. codeforces水题100道 第十六题 Codeforces Round #164 (Div. 2) A. Games (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/268/A题意:足球比赛中如果主场球队的主场球衣和客队的客队球衣颜色一样,那么要求主队穿上他们的可对 ...

  2. Codeforces Round #369 (Div. 2) A B 暴力 模拟

    A. Bus to Udayland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #368 (Div. 2) B. Bakery (模拟)

    Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...

  4. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  6. Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力

    B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...

  7. Codeforces Round #328 (Div. 2) A. PawnChess 暴力

    A. PawnChess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/592/problem/ ...

  8. Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)

    A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...

  9. Codeforces Round #164 (Div. 2)

    A. Games 模拟. B. Buttons 简单计数. C. Beautiful Sets of Points 显然每行每列只能有一个点,那么最大点数为\(1+min(n, m)\). 在不考虑\ ...

随机推荐

  1. 《算法》C++代码 Floyd

    今天写写最短路径的Floyd算法(有翻译叫弗洛伊德,不过这奇葩翻译用来读读就好……). 这个算法的实质,广义来讲,其实是DP(动态规划).其实按说,算法应该先说说什么贪心.搜索.DP.二分之类的基本算 ...

  2. Python 3基础教程12-常见的错误

    本文来介绍几种常见的错误,任何人在刚开始接触一个新的语言,即使照着代码抄写,也可能会犯错误,这里我们就介绍几种常见的错误,看看你是否遇到过. 1. NameError: name 'xxx' is n ...

  3. JMeter学习笔记(七) 导出文件接口测试

    导出文件接口,其实跟下载文件接口的测试类似,主要就是执行接口导出文件后保存到本地. 下载文件接口测试,参考文档:https://www.cnblogs.com/xiaoyu2018/p/1017830 ...

  4. SQL面试题:之一(难度:中等)

    SQL面试题:之一(难度:中等)

  5. python3.x 安装命令

    在root下执行下面的命令即可: sudo apt-get install python3-dev build-essential libssl-dev libffi-dev libxml2 libx ...

  6. Ubuntu16.04 问题汇总

    Ubuntu16.04安装wps并解决系统缺失字体问题 http://www.cnblogs.com/liutongqing/p/6388160.html

  7. 聊聊、AES 和 DES

    AES 和 DES 都是对称加密的一种,但是 DES 的 Key 是 56 位,而 AES 的 Key 有 128,256,512 可选. AES 加密AES String randomKey = & ...

  8. java中newInstance和new(转)

    在Java开发特别是数据库开发中,经常会用到Class.forName( )这个方法.通过查询Java Documentation我们会发现使用Class.forName( )静态方法的目的是为了动态 ...

  9. GCD 开发详情

    目录 一.简介 二.dispatch Queue - 队列 三.dispatch Groups - 组 四.dispatch Semaphores - 信号量 五.dispatch Barriers ...

  10. 【bzoj3675】[Apio2014]序列分割 斜率优化dp

    原文地址:http://www.cnblogs.com/GXZlegend/p/6835179.html 题目描述 小H最近迷上了一个分隔序列的游戏.在这个游戏里,小H需要将一个长度为n的非负整数序列 ...