<传送门>

http://codeforces.com/contest/432/problem/B

B. Football Kit
 

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 ≤ 105; xi ≠ 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-1支队伍打两场,一场主场一场客场,每支队伍的衣服颜色都有分主场x和y,并且x!=y。原则上主场就穿主场颜色的衣服,客场就穿客场颜色的。但是如果一支队伍的是打客场,并且客场颜色刚好跟对方主场颜色一样,为了可以区分,这支客场的队伍需要穿他们主场的衣服。

问题就是要我们计算出,在所有比赛结束后,每个队伍的主场和客场衣服各穿了多少次。

【题目分析】

首先,每支队伍都要打自己主场的比赛n-1次,所以他们主场颜色的衣服至少是N-1次,剩下的就是n-1次客场作战的比赛中,看他们客场衣服跟其他队主场的冲突次数了。由于颜色使用整数表示,并且不超过100000,所以我们可以直接开个100001大小的数组来统计每种主场颜色出现的次数,这样就可以知道每个队伍的客场跟别人的主场冲突的次数了,相应的客场衣服的次数也就能求出来了。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<bits/stdc++.h>
#define MAX 100005
using namespace std;
int x[MAX];
int y[MAX];
int f[MAX];
int main()
{int n;cin>>n;for(int i=0;i<n;i++){scanf("%d%d",&x[i],&y[i]);f[x[i]]++;}int a,b;for(int i=0;i<n;i++){a=n-1+f[y[i]];b=n-1-f[y[i]];cout<<a<<" "<<b<<endl;}return 0;
}

View Code

转载于:https://www.cnblogs.com/crazyacking/p/3811133.html

Codeforces Round #246 (Div. 2) B. Football Kit相关推荐

  1. Codeforces Round #246 (Div. 2)

    主题链接:Codeforces Round #246 (Div. 2) A:直接找满足的人数.然后整除3就是答案 B:开一个vis数组记录每一个衣服的主场和客场出现次数,然后输出的时候主场数量加上反复 ...

  2. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes kmp + dp

    传送门 文章目录 题意: 思路: 题意: 思路: 通过完美子串的定义,我们不难发现满足条件的子串就是kmpkmpkmp中ne[n]ne[n]ne[n]不断向前跳得到的串,现在问题就是如何求这些前缀串在 ...

  3. Codeforces Round #246 (Div. 2) D. Prefixes and Suffixe 后缀数组

    链接: codeforces.com/contest/432/problem/D 题意: 给你一个字符串,求每一个和前缀匹配的后缀在这个字符串中出现的次数 题解: 先算出lcp,找到sa[i]==0的 ...

  4. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  5. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  6. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  7. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  8. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  9. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

最新文章

  1. Spring Boot + GraphQL 才是 API 的未来!
  2. eclipse中使用javap分析java代码备忘
  3. python抓取网页信息_python抓取网页中的动态数据
  4. Nginx的启动、停止和重启
  5. c语言编译器怎样退出全屏,BOOX 应用软件怎样退出全屏模式?
  6. 【CF#505B】Mr. Kitayuta's Colorful Graph (并查集或Floyd或BFS)
  7. iOS有哪些数据类型/基本数据类型?
  8. 下载安装vs2019详细版
  9. 可解释性系列论文:Mathematics of Deep Learning
  10. Daily Scrum 12.13
  11. 双11,移动电商如何更好地吸引女性购物?
  12. 微信支付V3-企业转账至零钱1/2
  13. 2016年蓝桥杯java——分小组
  14. linux的7za无法使用,提示命令找不到:-bash 7za command not found的解决方法.doc
  15. 刚进公司就把祖上十八代单传的代码优化了是什么体验?
  16. 服务器2003系统怎么卸载软件,WindowsXP系统添加删除程序的方法
  17. 《智能设备艺术、科技、文化作品实例开发与设计》android开发系列介绍---2.1棋类作品:华容道
  18. 【电气专业知识问答】问:高压断路器大修后运行人员需了解哪些试验工作及结论?
  19. linux查看双路cpu三级缓存,Intel谈八核心Xeon 24MB超大三级缓存技术
  20. Django文件部署(2.关于换源的一点小事)(全)

热门文章

  1. Paging Library使用及原理
  2. 性能测试总结(一)---基础理论篇
  3. 企业并不怕尝新 业务变革的技术们
  4. Android -- TouchDelegate
  5. golang atomic 32位机器问题
  6. 终于恢复了珍惜多年的照片
  7. C 内存free()出错
  8. 制作win2000能用的 schtasks.exe
  9. ubuntu16.04安装mysql5.7.15
  10. pandoc文档书写