int main() { char s[1000],*p; int stack[50]; while((fgets(s,sizeof(s),stdin))!=NULL) { p = strtok(s," "); int k=0; while(p!=NULL) { stack[k++] = atoi(p); p = strtok(NULL," "); } // print original one for(int i=0;i<k-1;i++) { printf("%d ",stack[i]); } printf("%d\n",stack[k-1]); int first_move = 1; for(int i=k;i>=1;i--) { MaxVal mv = findmax(stack,i); if(mv.pos!=i-1) { if(mv.pos!=0) { // biggest is in the middle // revolve to make the biggest to the leftmost position if(first_move) { printf("%d",k-mv.pos); //because we stored pancakes from left to right but it counts from right to left stating from 1 first_move = 0; } else { printf(" %d",k-mv.pos); //because we stored pancakes from left to right but it counts from right to left stating from 1 } revolve(stack,mv.pos); // revolve to make the biggest to current right position printf(" %d",k-i+1); revolve(stack,i-1); } else { // biggest is at the leftmost position, just need to revolve once to make it to the right position if(first_move) { printf("%d",k-i+1); first_move = 0; } else { printf(" %d",k-i+1); } revolve(stack,i-1); } } } if(first_move) printf("0\n"); // already sorted. else printf(" 0\n"); } return 0; }
static void meltIce (float state[12], float other[12], float time) { //BEGIN::PROC::meltIce /* * meltIce melts the * ice sheet on Opulens * (no shit!) */ float x[3]={0,-0.35,-0.2}; if (PiceHits()+PotherIceHits()>18 || time<47) { revolve (x,state,other); } else { ZRSetPositionTarget (state); mathVecSubtract(x,x,state,3); ZRSetAttitudeTarget(x); } if (time>59) Plaser(); //END::PROC::meltIce }
void ZRUser01(float *myState, float *otherState, float time) { //BEGIN::PROC::ZRUser // These are just some costants, don't pay to much attention to them :) #define WAIT_TIME 13 // Seconds to wait before starting spinning #define TIME_OPP_STAT 140 // Will only start considering about going // to a station after TIME_OPP_STAT seconds. #define ACCURACY_STAT 1.975f // Number between 1 and 2, the higher it is, // the more accurate in deciding whether the // opponent is headed towards the station. #define FUEL_STAT 25 // The minimum amount of fuel required to go // to a mining station (below this value, // the sphere's not going anywhere // msg : contains the messages received from the opponent // tt : contains a condition used a couple of times (space optimization) // out : contains the message we're sending our opponent unsigned short msg,tt,out=0; // avoid: is true or false whether the collision avoidance system is activated or not unsigned char avoid; // Don't worry about x and v ^^ float x[2]; float v[3]; // stat : these are some coordinates of stuff, like stations, asteroids and // a couple of corners of the playground float stat[6][3] = { {-0.5f,+0.31f,-0.55f}, {+0.5f,-0.31f,+0.55f}, {0,-0.35f,-0.2f}, {0,+0.35f,+0.2f}, {-0.5f,+0.65f,-0.55f}, {+0.5f,-0.65f,+0.55f}}; msg=PgetMessage(); avoid = PisAvoidingCollision(); tt=(tmp && tmp+WAIT_TIME<time); /* * y0b0tics protocol will be used only when * we're controlling the SPH # 1 */ if (!time) { if (myState[0]>0) { // SPH1 a=0.4; // a is the X coordinate of the nearest laser out=0x0400; // bit 11 sp=1; } else a=-0.4; } /* * If the opponent is willing to work * on Indigens, we're going to Indigens * as well, but we'll try to revolve. * Otherwise we keep sending our * opponent a "I'll revolve on Opulens" * message. */ if (time<60 && time) { if ((msg>3 && msg<6) || ast==1) { out=5; act=2; // Revolve ast=1; // Indigens } else { out=3; } } /* * If we're headed to a mining station, * we're telling our opponents which one * it is */ else if (act==4 && st<2) out=7-st; PsendMessage(out); /* * First of all, the Laser is taken * (btw, there's a "minor" bug in this * condition (&& time<60) is needed * (will add that as soon as some space * is available) */ if (!PhaveLaser()) { /* * If the opponent is trying to "steal" * our laser, we will get the other one */ if (avoid && myState[0]*a>0) a*=-1; /* v contains the * laser coordinates */ v[0]=a; v[1]=0; v[2]=0; ZRSetPositionTarget(v); } else { if (time>TIME_OPP_STAT && st<2) { /* * x[0] is given the value of the distance * between us and our opponent */ mathVecSubtract (v,myState,otherState,3); x[0]=mathVecMagnitude (v,3); /* * if our opponent is going to a station * we decide to go to the other one, but * only if we're able to arrive first */ if (checkTarget(otherState,0)>ACCURACY_STAT) { /* * Even if we're headed towards a station, * if our opponent is going to * the same station as us, we stop going * there and, instead, we move to the * closest corner of the playground, * so that, even if we don't gain anything, * at least we won't activate the collision * avoidance system */ if (!st && x[0]<0.65f) { st=4; } else if (st==-1) { /* * We go to the other station only if * we can reach it first */ if (getInTime(stat[0],otherState,stat[1],myState)) { st=1; act=4; } else st=-2; } } /* * Same stuff as before, but now * the other station is checked. */ else if (checkTarget(otherState,1)>ACCURACY_STAT) { if (st==1 && x[0]<0.65f) { st=5; } else if (st==-1) { if (getInTime(stat[1],otherState,stat[0],myState)) { st=0; act=4; } else st=-2; } } /* * although our opponent is not going to * a station, we leave the asteroid we're * working on to go to a station. * The time we're leaving the asteroid is * not fixed, but is calculated every time * in order to leave the asteroid as late as * possible */ else if (PgetPercentFuelRemaining()>FUEL_STAT && st==-1) { /* * x[0] contains the value of time * at which we have to leave the asteroid * to reach a station * 180-(time needed to reach a station) */ x[0]=timeStation(stat[0],myState); x[1]=timeStation(stat[1],myState); /* * It is then decided which station is * better, keeping in account that, if * we're spinning, our opponent could be * on our way to the station. */ if ((time>=x[0]) && (x[0]>x[1]) && !(act==3 && otherState[0]<0 && otherState[1]>0 && otherState[2]<0.2)) { act=4; st=0; } if ((x[0]<x[1]) && (time>=x[1]) && !(act==3 && otherState[0]>0 && otherState[1]<0 && otherState[2]>-0.2)) { act=4; st=1; } } } /* * act (action) contains a value * related to the action we're * doing. */ switch (act) { /* act = 1 -> melting ice on Opulens */ case 1: meltIce(myState,otherState,time); if (PiceMelted()) act=2; // if the ice is melted, we start revolving // on Opulens break; /* act = 2 -> revolve */ case 2: /* * if the opponent is revolving as * well, we keep revolving as well * for WAIT_TIME seconds. After that * seconds, if the opponent is * still revolving, we start spinning */ if (PisRevolving (otherState)==ast-1) { if (!tmp) tmp=time; if (tt && (checkTarget (otherState,ast)<1.9f) && st!=-2) { act=3; tmp=0; } } revolve(stat[ast],myState,otherState); break; /* act = 3 -> spinning */ case 3: /* * if the avoiding collision system * is working, it probably means that * our opponent wants to spin and he's * close to us so, after a few seconds, * we let him spin and we start revolving ^^ */ if (avoid) { if (!tmp) tmp=time; if (tt) { tmp=0; act=2; } } spin(stat[ast],myState); break; /* act = 4 -> going somewhere */ case 4: SetPosFaster(stat[st],myState); break; default: break; } if (tt) tmp=0; } //END::PROC::ZRUser }