提供简洁的代码
思路:没有思路,按题意模拟
每次读入一个字符,按描述操作就可以
注:不需要对开始特判
详见代码:
#include<iostream>
#include<cstdio>
#include<ctype.h>
#include<cmath>
using namespace std;
inline int read(){//快读,可快了,虽然这题没什么用
int x=0,f=0;char ch=getchar();
while(!isdigit(ch))f|=ch=='-',ch=getchar();
while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
return f?-x:x;
}
int mHp,mStr,mDef,LostHp,Str,Def,X,Y;//m表示怪物,其他含义如题,X,Y表示勇者当前位置,设为全局变量方便处理
char ma[107][107];//地图
inline void Move(){//移动
char o;cin>>o;//读入向哪里移动
if(o=='W')Y--;
else if(o=='E')Y++;
else if(o=='N')X--;
else X++;//移动操作
if(ma[X][Y]=='R')LostHp=max(0,LostHp-10);//注意,失去的血量不能是负的,与0取max
else if(ma[X][Y]=='Q')Str+=5;
else if(ma[X][Y]=='Y')Def+=5;//按题意模拟
else if(ma[X][Y]=='M')LostHp+=max(1,int(ceil(1.0*mHp/max(1,Str-mDef)))*max(1,mStr-Def));//注意ceil里应为double,否则不起作用
}
int main(){
int n=read(),m=read();
for(int i=1;i<=n;++i)scanf("%s",ma[i]+1);
mHp=read(),mStr=read(),mDef=read(),X=read(),Y=read(),Str=read(),Def=read();
int q=read();//以上为读入
while(q--){
char o;cin>>o;//读入字符
if(o=='M')Move();//移动
else printf("%d %d %d\n",LostHp,Str,Def);//询问输出
}
return 0;//好习惯
}