网易互娱小球变色问题ac,代码如下
#include <iostream>
#include <vector>
using namespace std;
int dx[4]{-1, -1, 1, 1};
int dy[4]{-1, 1, 1, -1};
int N, M;
void dp(int& f, int i, int j, int w, int cnts)
{
if (cnts == 0) return;
int a = i, b = j;
if (w == 0) a += dx[0], b += dy[0];
if (w == 1) a += dx[1], b += dy[1];
if (w == 2) a += dx[2], b += dy[2];
if (w == 3) a += dx[3], b += dy[3];
cnts--;
if (a == 2 || b == 2 || a == N - 1 || b == M - 1)
{
if (a == 2)
{
if (b == 2) w = 2, f += 2;
if (b == M - 1) w = 3, f += 2;
if (w == 0) w = 3, f += 1;
if (w == 1) w = 2, f += 1;
}
else if (a == N - 1)
{
if (b == 2) w = 1, f += 2;
if (b == M - 1) w = 0, f += 2;
if (w == 2) w = 1, f += 1;
if (w == 3) w = 0, f += 1;
}
else
{
if (b == 2)
{
if (w == 0) w = 1, f += 1;
if (w == 3) w = 2, f += 1;
}
if (b == M - 1)
{
if (w == 2) w = 3, f += 1;
if (w == 1) w = 0, f += 1;
}
}
}
dp(f, a, b, w, cnts);
}
int main()
{
int cnt = 0;
cin >> cnt;
for (int i = 0; i < cnt; i ++ )
{
int rows, cols;
cin >> rows >> cols;
N = rows, M = cols;
int x, y, w, t;
cin >> x >> y >> w >> t;
int f = 0;
dp(f, x, y, w, t);
cout << f << endl;
}
return (0);
}
#网易互娱##笔试题目#
#include <vector>
using namespace std;
int dx[4]{-1, -1, 1, 1};
int dy[4]{-1, 1, 1, -1};
int N, M;
void dp(int& f, int i, int j, int w, int cnts)
{
if (cnts == 0) return;
int a = i, b = j;
if (w == 0) a += dx[0], b += dy[0];
if (w == 1) a += dx[1], b += dy[1];
if (w == 2) a += dx[2], b += dy[2];
if (w == 3) a += dx[3], b += dy[3];
cnts--;
if (a == 2 || b == 2 || a == N - 1 || b == M - 1)
{
if (a == 2)
{
if (b == 2) w = 2, f += 2;
if (b == M - 1) w = 3, f += 2;
if (w == 0) w = 3, f += 1;
if (w == 1) w = 2, f += 1;
}
else if (a == N - 1)
{
if (b == 2) w = 1, f += 2;
if (b == M - 1) w = 0, f += 2;
if (w == 2) w = 1, f += 1;
if (w == 3) w = 0, f += 1;
}
else
{
if (b == 2)
{
if (w == 0) w = 1, f += 1;
if (w == 3) w = 2, f += 1;
}
if (b == M - 1)
{
if (w == 2) w = 3, f += 1;
if (w == 1) w = 0, f += 1;
}
}
}
dp(f, a, b, w, cnts);
}
int main()
{
int cnt = 0;
cin >> cnt;
for (int i = 0; i < cnt; i ++ )
{
int rows, cols;
cin >> rows >> cols;
N = rows, M = cols;
int x, y, w, t;
cin >> x >> y >> w >> t;
int f = 0;
dp(f, x, y, w, t);
cout << f << endl;
}
return (0);
}
#网易互娱##笔试题目#