codeforces 164 Div2 A
2013-02-13 21:24
337 查看
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 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.
Sample test(s)
input
output
input
output
input
output
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).
计算主队队服和客队重复的次数
代码:
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 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.
Sample test(s)
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<iostream> using namespace std; int arr[30][2]={0}; int main(void) { int amount; int i, j; cin>>amount; for( i=0; i<amount; i++) { cin>>arr[i][0]>>arr[i][1]; } int host, ans=0; for( i=0; i<amount; i++) { host=arr[i][0]; for( j=0; j<amount; j++) { if( host==arr[j][1]) ans++; } } cout<<ans<<endl; return 0; }
相关文章推荐
- codeforces 164 Div2 B
- 【数学题】【Codeforces 164 Div2 E】【Playlist】
- python codeforces 322 div2 C
- Mike and gcd problem-codeforces-Round 410 Div2-C
- Codeforces 869C Round #439 Div2 C:排列组合计数
- Codeforces Div. 2 #257-C. Jzzhu and Chocolate
- codeforces水题100道 第二题 Codeforces Beta Round #4 (Div. 2 Only) A. Watermelon (math)
- codeforces水题100道 第二十一题 Codeforces Beta Round #65 (Div. 2) A. Way Too Long Words (strings)
- codeforces 160 Div2 A
- codeforces 261 div2 virtual Participation
- 【codeforces】 Round #287 (Div. 2) C. Guess Your Way Out!
- 【Codeforces Round #411 (Div. 1)】Codeforces 804C Ice cream coloring
- 【CodeForces】CodeForces Round #466 (Div. 2) 题解
- 第八次codeforces竞技结束 #259 Div 2
- 【Codeforces Round #196 (Div. 1)】Codeforces 338D GCD Table
- 第二十五次codeforces竞技结束 #285 Div 2
- 【Codeforces Round #398 (Div. 2)】Codeforces 767C Garland
- 【CodeForces】841D. Leha and another game about graph(Codeforces Round #429 (Div. 2))
- 【比赛总结】Codeforces472 Div1
- codeforces 230 div2 D Tower of Hanoi DP