Codeforces Round #246 (Div. 2)(B)数学

来源:互联网 发布:网络安全法的特点 编辑:程序博客网 时间:2024/06/08 21:38

B. Football Kit
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 test(s)
input
21 22 1
output
2 02 0
input
31 22 11 3
output
3 14 02 2




题意:有n个球队相互比赛(要比n*(n-1)次),他们有主场服装和客场服装,颜色不相同。穿戴规则如下:


如果是主场,穿主场的服装


如果是客场,分2种情况

如果客场时的客场服装颜色与对方的主场衣服颜色相同,那么就穿自己的主场衣服。否则就穿直接穿客场服装。




题解:首先我们要知道每支队伍都要穿2*(n-1)次衣服,先使用数字统计主场,客场各自颜色数量。

然后就是一支队伍,最少要穿n-1次主场服装。然后要穿与自己客场相同颜色的主场次数次主场服装(很绕口,看不懂直接看代码吧。。。),然后用2*(n-1)减去主场的次数,剩下来就是客场的次数了。


#include <set>  #include <map>  #include <list>   #include <cmath>   #include <queue>   #include <vector>  #include <cstdio>   #include <string>   #include <cstring>  #include <iomanip>   #include <iostream>   #include <sstream>  #include <algorithm>  #define LL long long using namespace std;  #define N 200000 #define inf 0x3f3f3f3fLL x[N],y[N];struct point{LL xx,yy;}ans[N];LL n,xi[N],yi[N];int main()  {  #ifdef CDZSC    freopen("i.txt","r",stdin);  #endif  while(~scanf("%lld",&n)){memset(x,0,sizeof(x));memset(y,0,sizeof(y));for(int i=0;i<n;i++){scanf("%lld%lld",&xi[i],&yi[i]);x[xi[i]]++;y[yi[i]]++;}for(int i=0;i<n;i++){ans[i].xx=x[yi[i]]+n-1;ans[i].yy=2*(n-1)-ans[i].xx;}for(int i=0;i<n;i++){printf("%lld %lld\n",ans[i].xx,ans[i].yy);}}return 0;}










0 0
原创粉丝点击