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;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值