Pagini recente »
Istoria paginii runda/mult_prea_simplu/clasament
|
dumi_dum_dum_vs_vilci_vilc_vilc3
|
Cod sursă (job #318950)
Cod sursă (job
#318950)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("domino.in");
ofstream out("domino.out");
int n,rot,el;
int lastSt,lastDr;
bool lastRot;
struct piesa
{
int st,dr;
bool rotit;
} v[10005];
int sz;
int main()
{
in>>n>>rot>>el;
for(int i = 1; i<=n; i++)
{
int st,dr;
in>>st>>dr;
bool rotit=false;
if(st<dr)
{
int temp=st;
st=dr;
dr=temp;
rotit=true;
}
if(i>1 && el)
{
bool ok=false;
if(rotit)
{
if(lastRot)
{
if(dr>lastDr)
{
el--;
//cout<<"elimin: "<<lastSt<<' '<<lastDr<<'\n';
ok=true;
}
}
else
{
if(dr>lastSt)
{
el--;
//cout<<"elimin: "<<lastSt<<' '<<lastDr<<'\n';
ok=true;
}
}
}
else
{
if(lastRot)
{
if(st>lastDr)
{
el--;
//cout<<"elimin: "<<lastSt<<' '<<lastDr<<'\n';
ok=true;
}
else if(st>lastSt)
{
el--;
//cout<<"elimin: "<<lastSt<<' '<<lastDr<<'\n';
ok=true;
}
}
}
if(!ok)
{
v[++sz].st=lastSt;
v[sz].dr=lastDr;
v[sz].rotit=lastRot;
}
}
lastSt=st;
lastDr=dr;
lastRot=rotit;
}
v[++sz].dr=lastDr;
v[sz].st=lastSt;
while(el)
{
v[sz].dr=0;
v[sz--].st=0;
}
int cntRot=0;
for(int i = 1;i<=sz;i++)
{
if(v[i].rotit)
cntRot++;
}
for(int i = sz;i>=1 && cntRot>rot;i--)
{
if(v[i].rotit)
{
cntRot--;
v[i].rotit=0;
int temp=v[i].st;
v[i].st=v[i].dr;
v[i].dr=temp;
}
}
for(int i = 1;i<=sz;i++)
{
out<<v[i].st<<v[i].dr;
}
return 0;
}