网易0327笔试算法岗第一题

第一题只过了50% 有大佬帮忙看看哪里有问题吗
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<numeric>
using namespace std;
int a[200001];
int main()
{
	int n;
	cin >> n;
	string s;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	cin >> s;
	//询问次数
	int times;
	cin >> times;
	//
	for (int i = 0; i < times; i++)
	{
		//第x天的得分
		//红色 小红得分 紫色 小紫得分
		int x;
		cin >> x;
		//数组长度为n
		int start = 0;
		int rScores = 0;
		int pScores = 0;
		int index = 0;
		while (x)
		{
			//当前所在的位置
			if (start >= n)
			{
				start = 0;
			}
			index = start;
			//小红得分
			if (s[index] == 'R')
			{
				rScores += a[index];
			}
			//小紫得分
			else
			{
				pScores += a[index];
			}
			start++;
			x--;
		}
		cout << rScores << " " << pScores << endl;

	}
}


#网易笔试##笔试题目##网易互娱#
全部评论
超时了吧。应该只循环一次
1 回复 分享
发布于 2022-03-27 17:23
前缀和配合 整除取模可以过
1 回复 分享
发布于 2022-03-27 17:28
我感觉第一题应该可以用二分查找,释放次数多于某个数可以把小怪打死,小于就不行,这样应该是符合二分查找的条件的
点赞 回复 分享
发布于 2022-03-27 19:15
楼主您好,考虑蚂蚁实习吗。 岗位介绍: https://m.nowcoder.com/discuss/868274 如果有意向的话,可以加我微信了解呢。longterm-value(备注: 牛客 网)
点赞 回复 分享
发布于 2022-03-27 18:37
int改成long long
点赞 回复 分享
发布于 2022-03-27 18:06
过了86%,不知道什么问题?
点赞 回复 分享
发布于 2022-03-27 18:03
我也只50,现在想想用动态规划,保存和,就应该差不多,不用重复计算
点赞 回复 分享
发布于 2022-03-27 17:56
重复计算太多,超时了吧。
点赞 回复 分享
发布于 2022-03-27 17:23

相关推荐

谁知道呢_:要掉小珍珠了,库库学三年,这个结果
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

更多
牛客网
牛客企业服务