网易笔试题

#include<iostream>
//网易笔试题第一题
/*
给定一个棋盘M、N,小球的初始位置Ax、Ay,初始方向V(1左上,2右上,3右下,4左下),时间time,
求最终小球位置


*/
using namespace std;
bool wall(int Ax, int Ay, int M, int N, int &Vx, int &Vy, int &rushcount){
	bool rush = false;
	if (Ax == 1 && Vx < 0)//上
	{
		Vx = 1;
		rush = true;
		rushcount++;
		
	}
	else if (Ax == M - 2 && Vx > 0)//下
	{
		Vx = -1;
		rush = true;
		rushcount++;
		
	}

	if (Ay == 1 && Vy < 0)//左
	{
		Vy = 1;
		rush = true;
		rushcount++;
		
	}
	else if (Ay == N - 2 && Vy > 0)//右
	{
		Vy = -1;
		rush = true;
		rushcount++;
		
	}
	return rush;

}
void main5(){
	int  Lizi, M = 0, N = 0, Ax = 0, Ay = 0, Vx = 0, Vy = 0, V = 0;
	cin >> Lizi;
	int Mns[1000];
	int Axys[1000];
	int Vxys[1000];
	int Times[1000];

	for (int i = 0; i < Lizi; i++){
		cin >> M >> N;
		Mns[i * 2] = M;
		Mns[i * 2 + 1] = N;
		cin >> Ax >> Ay;
		Axys[i * 2] = Ax - 1;
		Axys[i * 2 + 1] = Ay - 1;
		cin >> V;
		if (V == 0)
		{
			Vx = -1;
			Vy = -1;
		}
		else if (V == 1)
		{
			Vx = -1;
			Vy = 1;
		}
		else if (V == 2)
		{
			Vx = 1;
			Vy = 1;
		}
		else if (V == 3)
		{
			Vx = 1;
			Vy = -1;
		}
		Vxys[i * 2] = Vx;
		Vxys[i * 2 + 1] = Vy;
		cin >> Times[i];
	}
	for (int j = 0; j < Lizi; j++)
	{
		
		int Ax1 = Axys[j * 2], Ay1 = Axys[j * 2 + 1];
		int Vx1 = Vxys[j * 2], Vy1 = Vxys[j * 2 + 1];
		int M1 = Mns[j * 2], N1 = Mns[j * 2 + 1];
		int rushcount = 0;
		for (int k = 0; k <= Times[j]; k++)
		{
			bool rush = wall(Ax1, Ay1, M1, N1, Vx1, Vy1, rushcount);

			Ax1 += Vx1;
			Ay1 += Vy1;
		}
		cout << rushcount << endl;
	}


	system("pause");

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值