9.6腾讯笔试(后台&综合)

9.6腾讯笔试
第四题(题目有毒)
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int N;
	long long s = 0;
	cin >> N;
	vector<int> vec1(N),vec2(N);
	for (int i = 0; i < N; i++) {
		cin >> vec1[i];
		vec2[i] = vec1[i];
	}
	sort(vec2.begin(), vec2.end());
	int Lmid = vec2[N / 2 - 1];
	int Rmid = vec2[N / 2];
	for (int i = 0; i < N; i++) {
		if (vec1[i] >= Rmid) {
			cout << Lmid << "\n";
		}
		else {
			cout << Rmid << "\n";
		}
	}
	return 0;
}
第三题
#include <vector>
#include <string>
#include <iostream>
#include <unordered_map>
#include <queue>
#include <algorithm>
using namespace std;
long long res = 0;	
unordered_map<int, vector<int>> teams;
unordered_map<int, bool> teamVis;
unordered_map<int, bool> manVis;
vector<vector<int,int>> party;
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		vector<int> tVec;
		for (int j = 0; j < x; j++) {
			int t;
			cin >> t;
			tVec.emplace_back(t);
			teams[t].emplace_back(i);//x参加了什么
		}
		party.emplace_back(tVec);
	}

	cout << res;
	return 0;
}

void dfs(int curMan) {
	for (auto team : teams[curMan]) {
		if (teamVis[team] == false) {
			teamVis[team] = true;
			for (auto man : party[team]) {
				if (!manVis[man]) {
					res++;
					manVis[man] = true;
					dfs(man);
				}
				
			}
		}
	}
}

第二题:
#include <vector>
#include <string>
#include <iostream>
#include <unordered_map>
#include <queue>
#include <algorithm>
using namespace std;
struct MyCmp1 {
	bool operator()(const pair<string, int>& x, const pair<string, int>& y) {
		if (x.second == y.second) return x.first < y.first;
		return x.second > y.second;
	}
};
struct MyCmp1_1 {
	bool operator()(const pair<string, int>& x, const pair<string, int>& y) {
		if (x.second == y.second) return x.first < y.first;
		return x.second > y.second;
	}
};
struct MyCmp2 {
	bool operator()(const pair<string, int>& x, const pair<string, int>& y) {
		if (x.second == y.second) return x.first < y.first;
		return x.second < y.second;
	}
};
struct MyCmp2_2 {
	bool operator()(const pair<string, int>& x, const pair<string, int>& y) {
		if (x.second == y.second) return x.first < y.first;
		return x.second < y.second;
	}
};
int main()
{
	int N, K;
	cin >> N >> K;
	unordered_map<string,int> vis;
	//小顶
	priority_queue<pair<string, int>, vector<pair<string, int>>, MyCmp1> q1;
	//大顶
	priority_queue<pair<string, int>, vector<pair<string, int>>, MyCmp2> q2;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		//cout << s << '\n';
		vis[s]++;
	}
	for (auto v : vis) {
		string str = v.first;
		int cnt = v.second;
		//cout << v.first << " " << v.second << "\n";
		if (q1.size() < K) {
			q1.emplace(str, cnt);
		}
		else {
			if (q1.top().second < cnt) {
				q1.pop();
				q1.emplace(str, cnt);
			}
			else if (q1.top().second == cnt && str < q1.top().first) {
				q1.pop();
				q1.emplace(str, cnt);
			}
		}
		if (q2.size() < K) {
			q2.emplace(str, cnt);
		}
		else {
			if (q2.top().second > cnt) {
				q2.pop();
				q2.emplace(str, cnt);
			}
			else if (q2.top().second == cnt && str < q2.top().first) {
				q2.pop();
				q2.emplace(str, cnt);
			}
		}
	}
	vector<pair<string, int>> v1;
	vector<pair<string, int>> v2;
	while (!q1.empty()) {
		v1.emplace_back(q1.top().first, q1.top().second);
		q1.pop();
	}
	while (!q2.empty()) {
		v2.emplace_back(q2.top().first, q2.top().second);
		q2.pop();
	}
	sort(v1.begin(), v1.end(), MyCmp1_1());
	sort(v2.begin(), v2.end(), MyCmp2_2());
	for(auto i:v1) cout << i.first << " " << i.second << "\n";
	for(auto i:v2) cout << i.first << " " << i.second << "\n";
	return 0;
}


