Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
mula_russa

[Ajuda] Problema C Selection Sort

Recommended Posts

mula_russa

Boas, estou a tentar resolver este problema http://acm.timus.ru/problem.aspx?space=1&num=1178 , no entanto não estou a conseguir e não consigo perceber como o resolver. Será que alguem me pode ajudar?

Este é o codigo que tenho:

#include <stdio.h>

void SelSort(int a[],int b[],int c[], int n);

int main()
{
  int n, x[10000],y[10000],c[10000],i,dum;
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
     scanf("%d %d",&x[i],&y[i]);
  for(i=0;i<n;i++)
     c[i]=i;
  
  SelSort(x,y,c,n);


  for(i=0;i<(n/2);i++)
     printf("%d %d\n",c[(2*(i+1)-1)-1]+1,c[(2*(i+1))-1]+1);
  return 0;
}


void SelSort(int a[], int b[], int c[], int n)
{
   unsigned int indi,indj,indmin,q;
   
   for(indi=0;indi <n-1; indi++)
   {
      indmin=indi;
      for(indj =indi+1;indj <n; indj++)
         if((a[indmin]<a[indj] && b[indmin]<b[indj]))
           indmin=indj;
      if(indmin!=indi)
      {
         q=a[indi];

 a[indi]=a[indmin];

 a[indmin]=q;

         q=b[indi];

 b[indi]=b[indmin];

 b[indmin]=q;

         q=c[indi];

 c[indi]=c[indmin];

 c[indmin]=q;
      }
   }
}

Obrigado!

Cumprimentos

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.