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

I always wa in test 4,please help me,thank you!!!
Posted by guojinyu 17 Jun 2011 20:02
Please tell me the reason or give me the t4,thank you!
This is my program:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int n,result=0,xia=0,rxia;
int line[110][2],era[110][2],fera[110][2];
void init()
{
  int i,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  {
    scanf("%d %d",&line[i][0],&line[i][1]);
    if(line[i][0]>line[i][1])
      swap(line[i][0],line[i][1]);
  }
  for(i=1;i<n;i++)
    for(j=i+1;j<=n;j++)
    {
      if(line[j][0]<line[i][0])
      {
        swap(line[i][0],line[j][0]);
        swap(line[i][1],line[j][1]);
      }
      if(line[j][0]==line[i][0])
        if(line[j][1]<line[i][1])
        {
          swap(line[i][0],line[j][0]);
          swap(line[i][1],line[j][1]);
        }
    }
}
void jilu(int i)
{
  xia++;
  era[xia][0]=line[i][0];
  era[xia][1]=line[i][1];
}
void copyera()
{
  int i;
  for(i=1;i<=xia;i++)
  {
    fera[i][0]=era[i][0];
    fera[i][1]=era[i][1];
  }
}
void solve()
{
  int i,x,temp=1,now;
  for(x=1;x<=n;x++)
  {
    xia=0;
    temp=1;
    memset(era,0,sizeof(era));
    xia++;
    era[xia][0]=line[x][0];
    era[xia][1]=line[x][1];
    now=line[x][1];
    for(i=x+1;i<=n;i++)
      if(line[i][0]>=now)
      {
        temp++;
        now=line[i][1];
        jilu(i);
      }
    if(temp>result)
    {
      result=temp;
      copyera();
      rxia=xia;
    }
  }
  printf("%d\n",result);
  for(i=1;i<=rxia;i++)
    printf("%d %d\n",fera[i][0],fera[i][1]);
}
int main()
{
  init();
  solve();
  return(0);
}

Thank you very much!!!
Re: I always wa in test 4,please help me,thank you!!!
Posted by best 24 Feb 2013 18:53
Maybe you forget sort first just like me.