ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1078. Segments

WA ON TEST #2 !!! segments problem!
Posted by michel mizrahi 22 Jun 2005 07:31
I get sooo many WA!!! I don't know what's wrong with my code, I have read all the posts in this forum but I am still without answer
here is my code:

#include <stdio.h>
int x[502],y[502],ind[502];

void quick_sort(int l, int h){
   int p;
   if(h>l){
      p=partition(l,h);
      quick_sort(l,p-1);
      quick_sort(p+1,h);
   }
}

void swap(int a, int b){
     int tmp=x[a];
     x[a]=x[b];x[b]=tmp;
     tmp=y[a];
     y[a]=y[b];y[b]=tmp;
     tmp=ind[a];
     ind[a]=ind[b];
     ind[b]=tmp;
}

int partition(int l, int h){
    int p=l,i;
    for(i=l;i<h;i++)
       if(x[i]<x[h]){
         swap(i,p);
         p++;
       }
    swap(h,p);
    return p;
}

int main(){
  int n,i,sol[502],solt[502],k,res=0,j,tot,tmp;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&x[i],&y[i]);
    ind[i]=i+1;
  }
  quick_sort(0,n-1);
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      if(x[i]==x[j] && y[i]==y[j]){
        x[i]=-15000;
        y[i]=-11000;
      }
  for(i=0;i<n;i++){
    k=1;solt[0]=ind[i];tmp=1;
    for(j=i+1;j<n;j++)
      if(x[i]<x[j] && y[i]>y[j]){
        tmp++;
        solt[k]=ind[j];
        k++;
      }
    if(tmp>res){
      res=tmp;
      for(j=0;j<k;j++)
         sol[j]=solt[j];
      tot=k;
    }
  }
  printf("%d\n",res);
  printf("%d",sol[tot-1]);
  for(i=tot-2;i>-1;i--)
    printf(" %d",sol[i]);
  printf("\n");
  return 0;
}

if someone can help me or give me some tricky input, I would appreciate very much
thanks and sorry for my bad english!
bye

Edited by author 22.06.2005 07:32

Edited by author 22.06.2005 07:32