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. 【Kth Smallest Element in a BST 】cpp

    题目: Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. ...

  2. Python学习4,字符串

    字符串这个东西主要靠记,多打打就好了. _author_ = "Happyboy" name = "my \tname is happyboy and i am 66 y ...

  3. django-settings里redis连接与缓存配置

    # Django-redis的缓存配置 CACHES = { "default": { "BACKEND": "django_redis.cache. ...

  4. Python全栈工程师(字符串/序列)

    ParisGabriel     Python 入门基础       字符串:str用来记录文本信息字符串的表示方式:在非注释中凡是用引号括起来的部分都是字符串‘’ 单引号“” 双引号''' ''' ...

  5. JAVA相似算法的运用

    今天要处理问题是把一个产品的名字按照其内容对比文档转换出它的中文名. 但是这个文档感觉不全,产品种类有多又杂. 如果像这样写的话 if(xxx.contains()) else if() ... 不知 ...

  6. SQL查询oracle的nclob字段

    使用CONTAINS关键字查询NCLOB字段 SELECT  FORMATTED_MESSAGE    FROM     TBL_LOG WHERE     CONTAINS(FORMATTED_ME ...

  7. Servlet 中 RequestDispacher 请求与分发

    RequestDispacher 请求与分发使用HttpServletRequest的getRequestDispatcher()方法取得 Login.java页面 package control; ...

  8. jQuery选择器之类选择器

    类选择器,顾名思义,通过class样式类名来获取节点. 描述: $('.class') 类选择器,相对于id选择器来说,效率相对会低一些,但是优势就是可以多选. 同样的jQuery在实现上,对于类选择 ...

  9. MVC从Controller到view进行传值的方法

    这几天基本上都是交接的一些杂事,没有什么工作任务,就有空来回顾一下MVC.虽然工作中也用到了MVC,但已经被微软的架构师设计的找不到MVC的影子了,可能有别的考虑吧,至今还没研究出来.所以,今天就来回 ...

  10. Spring 事件机制

    通过模拟邮件的发送,说明Spring的事件监听机制 事件类 package org.zln.module_chapter2.event; import org.springframework.cont ...