9.16 美团笔试 4.06 / 5.00

T1 100%

cpp 复制代码
#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%

cpp 复制代码
#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%

cpp 复制代码
#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%

cpp 复制代码
#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%

只会骗了

cpp 复制代码
#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;
}
相关推荐
NAGNIP19 分钟前
Serverless 架构下的大模型框架落地实践
算法·架构
moonlifesudo25 分钟前
半开区间和开区间的两个二分模版
算法
moonlifesudo28 分钟前
300:最长递增子序列
算法
CoovallyAIHub5 小时前
港大&字节重磅发布DanceGRPO:突破视觉生成RLHF瓶颈,多项任务性能提升超180%!
深度学习·算法·计算机视觉
CoovallyAIHub6 小时前
英伟达ViPE重磅发布!解决3D感知难题,SLAM+深度学习完美融合(附带数据集下载地址)
深度学习·算法·计算机视觉
聚客AI1 天前
🙋‍♀️Transformer训练与推理全流程:从输入处理到输出生成
人工智能·算法·llm
大怪v1 天前
前端:人工智能?我也会啊!来个花活,😎😎😎“自动驾驶”整起!
前端·javascript·算法
惯导马工1 天前
【论文导读】ORB-SLAM3:An Accurate Open-Source Library for Visual, Visual-Inertial and
深度学习·算法
骑自行车的码农1 天前
【React用到的一些算法】游标和栈
算法·react.js
博笙困了1 天前
AcWing学习——双指针算法
c++·算法