赛艇

题目描述:

河神喜欢在自己的领地小汤河上开赛艇,于是他用一口锅改装成了一颗赛艇。我们假定小汤河只有一小段经过小汤河职业技术学院,这段河道宽为n长为m。
现在河神想要秀自己最高超的技术,所以他给自己的船设置了一个复杂的自动驾驶程序(事实上只是预先设置好p次操作后的行驶路线罢了)。但是河神并不知道,河中有t口废弃的锅。
碰到这些锅,或者冲上河岸,河神就会翻船。你的任务就是判断河神会不会翻船。

输入:

因为河神每天都要赛艇所以请多组输入。
第一行输入n,m(0<n,m<100)
第二行输入河神的坐标x,y(0=<x<n && 0=<y<m)(坐标系取第一象限,即(0,0)在左下角)
第三行输入锅的数量t(0=<t<n*m)
接下来t行输入锅的坐标xi,yi(0=<xi<n && 0=<yi<m)
第t+4行输入河神赛艇操作的数量p(0<p<100)
接下来p行输入行驶方向(N,E,W,S分别代表向北(上),向东(右),向西(左),向南(下),一次移动一个单位)

输出:

如果河神翻船了,输出"the boss of river is also desperated what can he do?"

河神没翻船则输出"the boss of river finished his show!!"

样例输入
5 5
1 1
2
2 2
3 3
5
N
W
N
E
E
样例输出
the boss of river finished his show!!
提示

很简单的模拟,你们可以试试百搭,哦不,百度大法。(不要总是思维江化地认为0,0在左上角嘛)

#include <iostream>
using namespace std;
int main()
{
	int n,m,x,y,a[102],b[102],t,p,to;
	char direction[100];
	while(cin>>n>>m>>x>>y)
	{b[102]={};
	a[102]={};
		to=0;
		cin>>t;
		for(int i=1;i<=t;i++)
		{
			cin>>a[i]>>b[i];
		}
		cin>>p;
		for(int i=1;i<=p;i++)
		{
			cin>>direction[i];
			if(direction[i]=='N') y++;
			if(direction[i]=='S') y--;
			if(direction[i]=='E') x++;
			if(direction[i]=='W') x--;
		}
		if(x<0||x>n||y<0||y>m) to=1;
		for(int i=1;i<=t;i++)
		{
			if(x==a[i]&&y==b[i]) {
			to=1;break;}
		}
		if(to==0) cout<<"the boss of river finished his show!!"<<endl;
		else cout<<"the boss of river is also desperated what can he do?"<<endl;
	}
	return 0;
 } 

猜你喜欢

转载自blog.csdn.net/reticent_man/article/details/80784111