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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- Javascript函数式编程的一些例子[转载]
函数式编程风格 通常来讲,函数式编程的谓词(关系运算符,如大于,小于,等于的判断等),以及运算(如加减乘数等)都会以函数的形式出现,比如: a > b通常表示为: gt(a, b)/ ...
- hdu 4893Wow! Such Sequence!
多校第三场 7题..线段树A的 #include <cstdio> #include <cstring> #include <iostream> #include ...
- 百度编辑器同一id重复调用不能生效的办法
在使用js 调用表单组件模板的时候,表单内有一个编辑框 第一次调出的时候,百度编辑器正常显示,关闭后,再打开,百度编辑器不能显示 原因:第一次使用的时候, UE.getEditor('node_con ...
- Spark Streaming ReceiverTracker架构设计
本节的主要内容: 一.ReceiverTracker的架构设计 二.消息循环系统 三.ReceiverTracker具体实现 Spark Streaming作为Spark Core基础 架构之上的一个 ...
- 给Swing的GUI组件设置前景色和背景色
JButton btn=new JButton("TEST"); btn.setForeground(Color.white);// 设置前景色(文字颜色)btn.setBackg ...
- UVA 10441 - Catenyms(欧拉道路)
UVA 10441 - Catenyms 题目链接 题意:给定一些单词,求拼接起来,字典序最小的,注意这里的字典序为一个个单词比过去,并非一个个字母 思路:欧拉回路.利用并查集判联通,然后欧拉道路判定 ...
- C基础测试
一.用指针的方法,把输入的一个字符串按逆序重新排序其字符,并输出. #include <stdio.h> #include <string.h> void main( ) { ...
- 病毒木马查杀实战第015篇:U盘病毒之脱壳研究
前言 因为我们的终于目标是编写出针对于这次的U盘病毒的专杀工具.而通过上次的分析我们知道,病毒有可能在不同的计算机中会以不同的名称进行显示.假设真是如此,那么就有必要在此分析出病毒的命名规律等特征,然 ...
- python之sqlalchemy基本
一.SQLAlchemy 1.sqlalchemy是一个ORM框架,它本身无法操作数据库,需要依赖pymysql.MySQLdb,mssql等第三方插件 2.安装: pip install SQLAl ...
- Request常用方法
一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...