|
|
back to boardGetting wrong answer for test 1.. pls help #include<stdio.h> int main() { int a[101][101]={0} , i , j , count[101] , cc=0 , n , p[101][2] , booll[101]={0} , k ,temp ,max, maxind; int t1, t2 ; scanf("%d",&n); k=n;
for( i = 0 ; i < n ; i++ ) { scanf("%d %d",&p[i][0] , &p[i][1]); if( p[i][0] > p[i][1] ) { temp = p[i][0] ; p[i][0] = p[i][1]; p[i][1] = temp; }
for( j = 0 ; j < i ; j++ ) { if( ( p[i][0] > p[j][0] && p[i][0] < p[j][1] ) || ( p[i][1] > p[j][0] && p[i][1] < p[j][1] ) || ( p[j][0] > p[i][0] && p[j][0] < p[i][1] ) || ( p[j][1] > p[i][0] && p[j][1] < p[i][1] )) { a[i][j] = a[j][i] = 1; count[i]++; count[j]++; }
}
booll[i]=1; }
for( i = 0 ; i < n ; i++) if(count[i]) cc++; while( cc ) { max = 0; maxind = 0; for( i = 0 ; i < n ; i++ ) if( count[i] > max && booll[i] ) { max = count[i]; maxind = i; }
i = maxind; booll[i] = 0; count[i]=0; cc--; k--;
for( j = 0 ; j < n ; j++ ) if( a[i][j] ){ a[i][j] = 0; a[j][i] = 0; count[j]--; if(!count[j]) cc--; }
}
for( i = 1 ; i < n ; i++ ) { j=i-1; temp = booll[i]; t1=p[i][0] ; t2 = p[i][1]; while( j >= 0 && t1 < p[j][0] ) { p[j+1][0] = p[j][0]; p[j+1][1] = p[j][1]; booll[j+1] = booll[j]; j--; }
p[j+1][0] = t1; p[j+1][1]=t2; booll[j+1] = temp; }
printf("%d\n",k); for( i = 0 ; i < n ; i++ ) if( booll[i] ) printf("%d %d\n", p[i][0] , p[i][1] );
return 0; } |
|
|