拼多多9.1笔试1,1,0.6,1

T1
把一个矩阵分成按对角线分成八份,如
5
0 2 0 1 0
3 0 0 0 8
0 0 0 0 0
4 0 0 0 7
0 5 0 6 0
8
0 2 2 2 1 1 1 0
3 0 2 2 1 1 0 8
3 3 0 2 1 0 8 8
3 3 3 0 0 8 8 8
4 4 4 0 0 7 7 7
4 4 0 5 6 0 7 7
4 0 5 5 6 6 0 7
0 5 5 5 6 6 6 0
#include <iostream>
#include <queue>
using namespace std;
int ju[201][201], temp;
struct pos{
	int x, y;
};
bool ifLegal(int x, int y) {
	return x >= 0 && x < temp && y >= 0 && y < temp;
}
int d[2][4]={{-1,0,1,0},{0,1,0,-1}};
void da(int x, int y,int c) {
	pos t;
	t.x = x;
	t.y = y;
	queue<pos>que;
	que.push(t);
	while(!que.empty()) {
		pos k = que.front();
		que.pop();
		if (!ifLegal(k.x, k.y))
		continue;
		if (ju[k.x][k.y] != 0)
		continue;
		ju[k.x][k.y] = c;
		for (int i = 0; i < 4; i ++) {
			pos temp;
			temp.x = k.x + d[0][i];
			temp.y = k.y + d[1][i];
			que.push(temp);
		}
	};
}
int main() {
	int n;
	cin >> n;
	temp = n;
	if (temp%2 == 0) {
		++ temp;
	}
	for (int i = 0; i < temp; i ++) {
		ju[i][i] = -1;
		ju[i][temp - i - 1] = -1;
		ju[temp/2][i] = -1;
		ju[i][temp/2] = -1;
	}
	da(0, temp - 2, 1); 
	da(0, 1, 2);
	da(1,0,3);
	da(temp - 2, 0, 4);
	da(temp - 1, 1, 5);
	da(temp - 1, temp - 2, 6);
	da(temp - 2, temp - 1, 7);
	da(1, temp - 1, 8);
	for (int i = 0; i < temp; i ++) {
		for (int j = 0; j < temp; j ++) {
			if (temp != n && (i == temp/2 || j == temp / 2)){
				continue;
			}
			if (ju[i][j] == -1)
			cout << 0;
			else
			cout << ju[i][j];
			cout << " ";
		}
		if (temp != n && i == temp/2)
		continue;
		cout << endl;
	}
}
T2
有一个n*n的棋盘 对应位是1代表是士兵 否则不是 一个士兵和他的上下左右四个位置的士兵可直接连接 连接在一起的士兵构成一个兵团 问移动一个士兵 得到的最大兵团的士兵个数
首先bfs出来全部的兵团,之后枚举每个位置添加士兵,算出添加士兵后的最大军团数量,之后取这个值和全部士兵的最小值输出,因为如果全部士兵不构成一个兵团 我们必能拿出一个其他兵团的兵添加到该位置 反之 拿兵团外围一个兵也可添加到该位置
    #include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
