#include #include #include #include #include #include using namespace std; int main (){ int NNN,PX,PY; cin >> NNN >> PX >> PY; int command[100000]={0}; int temp; for(int i =0;i> temp; if(temp==1){ cin >> temp; command[i]=1000000+temp; temp=0; } if(temp==2){ cin >> temp ; command[i]=temp; temp=0; } if(temp==3){ command[i]=-1; } } int matcom[100000][3][3]={0}; //各コマンドを行列化して格納する int ruicom[100000][3][3]={0}; //行列の積を格納する for(int i=0;i999999){ comtemp = command[i]-1000000; for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ if(j==k){ matcom[i][j][k]=1; } else{ matcom[i][j][k]=0; } } } matcom[i][0][2]=comtemp; } //command 90deg else if(command[i]==-1){ matcom[i][0][0]=0; matcom[i][0][1]=1; matcom[i][0][2]=0; matcom[i][1][0]=-1; matcom[i][1][1]=0; matcom[i][1][2]=0; matcom[i][2][0]=0; matcom[i][2][1]=0; matcom[i][2][2]=1; } //command Dy else if(command[i]>0){ for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ if(j==k){ matcom[i][j][k]=1; } else{ matcom[i][j][k]=0; } } } matcom[i][1][2]=command[i]; } /* for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ printf("%d",matcom[i][j][k]); } printf("\n"); } printf("\n"); */ } for(int i =NNN-1;i>-1;i--){ //i=0は、なにもかけなくていいです if(i==NNN-1){ for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ ruicom[i][j][k]=matcom[i][j][k]; } } } else { for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ ruicom[i][j][k]=0; for(int l=0;l<3;l++){ ruicom[i][j][k] += ruicom[i+1][j][l]*matcom[i][l][k]; } } } } /* for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ printf("%d",ruicom[i][j][k]); } printf("\n"); } printf("\n"); */ } int ansx=0; int ansy=0; for(int i=NNN-1;i>-1;i--){ ansx = ruicom[NNN-1-i][0][0] * PX + ruicom[NNN-1-i][0][1]* PY + ruicom[NNN-1-i][0][2] * 1; ansy = ruicom[NNN-1-i][1][0] * PX + ruicom[NNN-1-i][1][1]* PY + ruicom[NNN-1-i][1][2] * 1; cout << ansx << " " << ansy << endl; } return 0; }