2019.9.7网易互娱——游戏研发笔试

1、第一题    AC

#include
#include
#include
#include
using namespace std;
int main()
{
	int T;
	cin >> T;
	vector num(T);
	vector flag;
	int i,temp;
	for (i = 0; i < T; i++)
	{
		cin >> num[i];
	}
	for (i = 0; i < T; i++)
	{
		temp = num[i];
		vector g;
		do
		{
			g.push_back(temp % 2);
			temp /= 2;

		} while (temp != 0);
		vector h = g;
		reverse(g.begin(),g.end());
		if (h == g)
		{
			flag.push_back("YES");
		}
		else
		{
			flag.push_back("NO");
		}
    }
	for (i = 0; i < T; i++)
	{
		cout << flag[i] << endl;
	}
	system("pause");
	return 0;
}


 

2、第二题  AC

#include
#include
#include
#include
using namespace std;
int main()
{
	int T;
	cin >> T;
	int i, ct, VALUE, LEFT, RIGHT;
	vector  aaa;
	for (ct = 0; ct < T; ct++)
	{
		int N;
		cin >> N;
		vector > num(N);
		for (i = 0; i < N; i++)
		{
			cin >> VALUE >> LEFT >> RIGHT;
			num[i].push_back(VALUE);
			num[i].push_back(LEFT);
			num[i].push_back(RIGHT);
		}
		vector flag(N, 0);
		for (i = 0; i < N; i++)
		{
			if (num[i][1] != -1)
			{
				flag[num[i][1]] = 1;
			}
			if (num[i][2] != -1)
			{
				flag[num[i][2]] = 1;
			}
		}
		int root;
		for (i = 0; i < N; i++)
		{
			if (flag[i] == 0)
			{
				root = i;
				break;
			}
		}
		vector ceng(N, 9999);
		ceng[root] = 0;
		while (1)
		{
			for (i = 0; i < N; i++)
			{
				if (ceng[i] != 9999)
				{
					if (num[i][1] != -1 && ceng[num[i][1]]==9999)
					{
						ceng[num[i][1]] = ceng[i] + 1;
					}
					if (num[i][2] != -1 && ceng[num[i][2]] == 9999)
					{
						ceng[num[i][2]] = ceng[i] + 1;
					}
				}
			}
			bool dd = true;
			for (i = 0; i < N; i++)
			{
				if (ceng[i] == 9999)
				{
					dd = false;
					break;
				}
			}
			if (dd == true)
			{
				break;
			}
		}
		int max = 0;
		for (i = 0; i < N; i++)
		{
			if (ceng[i] > max)
			{
				max = ceng[i];
			}
		}
		vector res(max+1, 0);
		for (i = 0; i < N; i++)
		{
			res[ceng[i]] += num[i][0];
		}
		if (max == 1)
		{
			aaa.push_back("YES");
			continue;
		}
		bool temp = true;
		for (i = 1; i < max+1; i++)
		{
			if (res[i] <= res[i - 1])
			{
				temp = false;
			}
		}
		if (temp == true)
		{
			aaa.push_back("YES");
		}
		else
		{
			aaa.push_back("NO");
		}
	}
	for (i = 0; i < T; i++)
	{
		cout << aaa[i] << endl;
	}
	system("pause");
	return 0;
}

3、第三题   10%

#include
#include
#include
#include
#include


using namespace std;

int solve(vector& nums, int K, int M)
{
	int temp = 0;
	if (M == 0 && K != 0)
	{
		temp = 31 / (K + 1);
		return temp;
	}
	if (K == 0 && M != 0)
	{
		temp = 30;
		return temp;
	}
	if (K == 0 && M == 0)
	{
		temp = 30;
		return temp;
	}
	if(M == 1)
	if (nums[0] > K)
	{
		temp += (nums[0] - 1) / (K + 1);
	}
	if ((30 - nums[M - 1]) >= K)
	{
		temp += (30 - nums[M - 1]) / (K + 1);
	}
	for (int i = 0; i(2 * K + 1))
		{
			temp += (((nums[i + 1] - nums[i]) - 1) - K)/(K+1);
		}
	}
	return temp + M;
}

int main()
{
	int T;
	int K, M;
	cin >> T;
	vector result1;
	for (int i = 0; i> K >> M;
		vector nums(M);
		for (int j = 0; j> nums[j];
		}
		int result = solve(nums, K, M);
		result1.push_back(result);
		}
		
	    for (int i = 0; i < T; i++)
		{
			cout << result1[i] << endl;
		}
		system("pause");
		return 0;
}

 

你可能感兴趣的:(C++)