#腾讯#
全部评论
第五题是不是可以使用选择排序的思路。
1 回复 分享
发布于 2020-09-06 22:40
https://blog.csdn.net/qq_38649940/article/details/108438347 腾讯笔试题解!(虽然好像和大家题目不同emm....
1 回复 分享
发布于 2020-09-06 23:02
第四题那个题目我看了15分钟,还好A了,求个第五题思路
点赞 回复 分享
发布于 2020-09-06 22:04
不同岗位题不一样
点赞 回复 分享
发布于 2020-09-06 22:05
也不加个路过,别人直接点5岂不是打击我们的信心?😂
点赞 回复 分享
发布于 2020-09-06 22:10
有做算法研究员的哥们吗?感觉有点难啊
点赞 回复 分享
发布于 2020-09-06 22:12
大佬们都A了4道,羡慕
点赞 回复 分享
发布于 2020-09-06 22:14
做完华为的笔试赶着来腾讯 一个小时 第一题 双指针 100% 第二题 队列  思路写完,还没来得及调试代码。。。。。 感觉应该可以100%的 第三题 没认真看 0 第四题 中位数 50% 第五题 红黑旗  0
点赞 回复 分享
发布于 2020-09-06 22:21
就求一个红黑棋思路 感觉选4-4.99的那么多 都是死在红黑棋了
点赞 回复 分享
发布于 2020-09-06 22:24
第四题我人傻了
点赞 回复 分享
发布于 2020-09-06 22:26
第五题头皮挠破,最后输出0,+0.05分🤣
点赞 回复 分享
发布于 2020-09-06 22:34
第二题我构建了图结构,然后从0开始BFS遍历,结果只过了20,说是数组越界,看了好久感觉不应该啊,有人和我思路相似吗
点赞 回复 分享
发布于 2020-09-06 22:48
排序输出那道...我NM自己写测试用例怎么测试都对,传上去就是0我个five
点赞 回复 分享
发布于 2020-09-07 09:49
第五题盯了半小时草稿纸写了一整张还是没思路。。。QAQ
点赞 回复 分享
发布于 2020-09-07 19:30

相关推荐

01-21 12:26
暨南大学 golang
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
2024-12-18 15:35
程序员牛肉:完全是在胡写简历。 我很好奇你干嘛要在教育经历里面写你是软件二班的班长?你写它的目的是什么?我觉得真的就是很突兀。给我第一感觉就是:你真的是一个心智健全的成年人吗? 另外我也很好奇你是怎么做到参加了这么多所谓的计算机比赛,完事儿一个拿得出手的项目都没有。 自己的项目经历还是图书馆管理系统这种垃圾东西……我的的建议是你都不如大幅度删减一下自己的水奖项,看着真的给人一种又水又学傻了的感觉。 计算机不看奖项,看院校和个人能力。 计算机是强工科,你要投后端的你就应该明白,人家招你进去是指望你干活儿的。那你觉得你这份简历有展示出你的后端水平吗? 你动动你的脑子想一想,人家面试官要想通过你的简历看出你的项目开发能力,最重要的板块就是两个,第一个是你的实习,第二个是你的项目。你没有实习,是不是就应该在项目上好好琢磨琢磨? 你自己看看你项目写的什么描述,你作为一个要后端岗位的应届生,你对你自己项目的描述还仅仅停留在使用mySQL,使用JAVA,使用spring boot框架。给人一眼感觉就感觉完全就是你做的玩具。可能就是你哪一个学期做的课设。 对于应届生来讲,在项目板块要尽量突出自己的技术能力,因为谈业务你肯定也不懂。简单来讲,你的项目要清晰准确的表达:你用哪种技术解决了现有的哪种技术问题,带来了多少的效益提升? 所有关于项目的描述都围绕我说的这种表达方式去写。不要自己自嗨式的写一堆垃圾上去 你既没有实习项目,又没有一个比较好一点的项目,而且院校也比较差,所以找工作会异常的难找。
点赞 评论 收藏
分享
02-09 10:51
已编辑
门头沟学院 Java
Java抽象带篮子:考完研冲春招可以看看我的置顶帖子,里面写了怎么写简历,怎么包装实习经历,还有八股笔记资料和速成的高质量项目话术呢
点赞 评论 收藏
分享
评论
5
18
分享

创作者周榜

更多
牛客网
牛客企业服务