两只多姆牛,模拟
#include
using namespace std;
char mp[11][11];
int xa,ya,xb,yb;
int lxa,lya,lxb,lyb;
int fa = 1,fb = 1;
int ans = 0;
void yda(){
if(fa==1){//北
lxa = xa - 1;
lya = ya;
}
if(fa==2){//东
lxa = xa;
lya = ya + 1;
}
if(fa==3){//南
lxa = xa+1;
lya = ya ;
}
if(fa==4){//西
lxa = xa;
lya = ya - 1;
}
if(lxa>=1 && lya >=1 && lya<=10 && lxa <= 10&& mp[lxa][lya] == '.'){
xa = lxa;
ya = lya;
}else{
fa++;//方向改变
if(fa>4){
fa = 1;
}
}
}
void ydb(){
//平移区
if ( fb == 1 ){
lxb = xb - 1 ;
lyb = yb ;
}
if ( fb == 2 ){
lxb = xb ;
lyb = yb + 1 ;
}
if ( fb == 3 ){
lxb = xb + 1 ;
lyb = yb ;
}
if ( fb == 4 ){
lxb = xb ;
lyb = yb - 1 ;
}
//判定区:
if ( lxb >= 1 && lyb >= 1 && lyb <= 10 && lxb <= 10 && mp[lxb][lyb] == '.' ){
xb = lxb ;
yb = lyb ;
}
else{
fb++ ;
if ( fb > 4 ){
fb = 1 ;
}
}
}
int main(){
for(int i = 1;i<=10;i++){
for(int j = 1;j<=10;j++){
cin >> mp[i][j];
if(mp[i][j]=='F'){
xa=i;
ya=j;
mp[i][j] = '.';
}
if(mp[i][j]=='C'){
xb=i;
yb=j;
mp[i][j] = '.';
}
}
}
while(1){
yda();
ydb();
ans++;
if(ans>1000){
cout<<0;
return 0;
}
if(xa==xb&&ya==yb){
cout< return 0;
}
}
}
using namespace std;
char mp[11][11];
int xa,ya,xb,yb;
int lxa,lya,lxb,lyb;
int fa = 1,fb = 1;
int ans = 0;
void yda(){
if(fa==1){//北
lxa = xa - 1;
lya = ya;
}
if(fa==2){//东
lxa = xa;
lya = ya + 1;
}
if(fa==3){//南
lxa = xa+1;
lya = ya ;
}
if(fa==4){//西
lxa = xa;
lya = ya - 1;
}
if(lxa>=1 && lya >=1 && lya<=10 && lxa <= 10&& mp[lxa][lya] == '.'){
xa = lxa;
ya = lya;
}else{
fa++;//方向改变
if(fa>4){
fa = 1;
}
}
}
void ydb(){
//平移区
if ( fb == 1 ){
lxb = xb - 1 ;
lyb = yb ;
}
if ( fb == 2 ){
lxb = xb ;
lyb = yb + 1 ;
}
if ( fb == 3 ){
lxb = xb + 1 ;
lyb = yb ;
}
if ( fb == 4 ){
lxb = xb ;
lyb = yb - 1 ;
}
//判定区:
if ( lxb >= 1 && lyb >= 1 && lyb <= 10 && lxb <= 10 && mp[lxb][lyb] == '.' ){
xb = lxb ;
yb = lyb ;
}
else{
fb++ ;
if ( fb > 4 ){
fb = 1 ;
}
}
}
int main(){
for(int i = 1;i<=10;i++){
for(int j = 1;j<=10;j++){
cin >> mp[i][j];
if(mp[i][j]=='F'){
xa=i;
ya=j;
mp[i][j] = '.';
}
if(mp[i][j]=='C'){
xb=i;
yb=j;
mp[i][j] = '.';
}
}
}
while(1){
yda();
ydb();
ans++;
if(ans>1000){
cout<<0;
return 0;
}
if(xa==xb&&ya==yb){
cout<
}
}
}
全部评论
相关推荐