Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] B. Finding Team Member 排序

B. Finding Team Member

time limit per test

2 seconds

memory limit per test

256 megabytes

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 are distinct.

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?

Input

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

Output a line containing 2n numbers. The i-th number should represent the number of teammate of i-th person.

Sample test(s)

Input

261 23 4 5

Output

2 1 4 3

题解:没脑子的找就是了

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
#define maxn 800+6
vector< pair<int ,pair<int ,int > > > mp;
set<int >s;
int ans[maxn];
int main()
{

   int n,x;
   cin>>n;
    for(int i=2;i<=2*n;i++)
    {
        for(int j=1;j<i;j++)
        {
          cin>>x;
            mp.push_back(make_pair(x,make_pair(i,j)));
        }
    }
    sort(mp.begin(),mp.end());
    int k=mp.size();
    for(int i=k-1;i>=0;i--)
    {
        if(s.count(mp[i].second.first)||s.count(mp[i].second.second))continue;
        s.insert(mp[i].second.first);
        s.insert(mp[i].second.second);
        ans[mp[i].second.first]=mp[i].second.second;
        ans[mp[i].second.second]=mp[i].second.first;
    }
    for(int i=1;i<=2*n;i++)
        cout<<ans[i]<<" ";
    return 0;
}

代码

时间: 2024-11-05 03:12:29

Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] B. Finding Team Member 排序的相关文章

Codeforces Round #320 (Div. 2) [Bayan Thanks-Round]

一部分题解,算是自己SB了 上午的TC 也是这样 写好了代码,却一直没注意细节,然后以为错了. 此处省100字,ps 貌似紫了,作为一个老菜鸡,终于紫了 A,B 都是语文题 C: 给以一个三角形一样的图,判断点(a,b)是否在图中,我是这样判断的: 前一半是k*2*x+b=a;求最小的x,这里二分,但是注意k=0,所以你特判掉: 后一半是:2*(k+1)=a+b;二分类似 D:坐等官方题解,不靠谱系列:我试了很多方法: 做法:只可能是一个数*x^k: 之前以为是最大数*x^k ,但是错的 想想:

Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline

题目中给出的函数具有周期性,总可以移动到第一个周期内,当然,a<b则无解. 假设移动后在上升的那段,则有a-2*x*n=b,注意限制条件x≥b,n是整数,则n≤(a-b)/(2*b).满足条件的x≥(a-b)/(2*n) 假设在下降的那段,2*x-(a-2*x*n)=b,n+1≤(a+b)/(2*b),x≥(a+b)/(2*(n+1)) 两者取最小值 #include<bits/stdc++.h> using namespace std; int main() { int a,b; sc

Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness

f(x)是个凹函数,三分即可,计算方案的时候dp一下.挂精度很坑,指定循环次数正解? #include<bits/stdc++.h> using namespace std; const double eps = 1e-11; const int maxn = 2e5+5; double a[maxn]; double d1[maxn],d2[maxn]; int n; inline double cal(double x) { double a1 = 0., a2 = 0.; for(int

[Codeforces] Round #320 (Div.2)

1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序 题意 有 a[ i ] 个数 要求选最多的数 使其和不超过 S ,且在此情况下,和最小选最多数情况下 和最小 且 每个数有加成 如果选了 k个数 那么加成后 就是 a[ i ] + k*i ; 题解 二分mid 表示选了个数 加成一下,将加成以后结果排序一下 , 若前 mid数 和大于 s 则此方案不可行 PS 要用 long long ..... 还有 co

Codeforces Round #320 (Div. 2) &quot;Or&quot; Game(好题,贪心/位运算/前缀后缀或)

1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 using namespace std; 6 typedef long long ll; 7 /* 8 n个数,你最多有k次操作,每次操作可以选择一个数乘以x,问所有数或(|)的最大值 9 贪心思路:选一个数进行k此乘以x操作; 因为x>=2 10 111 ---> 1111 11

codeforces Round #320 (Div. 2) C. A Problem about Polyline(数学)

解题思路: 我们可以发现这样的一个规律: (1)首先b一定要小于a,否则无论如何曲线也无法通过(a,b); (2)设int k=a/b, 如果k为奇数,说明这个点在上图的绿色的线上, 没关系,我们让 k+=1:这样的话一定有(0,0), (a,b)这两点确定的直线的 斜率1/k介于(1/(k-1),  1/(k+1))之间,那么我们可以通过缩小(或者放大)X的值,使得第 k/2 个周期块 斜率为-1的那条边经过(a, b).此时 的X值就是最小的! (3)如果(a,b)在第 k/2 个周期块 斜

CodeForces #Round 320 (div 1) 简要记录

A 题意: 目前平面上有一条折线,其通过的点分别为(0,0)->(x,x)->(2x,0)->(3x,x)-.. x等于1的时候大概就是这样子 然后给定一个整数点(a,b) 询问最小的x值使折线经过这个点. 解析: 好吧其实我一直以为这是一个结论题,然后一直想有没有什么神奇的结论,结果被数学公式D的飞起. 首先a a==b直接输出a即可. a>b的时候, 有两种可能,第一种是y=x-(a-b) 另一种是y=-x+(a+b) 我们先感受一个情况,所有由斜率为1的直线经过的点都可以用斜

Codeforces Round #415 (Div. 2)(A,暴力,B,贪心,排序)

A. Straight «A» time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year.