CodeForces 579b
2 seconds
256 megabytes
standard input
standard output
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.
2
6
1 2
3 4 5
2 1 4 3
3
487060
3831 161856
845957 794650 976977
83847 50566 691206 498447
698377 156232 59015 382455 626960
6 5 4 3 2 1
#include<string.h>
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node
{
int a,b;
int wei;
}team[];
bool cmp(Node n1,Node n2){
return n1.wei>n2.wei;
}
int main(){
int n;
int ans[];
int t=;
scanf("%d",&n);
for(int i=;i<*n+;i++){
ans[i]=-;
}
for(int i=;i<=*n;i++){
for(int j=;j<i;j++){
scanf("%d",&team[t].wei);
team[t].a=j;
team[t].b=i;
t++;
}
}
sort(team,team+t,cmp);
for(int i=;i<t;i++){
if(ans[team[i].a]<&&ans[team[i].b]<){
ans[team[i].a]=team[i].b;
ans[team[i].b]=team[i].a; }
}
int flag=;
for(int i=;i<=n*;i++){
if(flag) printf(" ");
printf("%d",ans[i] );
flag=;
}
printf("\n");
return ;
}
水题,但是要注意题目给出到是n支队伍,而不是n个人,开始到时候wa了多次,因为没有注意到这一点。
CodeForces 579b的更多相关文章
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- Linux驱动mmap内存映射
mmap在linux哪里? 什么是mmap? 上图说了,mmap是操作这些设备的一种方法,所谓操作设备,比如IO端口(点亮一个LED).LCD控制器.磁盘控制器,实际上就是往设备的物理地址读写数据. ...
- MyEclipse安装后需要进行的配置
摘自: http://hi.baidu.com/timesten/item/c826983a6f9654ffde2221c0 MyEclipse安装后需要进行的配置 在MyEclipse中编写Web ...
- 在移动网页网页上点击链接跳转到QQ聊天界面
打开qq聊天窗口的方法 <a href="http://wpa.qq.com/msgrd?v=3&uin=1450612626&site=qq&menu=yes ...
- SSMybatis整合(二) -- 加入SpringMVC进行多表级联操作
---上节课我们讲了Mybatis的单表增删改查,关于代码我注释的比较详细,我相信初学的小伙伴还是多少能有一些收获的. - 第一集传送门:http://blog.csdn.net/jacxuan/ar ...
- iOS 使用NSUserdefault 保存自定义的 对象
一:NSUserDefaults支持的数据格式有:NSNumber(Integer.Float.Double),NSString,NSData,NSArray,NSDictionary,BOOL类型: ...
- 使用python语言编写脚本控制freeswitch总结
1. 在Linux环境下已经安装了freeswitch,(没安装freeswitch,请安装说明文档) 2. 进入源代码目录 cd libs/esl 目录下 首先安装 yum install p ...
- 最小公倍数 【杭电-HDOJ-1108】 附题+具体解释
/* 最小公倍数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- Qt-优化布局结构
在迄今为止讲到每一个例子中,我们只是简单的把窗口部件放置到某个确定的布局中.但在某些情况下,由此形成的布局看起来可能还不是我们最想要的形式.在这些情形中,可以通过改变要摆放的窗口部件的大小策略和大小提 ...
- Python-装饰器进阶
基本概念 具体概念请先看之前的文章 理解装饰器 装饰器是一个很著名的设计模式,经常被用于有切面需求的场景,较为经典的有插入日志.性能测试.事务处理, Web权限校验, Cache等. 很有名的例子,就 ...
- asp.net 查询本地excel 获取信息
string filepath = @"D:\test1.xls"; string sheetname = "Sheet5"; ...