Codeforces Round #320 (Div. 2) B. Finding Team Member
来源:互联网 发布:汉仪字体下载包 mac 编辑:程序博客网 时间:2024/05/27 00:48
There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths aredistinct.
Every contestant hopes that he can find a teammate so that their team’s strength is as high as possible. That is, a contestant will form a team with highest strength possible by choosing a teammate from ones who are willing to be a teammate with him/her. More formally, two people A and B may form a team if each of them is the best possible teammate (among the contestants that remain unpaired) for the other one.
Can you determine who will be each person’s teammate?
There are 2n lines in the input.
The first line contains an integer n (1 ≤ n ≤ 400) — the number of teams to be formed.
The i-th line (i > 1) contains i - 1 numbers ai1, ai2, ... , ai(i - 1). Here aij (1 ≤ aij ≤ 106, all aij are distinct) denotes the strength of a team consisting of person i and person j (people are numbered starting from 1.)
Output a line containing 2n numbers. The i-th number should represent the number of teammate of i-th person.
261 23 4 5
2 1 4 3
34870603831 161856845957 794650 97697783847 50566 691206 498447698377 156232 59015 382455 626960
6 5 4 3 2 1
In the first sample, contestant 1 and 2 will be teammates and so do contestant 3 and 4, so the teammate of contestant 1, 2, 3, 4 will be2, 1, 4, 3 respectively.
这道题的意思是给你N个人,后面是个三角形,n下面从第2行开始算起,第 i 行第 j 个表示第 i 个人和第 j 个人组合在一起的力量值,因为每个人都想要获得最大的力量值,问你要怎么组合才能让双方都满意。
其实做法很简单,就是把输入的值从大到小排列好,然后就可以知道他们的伙伴是谁了,这道题的关键是数组要开多大,因为没有看好题目,RE了四发,后来发现,按照我代码里的输入方法,极限数据是800*799/2,因为第一个for循环的最大值是2*n,第二个for循环的最大值是2*n-1,所以叠在一起就是800*799,又因为没有重复组队,所以还要除以2,这样的话,结构体的数组就要开到319600。
#include<iostream>#include<string.h>#include<stdio.h>#include<algorithm>using namespace std;struct node{int x;int y;int a;};bool cmp(node c,node d){return c.a>d.a;}node num[400000];int ans[1000];int flag[1000];int main(){int n;scanf("%d",&n);int k=0;for(int i=2;i<=2*n;i++){for(int j=1;j<=i-1;j++){scanf("%d",&num[k].a);num[k].x=i;num[k].y=j;k++;}}sort(num,num+k,cmp);for(int i=0;i<k;i++){if(!flag[num[i].x]&&!flag[num[i].y]){ans[num[i].x]=num[i].y;ans[num[i].y]=num[i].x;flag[num[i].x]=1;flag[num[i].y]=1;}}int f=0;for(int i=1;i<=2*n;i++){if(f) printf(" %d",ans[i]);else{f=1;printf("%d",ans[i]);} }printf("\n");return 0;}
- Codeforces Round #320 (Div. 2)B. Finding Team Member
- Codeforces Round #320 (Div. 2) B - Finding Team Member
- Codeforces Round #320 (Div. 2) B. Finding Team Member
- Codeforces Round #320 (Div. 2) 579B Finding Team Member
- Codeforces Round #320 (Div. 2) 579B - Finding Team Member
- Codeforces Round #320 (Div. 2) 579B. Finding Team Member
- Codeforces Round #320 (Div. 2) B. Finding Team Member
- Codeforces Round #320 (Div. 2) B. Finding Team Member
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round]B Finding Team Member
- codeforces 578 B. Finding Team Member( Codeforces Round #320 (Div. 2) )
- Codeforces Round #320 (Div. 2) 579B Finding Team Member(脑洞)
- cf#320 Div.2 Problem B Finding Team Member
- B. Finding Team Member
- Codeforces Round #356 (Div. 2) B Bear and Finding Criminals
- 579B(Finding Team Member)
- coderforce 579B. Finding Team Member
- Finding Team Member
- ★【16.6.2】Codeforces Round #356 (Div. 2) B. Bear and Finding Criminals
- MSSql Server基础学习系列———分页查询
- 用户登录界面.cs
- OC基础教程3-继承+复合
- UiAutomator 简单测试脚本示例
- 生活随笔:又一个小伙伴结婚了
- Codeforces Round #320 (Div. 2) B. Finding Team Member
- 使用 Spring Data JPA 简化 JPA 开发
- 用Python学习统计学基础-4
- 51Nod 1459 迷宫游戏 dijkstra拓展
- 第一章 绪论
- winform chart使用参考
- iBATIS操作Oracle CLOB数据
- 2016大众点评校招笔试-Android开发
- hadoop1.x中IPC协议