美团笔试820

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<unordered_map>
using namespace std;

// 交替输出字符串
void first() {
	int n = 0;
	cin >> n;
	string line1, line2;
	cin >> line1;
	cin >> line2;

	for (int i = 0; i < n; i++) {
		cout << line1[i] << line2[i];
	}
}
// 通信坐标最小
void second() {
	int n = 0;
	cin >> n;
	int x1 = 0, x2 = 0, x3 = 0, y1 = 0, y2 = 0, y3 = 0;
	cin >> x1 >> y1;
	cin >> x2 >> y2;
	cin >> x3 >> y3;
	int d1 = 0, d2 = 0, d3 = 0;
	cin >> d1 >> d2 >> d3;
	set<string> s1, s2;

	int ansx = INT32_MAX, ansy = INT32_MAX;
	for (int x = x1 - d1; x < x1 + d1; x++) {
		if (x <= 0 || x > n) continue;

		int xd = abs(x - x1);
		int left = d1 - xd;
		if (left == 0) {
			string k = to_string(x) + " " + to_string(y1);
			s1.insert(k);
		}
		else {
			int yy1 = y1 - left;
			int yy2 = y1 + left;
			if (yy1 > 0 && yy1 <= n) {
				string k = to_string(x) + " " + to_string(yy1);
				s1.insert(k);
			}
			if (yy2 > 0 && yy2 <= n) {
				string k = to_string(x) + " " + to_string(yy2);
				s1.insert(k);
			}
		}
	}
	
	for (int x = x2 - d2; x < x2 + d2; x++) {
		if (x <= 0 || x > n) continue;

		int xd = abs(x - x2);
		int left = d2 - xd;
		if (left == 0) {
			string k = to_string(x) + " " + to_string(y2);
			if (s1.count(k))
				s2.insert(k);
		}
		else {
			int yy1 = y2 - left;
			int yy2 = y2 + left;
			if (yy1 > 0 && yy1 <= n) {
				string k = to_string(x) + " " + to_string(yy1);
				if(s1.count(k))
					s2.insert(k);
			}
			if (yy2 > 0 && yy2 <= n) {
				string k = to_string(x) + " " + to_string(yy2);
				if (s1.count(k))
					s2.insert(k);
			}
		}
	}


	for (int x = x3 - d3; x < x3 + d3; x++) {
		if (x <= 0 || x > n) continue;

		int xd = abs(x - x3);
		int left = d3 - xd;
		if (left == 0) {
			string k = to_string(x) + " " + to_string(y3);
			if (s2.count(k)) {
				if (ansx > x || ansx == x && ansy > y3) {
					ansx = x;
					ansy = y3;
				}
			}
				
		}
		else {
			int yy1 = y3 - left;
			int yy2 = y3 + left;
			if (yy1 > 0 && yy1 <= n) {
				string k = to_string(x) + " " + to_string(yy1);
				if (s2.count(k)) {
					if (ansx > x || ansx == x && ansy > y3) {
						ansx = x;
						ansy = yy1;
					}
				}
			}
			if (yy2 > 0 && yy2 <= n) {
				string k = to_string(x) + " " + to_string(yy2);
				if (s2.count(k)) {
					if (ansx > x || ansx == x && ansy > y3) {
						ansx = x;
						ansy = yy2;
					}
				}
			}
		}
	}


	cout << ansx<<" "<<ansy;

}

// 复习获取最大期望
void third() {
	int n = 0, m = 0;
	cin >> n >> m;
	int i = 0;
	int num = 0;
	vector<int> p(n, 0), scores(n, 0);
	while (i < n) {
		cin >> num;
		p[i++] = num;
	}
	i = 0;
	while (i < n) {
		cin >> num;
		scores[i++] = num;
	}

	vector<pair<int,double>> tmp(n,{0,0});
	for (i = 0; i < n; i++) {
		tmp[i] = { i,(double)(100 - p[i]) / (double)100 * (double)scores[i] };
	}

	sort(tmp.begin(), tmp.end(), [&](const pair<int, double>& a, const pair<int, double>& b) {
		return a.second > b.second;
		});
	set<int> indexs;
	for (i = 0; i < m; i++) {
		indexs.insert(tmp[i].first);
	}
	double sum = 0;
	for (i = 0; i < n; i++) {
		if (indexs.count(i)) {
			sum += scores[i];
		}
		else {
			sum += (double)scores[i] * (double)p[i] / 100.0;
		}
	}

	printf("%.2f", sum);
}

 
long dp(vector<int>& s1, vector<int>& s2, int i, int j, unordered_map<long, long>& memo) {
	if (i < 0 && j < 0)
		return 0;
	int key = i * 20000 + j;
	if (memo.count(key)) {
		return memo[key];
	}
	long i_c = LONG_MAX;
	long j_c = LONG_MAX;
	long cc = LONG_MAX;
	if (i >= 0 && j >= 0) {
		cc = abs(s1[i] - s2[j]) + dp(s1, s2, i - 1, j - 1, memo);
		i_c = abs(s1[i]) + dp(s1, s2, i - 1, j, memo);
		j_c = abs(s2[j]) + dp(s1, s2, i, j - 1, memo);
	}
	else if (i >= 0) {
		i_c = abs(s1[i]) + dp(s1, s2, i - 1, j, memo);
	}
	else if (j >= 0) {
		j_c = abs(s2[j]) + dp(s1, s2, i, j - 1, memo);
	}

	memo[key] = min(min(i_c, j_c), cc);

	return memo[key];

}

