网易互娱游戏研发笔试 3道全A

1 判断数字的二进制形式是否是回文串
很简单,因为python有直接转二进制的函数所以用了python
#判断数字的二进制形式是否是回文串
def judge(x):
	s=bin(x)[2:]
	l=len(s)
	for i in range(0,l//2):
		if  s[i]!=s[l-i-1]:
			return 'NO'
	return 'YES'

T=input()
for i in range(0,T):
	x=input()
	print judge(x)
2判断是否是递增树
#include <iostream>
#include <string.h>
#include <limits.h>
#include <cmath>
#include <queue>
#include<vector>

using namespace std;
//测试数据
// 2
// 8
// 2 -1 -1
// 1 5 3
// 4 -1 6
// 2 -1 -1
// 3 0 2
// 2 4 7
// 7 -1 -1
// 2 -1 -1
// 8
// 21 6 -1
// 52 4 -1
// 80 0 3
// 31 7 -1
// 21 -1 -1
// 59 -1 -1
// 50 5 -1
// 48 -1 1
int a[1000 + 1][2];
int value[1000 + 1];
int vis[1001];
//判定是否是递增树
//int findroot(int l)
//{
//	for (int i = 0; i < l; i++)
//	{
//		int f = 0;
//		for (int j = 0; j < l; j++)
//		{
//			if (a[j][i] == 1)
//			{
//				f = 1;
//				break;
//			}
//		}
//		if (f == 0)
//			return i;
//	}
//	return 0;
//}
void judge(int length)
{
	int i;
	for (i = 0; i < length; i++)
		if (vis[i] == 0)break;


	queue<int> q;
	queue<int> nextq;
	q.push(i);
	int pre_sum = -1;
	while (!q.empty()) 
	{
		int sum = 0;
		while (!q.empty())
		{
			int root = q.front();
			q.pop();
			sum += value[root];

			if (a[root][0]>=0)nextq.push(a[root][0]);
			if (a[root][1] >=0)nextq.push(a[root][1]);
		}
	//		for (int i = 0; i < length; i++)
	//			if (a[root][i] == 1)
	//				nextq.push(i);

	//	}
		if (sum > pre_sum)
		{ pre_sum = sum; }
		else { 
		cout << "NO" << endl;
		return;
		}
		q.swap(nextq);
	}
	cout << "YES" << endl;
	return;
}

int main()
{
	int T;
	cin >> T;
	while(T--)
	{
		int N;
		cin >> N;
		memset(vis,0,4*N);
		for (int i = 0; i < N; i++)
		{
			int v, l, r;
			cin >> v >> l >> r;
			value[i] = v;
			if (l != -1)vis[l] = 1;
			if (r != -1)vis[r] = 1;
			a[i][0] = l;
			a[i][1] = r;
		}
		//cout << _I << endl;
		judge(N);
	}

}
3 喝咖啡
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include<vector>
using namespace std;

//void judge(int **a, int* v, int length)
//{
//	queue<int> q;
//}
//喝咖啡

int coffee(int K, int M, int *m)
{
	if (K == 0)return 30;
	int times = M;
	if (M == 0)return times + 29 / (K + 1)+1;
	
	if (m[0] != 1&& m[0] - K - 2>=0) times = times + 1 + (m[0] - K - 2) / (K + 1);
	for (int i = 0; i < M-1; i++)
	{
		int t = m[i + 1] - m[i];
		if (t < 2*K+2)continue;
		times = times + 1 + (t - 2 * K - 2) / (K + 1);
		//cout << times << endl;
	}
	if (m[M-1] != 30 && 30 - m[M - 1] - K - 1 >= 0) times = times + 1 + (30-m[M-1] - K - 1) / (K + 1);
	return times;
}

int main()
{
	int T;
	cin >> T;
	for (int j = 0; j < T; j++)
	{
		int K;
		int M;
		cin >> K >> M;
		int m[30];
		for (int i = 0; i < M; i++)
			cin >> m[i];
		cout << coffee(K, M, m) << endl;
	}

}


#笔试题目##网易互娱#
全部评论
请问游戏研发岗位可以用python写吗?
点赞
送花
回复
分享
发布于 2022-02-28 18:09

相关推荐

点赞 12 评论
分享
牛客网
牛客企业服务