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

Elmi Ehmedov I got WA #4. pls help me! [2] // Problem 1078. Segments 26 Apr 2011 12:37
my code :

#include <iostream>
#include <algorithm>

using namespace std;

struct cord
{
  int x,y,p;
};

int comp(cord a,cord b)
{
  if (a.x < b.x) return 1;
  return 0;
}

int main()
{
    cord a[501];
    int best[501];
    int way[501];
    int oway[501],f=0;
    int n,i,j,k,l;

    cin>>n;
    for (i=0;i<n;i++)
     {
      cin>>a[i].x>>a[i].y;
      if (a[i].y < a[i].x)
       swap(a[i].x,a[i].y);
      best[i]=1; a[i].p=i+1;
      way[i]=i;
     }
    sort(a,a+n,comp);
    for (i=0;i<n;i++)
     for (j=0;j<n;j++)
      if (j != i)
       {
         if (a[i].x >= a[j].x && a[i].y <= a[j].y)
          {
            if (best[j]+1 >= best[i])
             {
              best[i]=best[j]+1;
              way[i]=j;
             }
          }
       }
    k=best[0]; l=0;
    for (i=1;i<n;i++)
     if (best[i] >= k) k=best[i],l=i;
    while (l != way[l] && k > 0)
     {
      oway[f]=a[l].p; f++;
      l=way[l]; k--;
        }
    oway[f]=a[l].p; f++;
    cout<<f<<endl;
    for (i=0;i<f;i++) cout<<oway[i]<<" ";
    cout<<endl;

    return 0;
}

Edited by author 26.04.2011 18:15

Edited by author 26.04.2011 18:15
Elmi Ehmedov Re: I got WA #4. pls help me! [1] // Problem 1078. Segments 26 Apr 2011 23:07
oh, I have solved it. Thanks!

Edited by author 26.04.2011 23:09
Steven Re: I got WA #4. pls help me! // Problem 1078. Segments 27 Aug 2013 13:22
Why?