R - Games
Problem description
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
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).
解题思路:题目的意思就是如果主队hi有在客场aj踢球,即当i!=j时,hi==aj(题目已保证i==j时,hi!=aj,即自己不会跟自己比赛),计数器m就加1,最后输出m即可,暴力简单过!
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m=,h[],a[];cin>>n;
for(int i=;i<n;++i)
cin>>h[i]>>a[i];
for(int i=;i<n;++i)
for(int j=;j<n;++j)
if(i!=j&&h[i]==a[j])m++;
cout<<m<<endl;
return ;
}
R - Games的更多相关文章
- RESTframework简介
什么是RESTful? RESTful是一种开发理念,REST是Roy Thomas Fileding在他博文提出的.REST特点;url简洁,将参数通过url传递到服务器,简单就是说URL定位资源, ...
- Linux题库练习
转一个Linux的题库供自己学习使用(滑稽) 转自:http://www.linuxdiyf.com/view_202485.html 选择题1 在终端下输入mount -a命令的作用是:CA 强制进 ...
- django 之(二) --- 源码分析
CBV类视图继承 CBV:继承自View:注册的时候使用的as_view() 入口 不能使用请求方法的名字作为参数的名字 只能接受已经存在的属性对应的参数 定义了一个view 创建了一个类视图对象 保 ...
- Linux 基础优化
1.操作的最小化原则 1)安装系统最小化 一般情况下安装OS时,软件安装包组(Package Group)的选择: base--------------------------基本环境 editors ...
- [原]CentOS7安装Rancher2.1并部署kubernetes (二)---部署kubernetes
################## Rancher v2.1.7 + Kubernetes 1.13.4 ################ ##################### ...
- 利用python进行数据分析2_数据采集与操作
txt_filename = './files/python_baidu.txt' # 打开文件 file_obj = open(txt_filename, 'r', encoding='utf-8' ...
- Django项目:CRM(客户关系管理系统)--81--71PerfectCRM实现CRM项目首页
{#portal.html#} {## ————————46PerfectCRM实现登陆后页面才能访问————————#} {#{% extends 'king_admin/table_index.h ...
- CF456D A Lot of Games (字典树+DP)
D - A Lot of Games CF#260 Div2 D题 CF#260 Div1 B题 Codeforces Round #260 CF455B D. A Lot of Games time ...
- 运行(WIN+R)中能使用的命令:ms-settings:,shell:,cpl,mmc...
ms-settings: --- DESC --- --- CMD --- Battery Saver ms-settings:batterysaver Battery Saver Settings ...
随机推荐
- iOS 中plist文件中配置key值冲突的现象
iOS开发一些特殊的软件需要在项目中配置对应的key值,然而近期在项目中发现一个有意思的现象,苹果官方文档中提供的key值很多,但其实有一些彼此可能有冲突,当你同时配置了彼此冲突的key值,可能会出现 ...
- 求n!(高精度问题)
#include <iostream> #include <stdio.h> #define MAX 10000 using namespace std; void Mul(i ...
- 233 Matrix 矩阵快速幂
In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233 ...
- 洛谷 P3078 [USACO13MAR]扑克牌型Poker Hands
P3078 [USACO13MAR]扑克牌型Poker Hands 题目描述 Bessie and her friends are playing a unique version of poker ...
- cogs 22. [HAOI2005] 路由选择问题
22. [HAOI2005] 路由选择问题 ★★★ 输入文件:route.in 输出文件:route.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] X城有一个 ...
- android程序在调试时出现了套接字异常“java.net.SocketException: Permission denied”该如何解决
Socket不能对外连接,错误不会被报出,调试的时候,能看到Exception, 一般是抛出 java.net.socketexception permission denied这个异常.只要你的程序 ...
- array_change_key_case()
定义和用法 array_change_key_case() 函数将指定数组的所有的键进行大小写转换. 如果数组的键(索引)为数字则不发生变化.如果未提供第二个参数,则默认转换为小写. 语法 array ...
- c++ 双冒号的作用
转:原文:http://www.cnblogs.com/charley_yang/archive/2011/02/24/1964217.html #define FLY 10 #line 100 &q ...
- php导入sql文件
php导入sql文件 sql php php导入sql文件 基本思路 1.打开sql文件,放入一个变量(字符串类型)其中 2.使用正则替换掉其中的凝视("--"与"/** ...
- ExecutorCompletionService原理具体解释
在JDK并发包中有这么一个类ExecutorCompletionService,提交任务后,能够按任务返回结果的先后顺序来获取各任务运行后的结果. 该类实现了接口CompletionService: ...