bool shibing[400][400];
int shibingS[400][400];
struct pos{
	int x, y;

};
int d[2][4]={{-1,0,1,0},{0,1,0,-1}};
int num[400 * 400];
bool numcc[400*400];
int n, m;
bool ifLegal(int x, int y) {
	return x >= 0 && x < n && y >= 0 && y < m;
}
int da(int x, int y,int c) {
	pos t;
	int ans = 0;
	t.x = x;
	t.y = y;
	queue<pos>que;
	que.push(t);
	while(!que.empty()) {
		pos k = que.front();
		que.pop();
		if (!ifLegal(k.x, k.y))
		continue;
		if (shibing[k.x][k.y] == 0 || shibingS[k.x][k.y] == c)
		continue;
		shibingS[k.x][k.y] = c;
		ans++;
		for (int i = 0; i < 4; i ++) {
			pos temp;
			temp.x = k.x + d[0][i];
			temp.y = k.y + d[1][i];
			que.push(temp);
		}
	};
	//cout << ans << endl;
	return ans;
}
int main() {
	int cnt = 0, alll = 0;
	memset(shibingS, -1, sizeof(shibingS));
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j ++) {
			cin >> shibing[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i ++) {
		for (int j = 0; j < m; j ++) {
			if (shibingS[i][j] == -1 && shibing[i][j]) {
				++ cnt;
				num[cnt] = da(i, j, cnt);
				ans = max(ans, num[cnt]);
				alll += num[cnt];
			}
		}
	}
	queue<int>que;
//	for (int i = 0; i < n; i ++) {
//		for (int j = 0; j < m; j ++) {
//			cout << shibingS[i][j] << " ";
//		}
//		cout << endl;
//	}
	for (int i = 0; i < n; i ++) {
		for (int j = 0; j < m; j ++) {
			if (shibing[i][j])
			continue;
			int temp = 0;
			for (int k = 0; k < 4; k ++) {
				int x = i + d[0][k];
				int y = j + d[1][k];
				if (!ifLegal(x, y))
				continue;
				if (shibingS[x][y] != -1 && !numcc[shibingS[x][y]]) {
					numcc[shibingS[x][y]] = 1;
					temp += num[shibingS[x][y]];
					que.push(shibingS[x][y]);
				}
			}
			temp += 1;
			ans = max(ans, temp);
			while (!que.empty()) {
				int k = que.front();
				que.pop();
				numcc[k] = 0;
			}
		}
	}
	cout << min(ans, alll) << endl;
} 
T3
0,1背包问题 有负cost和负value 写丑了 不放代码了
T4
容斥原理 给定一个集合s求出[1,n]能被集合中任意元素整除的元素的数量
#include <iostream>
using namespace std;
long long gcd(long long m, long long n) {
	return n == 0 ? m : gcd(n, m%n);
}
long long k[11];
long long ans = 0;
long long allll;
int allnum;
void sele(int pos,int te,int all,long long lcm) {
	if (pos == all) {
		int temp = 1;
		for (int i = 1; i < all; i++) {
			temp*=-1;
		}
		ans += temp * (allll/lcm);
		return;
	}
	for (int t = te; t < allnum; t ++) {
		long long tec = k[t];
		if (pos != 0) {
			long long gc = gcd(lcm, tec);
			tec /= gc;
			tec *= lcm;
		}
		sele(pos + 1, t + 1, all, tec);
	}
	
}
int main() {
	cin >> allll >> allnum;
	for (int i = 0; i < allnum; i ++) 
	cin >> k[i];
	for (int i = 1; i <= allnum; i ++) 
	sele(0,0,i,0);
	cout << ans;
}
感觉这次笔试题不是很难,但脑子确实有点转不动



#笔试题目##拼多多#
全部评论
请问第二题 numcc[shibingS[x][y]] 这个numscc是什么意思
点赞 回复 分享
发布于 2020-09-02 12:06
最后一题什么思路的?
点赞 回复 分享
发布于 2020-09-02 09:22
tql
点赞 回复 分享
发布于 2020-09-01 21:24

相关推荐

06-27 12:54
已编辑
门头沟学院 Java
累了,讲讲我的大学经历吧,目前在家待业。我是一个二本院校软件工程专业。最开始选专业是觉得计算机感兴趣,所以选择了他。本人学习计算机是从大二暑假结束开始的,也就是大三开始。当时每天学习,我个人认为Java以及是我生活的一部分了,就这样持续学习了一年半,来到了大四上学期末,大概是在12月中旬,我终于找的到了一家上海中厂的实习,但我发现实习生的工作很枯燥,公司分配的活也不多,大多时间也是自己在自学。就这样我秋招末才找到实习。时间来到了3月中旬,公司说我可以转正,但是转正工资只有7000,不过很稳定,不加班,双休,因为要回学校参加答辩了,同时当时也是心高气傲,认为可以找到更好的,所以放弃了转正机会,回学校准备论文。准备论文期间就也没有投递简历。然后时间来到了5月中旬,这时春招基本也结束了,然后我开始投递简历,期间只是约到了几家下场面试。工资也只有6-7k,到现在我不知道该怎么办了。已经没有当初学习的心劲了,好累呀,但是又不知道该干什么去。在家就是打游戏,boss简历投一投。每天日重一次。26秋招都说是针对26届的人,25怎么办。我好绝望。要不要参加考公、考研、央国企这些的。有没有大佬可以帮帮我。为什么感觉别人找工作都是顺其自然的事情,我感觉自己每一步都在艰难追赶。八股文背了又忘背了又忘,我每次都花很长时间去理解他,可是现在感觉八股、项目都忘完了。真的已经没有力气再去学习了。图片是我的简历,有没有大哥可以指正一下,或者说我应该走哪条路,有点不想在找工作了。
码客明:太累了就休息一下兄弟,人生不会完蛋的
如果实习可以转正,你会不...
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-16 12:18
点赞 评论 收藏
分享
评论
5
20
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务