579B - Finding Team Member - CodeForces Solution


brute force implementation sortings *1300

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long n;
   cin>>n;
  // vector<vector<long long int>>vec;
    //vector<vector<long long int>> vec1(n * 2, vector<long long int>(n * 2, 0));
    vector<tuple<long long int, long long int, long long int>> triplets;

   /*for(int i=1;i<=n*2;i++)
   {
       vector<long long>temp;
       for(int j=1;j<=i-1;j++)
       {
           //long long hey;
           //cin>>hey;
           long long bye=-87;
           temp.push_back(bye);
       }

       vec.push_back(temp);

   }*/

   vector<long long>dorkar;

    for(int i=2;i<=(n*2);i++)
   {
       vector<long long>temp;
       for(int j=1;j<=i-1;j++)
       {
           long long hey;
           cin>>hey;
           //temp.push_back(hey);
           //vec1[i-1][j-1]=hey;
           //dorkar.push_back(hey);
           triplets.push_back(make_tuple(hey,i,j));
       }

       //vec.push_back(temp);

   }

   sort(dorkar.begin(),dorkar.end());
   sort(triplets.begin(), triplets.end());


   map<long long,long long>mapp;
   map<long long,long long>mapp1;
   map<long long,long long>mapp2;

   long long cc=0;

    for(int i=triplets.size()-1;i>=0;i--)
   {
       if(cc>=(n*2))
        break;
      long long int fir=get<0>(triplets[i]);
      long long int sec=get<1>(triplets[i]);
      long long int thir=get<2>(triplets[i]);

      if(mapp[sec]==0&&mapp[thir]==0)
      {


       mapp1[sec]=thir;
       mapp1[thir]=sec;

       //cout<<fir<<endl;
       mapp[sec]++;
       mapp[thir]++;

      cc+=2;
      }

      //cout<<fir<<" "<<sec<<" "<<thir<<endl;
   }

    for(int i=1;i<=n*2;i++)
   {
       cout<<mapp1[i]<<" ";
   }

   cout<<endl;

   //long long ii=0;

  /* for(int i=dorkar.size()-1;i>=0;i--)
   {
       if(ii>=n)
        break;

       mapp2[dorkar[i]]++;
       ii++;


   }

   long long cnt=0;

   //for(int i=dorkar.size()-1;i>=0;i--)
   //{

   int p=dorkar.size()-1;


       for(int j=1;j<n*2;j++)
       {
            if(cnt>=(n*2))
             break;
            int check=0;
           for(int k=0;k<j;k++)
           {
               //if(vec1[j][k]==dorkar[p]&&mapp[j]==0&&mapp[k]==0)
               if(mapp2[vec1[j][k]]!=0&&mapp[j]==0&&mapp[k]==0)
               {
                  // cout<<"TEsting"<<endl;
                  //cout<<j+1<<" "<<k+1<<endl;
                   mapp1[j+1]=k+1;
                   mapp1[k+1]=j+1;
                   mapp[j]++;
                   mapp[k]++;
                   check++;
                   cnt+=2;
                   p--;
                   break;
               }
           }

           //if(check!=0)
           // break;
       }
  // }*/


   //vec[3][2]= 5;

   //cout<<vec1[1][0]<<endl;

}


Comments

Submit
0 Comments
More Questions

Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number