9.16 美团笔试 4.06 / 5.00

T1 100%

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;

int n, a[N];

void solve() {
	cin >> n;
	for(int i = 0; i < n; i ++) cin >> a[i];

	int ans = a[0];
	for(int i = 1; i < n; i ++) {
		if(a[i] == 1) {
			ans ++ ;
			if(a[i - 1] == 1) ans ++ ;
		}
	}

	cout << ans << endl;
}

int main() {
	cin.tie(0); cout.tie(0);
	std::ios::sync_with_stdio(false);

	int T = 1;
//	cin >> T;
	while(T --) {
		solve();
	}

	return 0;
}

T2 100%

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;

void solve() {
	int x, y;
	cin >> x >> y;
	int r = ceil(sqrt(x * x + y * y));
	if(r == 0) r = 1;
	cout << max(11 - r, 0) << endl;
}

int main() {
	cin.tie(0); cout.tie(0);
	std::ios::sync_with_stdio(false);

	int T = 1;
//	cin >> T;
	while(T --) {
		solve();
	}

	return 0;
}

T3 100%

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1e3 + 10;

int n, H, A;
int h[N], a[N], ids[N];

void solve() {
	cin >> n >> H >> A;

	for(int i = 0; i < n; i ++) cin >> h[i];
	for(int i = 0; i < n; i ++) cin >> a[i];
	for(int i = 0; i < n; i ++) ids[i] = i;
	sort(ids, ids + n, [&](int a, int b){
		return h[a] < h[b];
	});

	int ed = -1;
	for(int i = 0; i < n; i ++) {
		int id = ids[i];
		if(h[id] >= H) break;
		ed = i;
	}

	if(ed == -1) cout << 0 << endl;
	else {
		vector<int> nums, f;
		for(int i = 0; i <= ed; i ++) {
			if(a[ids[i]] >= A) continue;
			nums.push_back(a[ids[i]]);
		}

		int ans = 0;
		f = vector<int> (nums.size());
		for(int i = 0; i < f.size(); i ++) {
			f[i] = 1;
			for(int j = 0; j < i; j ++) {
				if(nums[j] < nums[i]) f[i] = max(f[j] + 1, f[i]);
			}
			ans = max(ans, f[i]);
		}

		cout << ans << endl;
	}
}

int main() {
	cin.tie(0); cout.tie(0);
	std::ios::sync_with_stdio(false);

	int T = 1;
//	cin >> T;
	while(T --) {
		solve();
	}

	return 0;
}

T4 100%

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef long long LL;

const int N = 1e5 + 10;

int n, a[N];

int get(int x) {
	int ret = 0;
	while(x != 0 && x % 2 == 0) {
		x /= 2;
		ret ++ ;
	}
	return ret;
}

void solve() {
	cin >> n;
	for(int i = 0; i < n; i ++) cin >> a[i];

	sort(a, a + n);
	int ans = get(a[n - 1]), rec = a[n - 1];
	for(int i = n - 2; i >= 0; i --) {
		rec &= a[i];
		ans = max(ans, get(rec));
	}

	cout << ans << endl;
}

int main() {
	cin.tie(0); cout.tie(0);
	std::ios::sync_with_stdio(false);

	int T = 1;
//	cin >> T;
	while(T --) {
		solve();
	}

	return 0;
}

T5 6.67%

只会骗了

#include <bits/stdc++.h>

#define endl '\n'

using namespace std;

typedef long long LL;

const int N = 1e5 + 10, M = N * 2;

int n, m, C;
int h[N], e[M], ne[M], w[M], flag[M], num[M], idx;

LL total = 1e18;
vector<int> path, ans;

void add(int a, int b, int c, int f, int id) {
	e[idx] = b, w[idx] = c, flag[idx] = f;
	num[idx] = id,ne[idx] = h[a], h[a] = idx ++ ;
}

void dfs(int u, int p, LL sum, int rec, int vis) {
	if(sum > total) return ;
	if(vis == n) {
		if(rec == C && total > sum) {
			total = sum;
			ans = path;
		}
		return ;
	}

	for(int i = h[u]; i != -1; i = ne[i]) {
		int j = e[i];
		if(j == p) continue;
		if(flag[i] == 1) {
			path.push_back(num[i]);
			dfs(j, u, sum + 0ll + w[i], rec + 1, vis + 1);
		} else {
			path.push_back(num[i]);
			dfs(j, u, sum + 0ll + w[i], rec, vis + 1);
//			path.pop_back();
		}
	}
}

void solve() {
	cin >> n >> m;

	memset(h, -1, sizeof h);
	for(int i = 0; i < m; i ++) {
		int u, v, w, p;
		cin >> u >> v >> w >> p;
		add(u, v, w, p, i + 1);
		add(v, u, w, p, i + 1);
		if(p == 1) C ++ ;
	}

	cout << -1 << endl;

//	dfs(1, 0, 0, 0, 0);

//	if(ans.size() == 0) cout << -1 << endl;
//	else {
//		cout << ans.size() << endl;
//		for(int x : ans) cout << x << ' ';
//		cout << endl;
//	}
}

int main() {
	cin.tie(0); cout.tie(0);
	std::ios::sync_with_stdio(false);

	int T = 1;
//	cin >> T;
	while(T --) {
		solve();
	}

	return 0;
}
全部评论
第五题是Kruskal带上并查集,判断下图连通性就ok了
3 回复 分享
发布于 2023-09-16 20:59 新加坡
第五题直接打印-1也是6.67%
3 回复 分享
发布于 2023-09-16 20:49 江苏
第五题是克鲁斯卡尔最小生成树,配合并查集
1 回复 分享
发布于 2023-09-16 20:57 北京
t5 并查集
1 回复 分享
发布于 2023-09-16 20:57 四川
佬可以讲下第四题吗
点赞 回复 分享
发布于 2023-09-16 21:03 陕西
第一次做,请问佬,为什么做出来没有任何问题会显示什么数组越界或者其他问题?
点赞 回复 分享
发布于 2023-09-16 20:53 甘肃
佬三题是个什么思路
点赞 回复 分享
发布于 2023-09-16 20:51 重庆

相关推荐

就前几天旅游的时候,打开抖音就经常刷到这类视频:以前是高学历学生、老师、主持人,现在做着团播、擦边主播的工作,以及那些经过精心包装的“职业转型”故事——从铺天盖地的VLOG到所谓的“04年夜场工作日记”,这些内容在初中升学、高考放榜等关键时间节点持续发酵。可以说非常直接且精准地在潜移默化地影响着心智尚未成熟的青少年,使其对特殊行业逐渐脱敏。那我就想问了:某些传播公司、平台运营者甚至某些夜场的老板,你们究竟在传递怎样的价值观?点开那些视频,评论区里也是呈现明显的两极分化:一种是​​经济下行论​​:“现在就业市场已经艰难到这种程度了吗?”​​一种是事实反驳派​​:这些创作者往往拥有名校背景,从事着...
牛客刘北:被环境教育的,为了能拿到足够的钱养活自己,不甘心也得甘心,现在的短视频传播的思想的确很扭曲,但是很明显,互联网玩上一年你就能全款提A6,但你全心全意不吃不喝工作一年未必能提A6,但是在高考中考出现这个的确很扭曲,在向大家传播“不上学,玩互联网也可以轻松年入百万”,不是人变了,是社会在变
预测一下26届秋招形势
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
5
8
分享

创作者周榜

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