Code:
#include<bits/stdc++.h>
using namespace std;
double mux(double a,double b){
return a>b?a:b;
}
int dx[5]={0,0,0,-1,1};
int dy[5]={0,-1,1,0,0};
struct person{
double hp=0;
double st;
double de;
int x;
int y;
}a;
char mp[109][109];
int n,m;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++) cin>>mp[i][j];
}
double mhp,mst,mde;
double q;
cin>>mhp>>mst>>mde;
cin>>a.x>>a.y;
cin>>a.st>>a.de;
cin>>q;
for(int i=1;i<=q;i++){
int op;
cin>>op;
if(op==1){
cout<<(a.hp!=0?-1*a.hp:0)<<" "<<a.st<<" "<<a.de<<endl;
}
else if(op==2){
int d;
cin>>d;
a.x=a.x+dx[d];
a.y=a.y+dy[d];
if(mp[a.x][a.y]=='M'){
int aa=ceil(mhp/mux(1.0,a.st-mde));
int bb=mux(1,mst-a.de);
a.hp=a.hp-mux(1,aa*bb);
}
if(mp[a.x][a.y]=='R'){
a.hp=a.hp+10>1?0:a.hp+10;
}
if(mp[a.x][a.y]=='Y'){
a.de=a.de+5;
}
if(mp[a.x][a.y]=='Q'){
a.st=a.st+5;
}
}
}
}