腾讯后台&综合笔试 9-6 4.05a

T1 两个顺序数组求交集 没啥好说的 第二个数组读入的时候一边读一边扫第一个数组就行
#include <iostream>
#define maxn 1000001
using namespace std;
int a[maxn];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n;i ++) {
		cin >> a[i];
	}
	int pos = 0;
	int m;
	cin >> m;
	for (int i = 0; i < m; i ++) {
		int temp;
		cin >> temp;
		while (a[pos] > temp) {
			pos ++;
		}
		if (a[pos] == temp) {
			cout << temp << " ";
			pos ++;
		}
	}
} 
T2 我好像似乎在哪里见过这道题 就一堆小团体 小团体一个人知到这个消息 = 所有人都知道这个消息 给0号传递个消息 问最后多少个人知道 很简单的无向图 每个团体的第一个人和剩下的团体内的其余人拉个无向边就行 之后从0跑bfs
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#define maxn 100010
using namespace std;
vector<int>G[maxn];
bool vis[maxn];
void addedge(int from, int to) {
	G[from].push_back(to);
	G[to].push_back(from);
}
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i ++) {
		int k;
		cin >> k;
		int temp;
		cin >> temp;
		for (int j = 1; j < k; j ++) {
			int c;
			cin >> c;
			addedge(temp, c);
		}
	}
	queue <int> que;
	que.push(0);
	vis[0] = 1;
	int ans = 1;
	while (!que.empty()) {
		int k = que.front();
		que.pop();
		for (int i = 0; i < G[k].size(); i ++) {
			int u = G[k][i];
			if(!vis[u]) {
				que.push(u);
				++ans;
				vis[u] = 1;
			}
		}
	}
	cout << ans;
}
T3 给个n个数字的数列 输出n行 第i行输出删掉第i个数字剩下的数列的中位数 而且题目还tm保证n时偶数,这题。。。。应该放第一题感觉
#include <iostream>
#include <cstdio>
#include <algorithm>
#define maxn 200001
using namespace std;
int data[maxn], orderedData[maxn];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++) {
		cin >> data[i];
		orderedData[i] = data[i];
	}
	sort(orderedData, orderedData + n);
	int k1 = orderedData[n/2 - 1], k2 = orderedData[n/2];
	for (int i = 0; i < n; i ++) {
		if (data[i] <= k1) {
			cout << k2;
		} else {
			cout << k1;
		}
		cout << " " << endl;
	}
}
T4 给n个字符串 输出出现次数最大的前k个和后k个 相同次数输出字典序小的 stl应用题 map一下排个序 没有任何思想含量
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <algorithm>
#define maxn 100010
using namespace std;
map<string, int>mapsi;
struct ele{
	string s;
	int times;
	ele(string s, int times):s(s),times(times){};
	ele(){};
}eles[maxn];
bool comp1(const ele &a, const ele&b) {
	return a.times != b.times ? a.times < b.times : a.s < b.s;
}
bool comp2(const ele &a, const ele&b) {
	return a.times != b.times ? a.times > b.times : a.s < b.s;
}
int main() {
	int n,k;
	cin >> n >> k;
	for (int i = 0; i < n; i ++) {
		string s;
		cin >> s;
		int t = mapsi[s];
		mapsi[s] = ++t;
	}
	auto ite = mapsi.begin();
	int pos = 0;
	while (ite != mapsi.end()) {
		eles[pos++] = ele(ite->first, ite->second);
		ite++;
	}
	sort(eles, eles + pos, comp2);
	for (int i = 0; i < k; i ++) {
		cout << eles[i].s << " " << eles[i].times << endl;
	}
	sort(eles, eles + pos, comp1);
	for (int i = 0; i < k; i ++) {
		cout << eles[i].s << " " << eles[i].times << endl;
	}
	
}
T5 摸了一个小时 摸出来了0.05知到自己哪里错了 但就是不会写


#腾讯笔试##笔试题目##腾讯#
全部评论
应该是5%吧。。我们是20个测试用例。
2 回复 分享
发布于 2020-09-06 22:08
只有我这么傻吗,第一题还真的去建链表再去遍历,最后也只过了70%(服了,,,,,),早知道用数组去了,,,
1 回复 分享
发布于 2020-09-07 00:07
一模一样4.05,最后一题有思路吗 讨论一下
点赞 回复 分享
发布于 2020-09-07 12:54
一模一样AC4 最后一个cout 0 混5分 最后一题真没思路
点赞 回复 分享
发布于 2020-09-07 12:50
第二题,我直接开了100005*100005的数组,段错误😂
点赞 回复 分享
发布于 2020-09-06 22:22
第二题用unionfind做一直说我数组越界😂😂😂😂
点赞 回复 分享
发布于 2020-09-06 22:10

相关推荐

吴offer选手:学到了,下次面试也放张纸在电脑上,不然老是忘记要说哪几个点
点赞 评论 收藏
分享
评论
点赞
24
分享

创作者周榜

更多
牛客网
牛客企业服务