// 同步两个字符串的最小距离
void forth() {
	int n = 0, m = 0;
	cin >> n >> m;
	int i = 0;
	int num = 0;
	vector<int> s1(n, 0), s2(m, 0);
	while (i < n) {
		cin >> num;
		s1[i++] = num;
	}
	i = 0;
	while (i < m) {
		cin >> num;
		s2[i++] = num;
	}

	unordered_map<long, long> memo;

	long ans = dp(s1, s2, n - 1, m - 1, memo);
	cout << ans;
}
int main() {
	forth();

	return 0;
}
#美团笔试#
全部评论
第二题一直不能AC全部,也不知道哪错了。。
点赞
送花
回复
分享
发布于 2022-08-20 12:25 四川
第二题代码好长哦
点赞
送花
回复
分享
发布于 2022-08-20 12:30 北京
秋招专场
校招火热招聘中
官网直投
我想问一下 java 第一题 public static void out(String A,String B,int n){     StringBuffer ans=new StringBuffer();     for(int i=0;i<n;i++){              ans.append(A.charAt(i));              ans.append(B.charAt(i));      }      System.out.println(ans.toString()); } 不知道为什么过不了 能解答一下吗
点赞
送花
回复
分享
发布于 2022-08-20 13:01 上海
复习最大期望是必须要保留两位小数吗,我说怎么一直无法a掉,淦。另外你写的这几个题的代码,和我简直一模一样哈哈
点赞
送花
回复
分享
发布于 2022-08-20 14:06 北京
楼主,问一下,第四题一定要用long吗,我用int只过了45%,是因为越界的关系吗
点赞
送花
回复
分享
发布于 2022-08-20 17:18 四川
我还想问一下定位那一题思路,有没有大佬解答一下
点赞
送花
回复
分享
发布于 2022-08-20 17:23 四川
麻烦问下投的什么岗位的笔试?
点赞
送花
回复
分享
发布于 2022-08-20 18:11 山东

相关推荐

感觉这一周太梦幻了,就像一个梦,很不真实~~~感觉这个暑期,我的运气占了99成,实力只有百分之一4.15上午&nbsp;腾讯csig&nbsp;腾讯云部门,面完秒进入复试状态4.16下午&nbsp;美团优选供应链部门,4.18上午发二面4.17晚上&nbsp;阿里国际一面,纯拷打,面完我都玉玉了4.18下午&nbsp;阿里国际二面,是我们leader面的我,很轻松~~4.18晚上&nbsp;约了hr面4.19上午&nbsp;hr面,下午两点口头oc4.19晚上&nbsp;意向书说起来我的暑期好像一次都没挂过~~~~~难道我是天生面试圣体?----------------------------------------------------------------------六个月前,我还是0项目0刷题,当时想的是先把论文发出来再去找实习。结果一次组会,老师打破了我的幻想(不让投B会,只让投刊或者A)我拿头投啊!!!然后就开始物色着找实习,顺便做完了mit的6.s081,但是基本上还是没刷过题目-----------------------------------------------------------------------11月&nbsp;&nbsp;一次偶然的机会,面进了某个耳机厂的手环部门,大概是做嵌入式的,用的是CPP。12月&nbsp;莫名其妙拿到了国创的面试机会,0基础四天速成java基础!居然也给我面过了hhhhh,可能是面试没写题吧入职国创后的几个月,一直没活,天天搁那看剧,都快忘了还有暑期实习这回事了~~~~命运的齿轮在2.26开始转动,因为这一天美团开了,我开始慌了,因为那时的我什么都不会。lc,八股,sql全部是0进度。然后就开始了女娲补天,上班刷题,下班继续做之前的开源,顺便学一学八股。3月到现在,lc也刷到快200了,一天最多提交了47次~~~~~~~~~~八股根据别人的面经总结和博客,写了快十万字的笔记~~~~~~~~~~简历上的实习经历和开源,也努力去深挖了,写了几万字的记录~~~~~~所以面试的时候,基本上都能cover了,面试官问到的基础基本都会,不基础的我就把他往我会的地方引。结果好像还不错,基本上每个面试官评价都挺好的emmmmmmmm
投递阿里巴巴等公司10个岗位
点赞 评论 收藏
转发
2 5 评论
分享
牛客网
牛客企业服务