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 1112. Cover

Steve Francis What's wrong with my code??? Who can help me!!! [1] // Problem 1112. Cover 3 Mar 2003 17:06
#include <iostream.h>
int a[2000],q[2000],o[2000];
int check(int i)
{
 int j;
 for (j=i+1; j<a[i]; j++)
  {
   if (q[j]!=0) return 0;
  }
 for (j=i; j<=a[i]; j++)
   q[j]=1;
 return 1;
}
int main()
{
 int i,n,left,right,p;
 cin>>n;
 for (i=0; i<2000; i++) {a[i]=0; q[i]=0; o[i]=0;}
 for (i=0; i<n; i++)
  {
   cin>>left>>right;
   if (left>right)
     {
      p=left;
      left=right;
      right=p;
     }
   if (a[left+1000]==0) a[left+1000]=right+1000;
   else if (a[left+1000]>right+1000) a[left+1000]=right+1000;
  }
 p=0;
 for (i=0; i<2000; i++)
  if ((a[i])&&(check(i)))
    {
     p++;
     o[i]=1;
    }
 cout<<p<<endl;
 for (i=0; i<2000; i++)
  if (o[i])
   cout<<i-1000<<' '<<a[i]-1000<<endl;
}
Saber Test for everyone who got WA !!! // Problem 1112. Cover 3 Mar 2003 18:22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
5
1 2
2 6
3 4
4 5
5 6
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Saber
ssf_digi@hotmail.com