天天刷水题~~~(此题题意有点难理解)

来源:互联网 发布:网络攻击日语 编辑:程序博客网 时间:2024/05/17 14:15
Football Kit
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status

Description

Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi(xi ≠ yi).

In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.

Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.

Input

The first line contains a single integer n(2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xiyi(1 ≤ xi, yi ≤ 105xi ≠ yi) — the color numbers for the home and away kits of the i-th team.

Output

For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.

Sample Input

Input
21 22 1
Output
2 02 0
Input
31 22 11 3
Output
3 14 02 2

题意:n个球队,每个球队(设为a)在自己主场与其他球队(穿客场服)打n-1场比赛,若有球队队客场服与a队主场服相同则该队改穿自己的主场服,求各队主场服和客场服的使用次数
思路:数组a[i]:i表示主场服类型,a[i]表示主场服类型为i的球队的个数;b[i]:表示第i支球队客场服的类型;第i支球队使用主场服的次数为n-1+其客场服与其他球队主场服同类型的个数(即a[b[i]]),使用客场服的次数为n-1-其客场服与其他球队主场服同类型的个数(即a[b[i]])。
#include <cstdio>#define MAX 100000+5int n;int a[MAX],b[MAX],c;int main(){    int i;    scanf("%d",&n);    for(i = 0; i < n; i++){        scanf("%d%d",&c,&b[i]);        a[c]++;    }    for(i = 0; i < n; i++)        printf("%d %d\n",n-1+a[b[i]],n-1-a[b[i]]);}
0 0