Pagini recente »
Cod sursă (job #317792)
Cod sursă (job
#317792)
#include <iostream>
#include <stdio.h>
using namespace std;
const int N = 1e5 + 5 ;
struct Solution{
int val ;
bool isRot ;
};
int noPiese , noRot , noDel ;
Solution sol [ N ] ;
int crSol = -1 ;
int canRotate( int domVal , int crRot , int crDel ){
static int crDom ;
crDom = crSol ;
while ( crDel && crDom >=0 && domVal > sol[ crDom ].val ){
if ( sol [ crDom ].isRot == 1 ){
crRot ++ ;
}
crDom -- ;
crDel -- ;
}
if ( crRot ){
return 1 ;
}
return 0 ;
}
void addToSol ( int domVal , int isRotated ){
while ( noDel && crSol >= 0 && domVal > sol [ crSol ].val ){
if ( sol[ crSol ].isRot == 1 ){
noRot ++ ;
}
crSol -- ;
noDel -- ;
}
sol [ ++crSol ].isRot = isRotated ;
sol [ crSol ].val = domVal ;
}
int main(){
int i ;
int x , y ;
freopen("domino.in","r",stdin);
freopen("domino.out","w",stdout);
scanf("%d%d%d",&noPiese , &noRot , &noDel );
int isRotated , domVal ;
for ( i = 0 ; i < noPiese ; i++ ){
scanf("%d %d",&x , &y);
if ( y > x ){
isRotated = 1 ;
domVal = y * 10 + x ;
}else{
isRotated = 0 ;
domVal = x * 10 + y ;
}
if ( isRotated ){
int temp = canRotate( domVal , noRot , noDel );
if ( temp == 0 ){
isRotated = 0;
domVal = x * 10 + y ;
}else{
noRot -- ;
}
}
addToSol( domVal , isRotated );
}
for ( i = 0 ; i <= crSol - noDel ; i ++ ){
printf("%d",sol[ i ].val );
}
return 0;
}