<传送门>

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. python 图片base64 编解码,转换成Opencv,PIL.Image图片格式
  2. 工程师必知的代码重构指南
  3. MySQL从库的列类型不一致导致的复制异常问题
  4. 福建省高职单招分数怎么计算机,2019福建高职单招切线 高职招考分数线是多少...
  5. 2020年,哪些行业涨工资最多?
  6. [转]/etc/passwd文件解析
  7. 三种主流快平台技术测评,你更青睐谁?
  8. Tomcat配置Basic认证方案(一)
  9. linux简单的操作命令
  10. java数组元素的默认值_数组元素默认的初始值都是什么?
  11. qgridlayout 滚动时固定第一行_滚动轴承组合设计应考虑的问题
  12. Java导入导出Excel控件简介
  13. ArcGIS:如何创建地理数据库、创建要素类数据集、导入要素类、表?
  14. 微信小程序即时聊天前后端(TP5+Gateway)
  15. scratch ios html,scratch手机版
  16. elementui表格需要根据值显示文字
  17. WIN7 直装版安装教程
  18. android 陀螺仪简单的使用
  19. 2023.04.27 QT 制作文本编辑器
  20. 今年IBM公司庆祝成立100周年

热门文章

  1. Imperva开源域目录控制器,简化活动目录集成
  2. UIImage的scale
  3. 这些技术人棒棒哒!BingoDay2017获奖名单新鲜出炉~~~
  4. JEECG微云快速开发平台
  5. PHP高级编程SPL
  6. 项目源码分享之[条码扫描后台监控程序]
  7. 【查询】—Entity Framework实例详解
  8. SQL XML 字段操作
  9. Follow Me:CCIE RS--新版CCIE Routing Switching 考纲要点
  10. Windows Mobile 7 梦幻之旅系列1之- What’s New?