Pagini recente »
Borderou de evaluare (job #364080)
|
Cod sursă (job #816533)
|
Istoria paginii runda/tema_1_cls7_2018
|
Istoria paginii runda/2015-04-07-clasa-5-tema-34
|
Cod sursă (job #237658)
Cod sursă (job
#237658)
#include <stdio.h>
#include <stdlib.h>
int v[20001];
int pozcmax(int i, int x, int rotea){
int pas;
int indmax=i,cimax=0,j,vecj,vecim;
if(rotea)
for(j=i;j<i+2*x;j++){
if(v[j]>cimax){
indmax=j;
cimax=v[j];
}
else{
if(v[j]==cimax){
if(j%2==0)
vecj=v[j-1];
else
vecj=v[j+1];
if(indmax%2==0)
vecim=v[indmax-1];
else
vecim=v[indmax+1];
if(vecj>vecim){
indmax=j;
cimax=v[j];
}
}
}
}
else{
for(j=i;j<i+2*x;j+=2){
if(v[j]>cimax){
indmax=j;
cimax=v[j];
}
else{
if(v[j]==cimax){
vecj=v[j+1];
vecim=v[indmax+1];
if(vecj>vecim){
indmax=j;
cimax=v[j];
}
}
}
}
}
return indmax;
}
int main()
{
FILE *fin, *fout;
int n,k2,rotea,i,indice,aux,j;
fin=fopen("domino.in","r");
fout=fopen("domino.out","w");
fscanf(fin,"%d %d %d",&n,&rotea,&k2);
for(i=1;i<=2*n;i++)
fscanf(fin,"%d",&v[i]);
i=1;
while(k2 && i+(k2*2)<=2*n){
indice=pozcmax(i,k2+1,rotea);
if(rotea && indice%2==0){
aux=v[indice];
v[indice]=v[indice-1];
v[indice-1]=aux;
rotea--;
}
k2=k2-(indice-i)/2;
for(j=i;j<indice-(indice+1)%2;j++)
v[j]=-1;
i=indice+1+indice%2;
}
if(k2!=0)
for(;i<=2*n;i++)
v[i]=-1;
for(i=1;i<=2*n;i++)
if(v[i]!=-1)
fprintf(fout,"%d",v[i]);
fclose(fin);
fclose(fout);
return 0;
}