Pagini recente »
Istoria paginii utilizator/ana_madalina_18
|
Istoria paginii utilizator/antoniadutu
|
Istoria paginii utilizator/denisaionita
|
Istoria paginii utilizator/antoniadutu
|
Cod sursă (job #389141)
Cod sursă (job
#389141)
#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 ;
if ( crSol >=1 && sol [ crSol ].val == sol [ crSol - 1 ].val && sol [ crSol ].isRot == 0 && sol [ crSol -1 ].isRot == 1 ){
sol [ crSol - 1 ].isRot = 0;
sol [ crSol ].isRot = 1 ;
}
}
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;
}