VMWare 9.21笔试

第一题 AC
#include <bits/stdc++.h>
using namespace std;

int main() {
	int m;
	double n, r;
	string s1, s2;
	cin >> s1 >> m >> s2;
	n = stod(s1);
    //printf("%f\n", n);
    //cout << n << endl;
	r = stod(s2);
	int x, y;
	for (int i = 1; i <= m; ++i) {
		double cur = i * 1.0 * r;
		int times = cur / (4.0 * n);
        //cout << times << endl;
		cur = cur - times * 4.0 * n;
        //cout << cur << endl;
		if (cur >= 0 && cur <= n * 1.0) {
            //cout << 1 << endl;
			printf("%.2f %.2f\n", cur, 0.0);
		} else if (cur > n * 1.0 && cur <= n * 2.0) {
            //cout << 2 << endl;
			printf("%.2f %.2f\n", n * 1.0, cur - n);
		} else if (cur > n * 2.0 && cur <= n * 3.0) {
            //cout << 3 << endl;
			printf("%.2f %.2f\n", 3.0 * n - cur, n * 1.0);
		} else {
            //cout << 4 << endl;
			printf("%.2f %.2f\n", 0.0, 4.0 * n - cur);
		}
	}
}

第二题 AC
#include <bits/stdc++.h>
using namespace std;

int main() {
	int T, n;
	cin >> T;
	while (T--) {
		cin >> n;
		vector<int> pre(n);
		vector<int> next(n);
		for (int i = 0; i < n; ++i)
			cin >> pre[i];
		for (int i = 0; i < n; ++i)
			cin >> next[i];		
		vector<int> simp;
		simp.push_back(next[0]);
		for (int i = 1; i < n; ++i) {
			if (next[i] == next[i - 1])
				continue;
			simp.push_back(next[i]);
		}
		int i = 0;
		int j = 0;
		while (i < simp.size() && j < n) {
			if (simp[i] == pre[j]) {
				++i;
			}
			++j;
		}
		if (i == simp.size())
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

第三题 暴力 n的三次方,45%
后来想起来可以直接统计i和j的度,如果有i到j的边,就减去1,用了unordered_set存边(pair),编译失败。。。
查了一下,原来unordered_set不能直接存pair https://blog.csdn.net/zhaohaibo_/article/details/90340120
改成用二维vector,贴个代码
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> PAIR;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> first(n);
	vector<int> second(n);
	vector<vector<char>> edge(n + 1, vector<char>(n + 1, 0));
	vector<int> times(n + 1, 0);
	for (int i = 0; i < n; ++i) {
		cin >> first[i] >> second[i];
		++times[first[i]];
		++times[second[i]];
		edge[first[i]][second[i]] = 1;
		edge[second[i]][first[i]] = 1;
	}
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			int count = times[i] + times[j];
			if (edge[i][j] == 1)
				--count;
			if (count >= k)
				++res;
		}
	}
	cout << res << endl;
}



#笔试题目##VMware#
全部评论
第三题: 遍历时做1、2 操作 1、记录 pair 对(如<1, 2>,right>left)个数 为 p 2、维护一个 被选中 i 的邻接链表(倒排索引),以例子说明: ​     1 --> 1, 3, 4;2 ---> 2;3 ---> 2, 4; 4--->3 对 2 按 个数排序,然后双指针可得,包含重复的组合有 s = C(right - left + 1, 2),其中 cnt[right] + cnt[left] >= k 去重(O(n)):满足 cnt[a] + cnt[b] - p(共同选择) < k 的 pair 对 为 t, (容斥) 答案:s - t
1 回复
分享
发布于 2020-09-22 10:14
第三题我n^2暴力+剪枝还是45%,不过是Python。
点赞 回复
分享
发布于 2020-09-21 22:56
联想
校招火热招聘中
官网直投
第一题89%不知道为什么😢
点赞 回复
分享
发布于 2020-09-22 01:06
第三题36%
点赞 回复
分享
发布于 2020-09-22 08:42

相关推荐

3 4 评论
分享
牛客网
牛客企业服务