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

1、第一题    AC

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

		} while (temp != 0);
		vector<int> 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<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int T;
	cin >> T;
	int i, ct, VALUE, LEFT, RIGHT;
	vector<string>  aaa;
	for (ct = 0; ct < T; ct++)
	{
		int N;
		cin >> N;
		vector<vector<int> > 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<int> 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<int> 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<int> 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<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>


using namespace std;

int solve(vector<int>& 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<M - 1; i++)
	{
		if (nums[i + 1] - nums[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<int> result1;
	for (int i = 0; i<T; i++)
	{
		cin >> K >> M;
		vector<int> nums(M);
		for (int j = 0; j<M; j++)
		{
			cin >> 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;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值