3.29携程笔试

记录一下,AK了,消消最近的霉运。

码风属于依托答辩,勿吐槽。

T1

// #define STRESS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstring>
#include <sstream>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef set<int> si;
typedef vector<int> vi;
typedef unsigned int uint;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#ifdef STRESS
#include <random>
#include <chrono>
mt19937 rr(chrono::system_clock::now().time_since_epoch().count());
ll r(ll L, ll R) {uniform_int_distribution<ll> dist(L, R); return dist(rr);}
#endif
#ifdef LOCAL
#include "DEBUG.cpp"
#else
#define dbg(...) { }
#endif
#define rep(i, a, n) for(int i = (a); i <= (n); ++i)
#define per(i, a, n) for(int i = (a); i >= (n); --i)
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define mst(a, b) memset((a), (b), sizeof(a));
#define all(x) (x).begin(),(x).end()
#define tem template<class T> inline
#define sz(v) ((int)(v).size())
#define linf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define space putchar(' ')
#define enter puts("")
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls u << 1
#define rs u << 1 | 1
#define lson u << 1, l, mid
#define rson u << 1 | 1, mid + 1, r
const pii dir[] = { {1, 0}, { -1, 0}, {0, 1}, {0, -1}};
const double pi = acos(-1.0);
const double eps = 1e-8;
const uint mod = 1e9 + 7;
inline ll qpow(ll a, ll b) {assert(b >= 0); ll r = 1; for(; b; b >>= 1) {if(b & 1) r = r * a % mod; a = a * a % mod;} return r;}
inline ll inv(const ll &x) {return qpow(x, mod - 2);}
tem bool chkmax(T &a, T b) {if(a < b) {a = b; return 1;} return 0;}
tem bool chkmin(T &a, T b) {if(a > b) {a = b; return 1;} return 0;}
tem int sgn(T x) {return x > eps ? 1 : (x < -eps ? -1 : 0);}
inline int msb(const ll &x) {return x ? 63 - __builtin_clzll(x) : -1;}
inline int lsb(const ll &x) {return x ? __builtin_ctzll(x) : 64;}
inline int popcnt(const ll &x) {return __builtin_popcountll(x);}
inline int p2(const ll &x) {return 1ll << x;}
inline int lowbit(const ll &x) {return x & -x;}
inline ll sq(const ll &x) {return x * x;}
const int N = 2e5 + 5;

int a[N];

void solve() {
	a[0] = a[6] = a[9] = 1;
	a[8] = 2;
	int ans =0;
	string s; cin >> s;
	for(auto c : s) {
		ans += a[c - '0'];
	}
	cout <<ans<<endl;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
#endif
	IOS; cout << fixed << setprecision(12);
	solve();
	return 0;
}

T2

// #define STRESS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstring>
#include <sstream>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef set<int> si;
typedef vector<int> vi;
typedef unsigned int uint;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#ifdef STRESS
#include <random>
#include <chrono>
mt19937 rr(chrono::system_clock::now().time_since_epoch().count());
ll r(ll L, ll R) {uniform_int_distribution<ll> dist(L, R); return dist(rr);}
#endif
#ifdef LOCAL
#include "DEBUG.cpp"
#else
#define dbg(...) { }
#endif
#define rep(i, a, n) for(int i = (a); i <= (n); ++i)
#define per(i, a, n) for(int i = (a); i >= (n); --i)
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define mst(a, b) memset((a), (b), sizeof(a));
#define all(x) (x).begin(),(x).end()
#define tem template<class T> inline
#define sz(v) ((int)(v).size())
#define linf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define space putchar(' ')
#define enter puts("")
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls u << 1
#define rs u << 1 | 1
#define lson u << 1, l, mid
#define rson u << 1 | 1, mid + 1, r
const pii dir[] = { {1, 0}, { -1, 0}, {0, 1}, {0, -1}};
const double pi = acos(-1.0);
const double eps = 1e-8;
const uint mod = 1e9 + 7;
inline ll qpow(ll a, ll b) {assert(b >= 0); ll r = 1; for(; b; b >>= 1) {if(b & 1) r = r * a % mod; a = a * a % mod;} return r;}
inline ll inv(const ll &x) {return qpow(x, mod - 2);}
tem bool chkmax(T &a, T b) {if(a < b) {a = b; return 1;} return 0;}
tem bool chkmin(T &a, T b) {if(a > b) {a = b; return 1;} return 0;}
tem int sgn(T x) {return x > eps ? 1 : (x < -eps ? -1 : 0);}
inline int msb(const ll &x) {return x ? 63 - __builtin_clzll(x) : -1;}
inline int lsb(const ll &x) {return x ? __builtin_ctzll(x) : 64;}
inline int popcnt(const ll &x) {return __builtin_popcountll(x);}
inline int p2(const ll &x) {return 1ll << x;}
inline int lowbit(const ll &x) {return x & -x;}
inline ll sq(const ll &x) {return x * x;}
const int N = 2e5 + 5;

int n, k, a[N];

void solve() {
	cin >> n >> k;
	--k;
	int i = 1;
	for(i = 1; i <= 2 * k; i += 2) {
		a[i] = i + 1;
		a[i + 1] = i;
	}
	rep(j, 1, i - 1) cout << a[j] << ' ';
	per(j, n, i) cout << j << ' ';
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
#endif
	IOS; cout << fixed << setprecision(12);
	solve();
	return 0;
}

T3

// #define STRESS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstring>
#include <sstream>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef set<int> si;
typedef vector<int> vi;
typedef unsigned int uint;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#ifdef STRESS
#include <random>
#include <chrono>
mt19937 rr(chrono::system_clock::now().time_since_epoch().count());
ll r(ll L, ll R) {uniform_int_distribution<ll> dist(L, R); return dist(rr);}
#endif
#ifdef LOCAL
#include "DEBUG.cpp"
#else
#define dbg(...) { }
#endif
#define rep(i, a, n) for(int i = (a); i <= (n); ++i)
#define per(i, a, n) for(int i = (a); i >= (n); --i)
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define mst(a, b) memset((a), (b), sizeof(a));
#define all(x) (x).begin(),(x).end()
#define tem template<class T> inline
#define sz(v) ((int)(v).size())
#define linf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define space putchar(' ')
#define enter puts("")
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls u << 1
#define rs u << 1 | 1
#define lson u << 1, l, mid
#define rson u << 1 | 1, mid + 1, r
const pii dir[] = { {1, 0}, { -1, 0}, {0, 1}, {0, -1}};
const double pi = acos(-1.0);
const double eps = 1e-8;
const uint mod = 1e9 + 7;
inline ll qpow(ll a, ll b) {assert(b >= 0); ll r = 1; for(; b; b >>= 1) {if(b & 1) r = r * a % mod; a = a * a % mod;} return r;}
inline ll inv(const ll &x) {return qpow(x, mod - 2);}
tem bool chkmax(T &a, T b) {if(a < b) {a = b; return 1;} return 0;}
tem bool chkmin(T &a, T b) {if(a > b) {a = b; return 1;} return 0;}
tem int sgn(T x) {return x > eps ? 1 : (x < -eps ? -1 : 0);}
inline int msb(const ll &x) {return x ? 63 - __builtin_clzll(x) : -1;}
inline int lsb(const ll &x) {return x ? __builtin_ctzll(x) : 64;}
inline int popcnt(const ll &x) {return __builtin_popcountll(x);}
inline int p2(const ll &x) {return 1ll << x;}
inline int lowbit(const ll &x) {return x & -x;}
inline ll sq(const ll &x) {return x * x;}
const int N = 2e5 + 5;
#define int ll

int n, a[N];
map<int, pair<int, int>> m;

int f(int x, int y) {
	return a[x] * y - y - n;
}

void solve() {
	cin >> n;
	m[n] = {1, 1};
	a[1] = 1;
	rep(i, 2, 12) a[i] = a[i - 1] * i;
	rep(x, 3, 12) {
		m[abs(f(x, 1))] = {x, 1};
		int l = 3, r = 1e9;
		while(l <= r) {
			m[abs(f(x, mid))] = {x, mid};
			m[abs(f(x, mid + 1))] = {x, mid + 1};
			if(mid - 1 >= 3) m[abs(f(x, mid - 1))] = {x, mid - 1};
			if(f(x, mid) > 0) r = mid - 1;
			else l = mid + 1;
		}
		//		cout << "x = " << x << ' ' << l << ' ' << r << endl;
		rep(i, max(3ll, l - 5), r + 5) m[abs(f(x, i))] = {x, i};
	}
	auto [x, y] = m.begin()->second;
	cout << x << ' ' << y << endl;
}

signed main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
#endif
	IOS; cout << fixed << setprecision(12);
	solve();
	return 0;
}

T4

// #define STRESS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <cstring>
#include <sstream>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef set<int> si;
typedef vector<int> vi;
typedef unsigned int uint;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#ifdef STRESS
#include <random>
#include <chrono>
mt19937 rr(chrono::system_clock::now().time_since_epoch().count());
ll r(ll L, ll R) {uniform_int_distribution<ll> dist(L, R); return dist(rr);}
#endif
#ifdef LOCAL
#include "DEBUG.cpp"
#else
#define dbg(...) { }
#endif
#define rep(i, a, n) for(int i = (a); i <= (n); ++i)
#define per(i, a, n) for(int i = (a); i >= (n); --i)
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define mst(a, b) memset((a), (b), sizeof(a));
#define all(x) (x).begin(),(x).end()
#define tem template<class T> inline
#define sz(v) ((int)(v).size())
#define linf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define space putchar(' ')
#define enter puts("")
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls u << 1
#define rs u << 1 | 1
#define lson u << 1, l, mid
#define rson u << 1 | 1, mid + 1, r
const pii dir[] = { {1, 0}, { -1, 0}, {0, 1}, {0, -1}};
const double pi = acos(-1.0);
const double eps = 1e-8;
const uint mod = 1e9 + 7;
inline ll qpow(ll a, ll b) {assert(b >= 0); ll r = 1; for(; b; b >>= 1) {if(b & 1) r = r * a % mod; a = a * a % mod;} return r;}
inline ll inv(const ll &x) {return qpow(x, mod - 2);}
tem bool chkmax(T &a, T b) {if(a < b) {a = b; return 1;} return 0;}
tem bool chkmin(T &a, T b) {if(a > b) {a = b; return 1;} return 0;}
tem int sgn(T x) {return x > eps ? 1 : (x < -eps ? -1 : 0);}
inline int msb(const ll &x) {return x ? 63 - __builtin_clzll(x) : -1;}
inline int lsb(const ll &x) {return x ? __builtin_ctzll(x) : 64;}
inline int popcnt(const ll &x) {return __builtin_popcountll(x);}
inline int p2(const ll &x) {return 1ll << x;}
inline int lowbit(const ll &x) {return x & -x;}
inline ll sq(const ll &x) {return x * x;}
const int N = 2e5 + 5;
#define int ll

int n, f[N][2];
vector<pair<int, int>> e[N];

void dfs(int u, int fa) {
	for(auto [v, w] : e[u]) {
		if(v == fa) continue;
		dfs(v, u);
	}
	for(auto [v, w] : e[u]) {
		if(v == fa) continue;
		f[u][0] += max(f[v][0], f[v][1]);
	}
	for(auto [v, w] : e[u]) {
		if(v == fa) continue;
		chkmax(f[u][1], f[u][0] - max(f[v][0], f[v][1]) + w + f[v][0]);
	}
}

void solve() {
	cin >> n;
	rep(i, 1, n - 1) {
		int u, v, w; cin >> u >> v >> w;
		e[u].pb({v, w});
		e[v].pb({u, w});
	}
	dfs(1, 0);
	cout << max(f[1][0], f[1][1]) << endl;
}

signed main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
#endif
	IOS; cout << fixed << setprecision(12);
	solve();
	return 0;
}

#携程#
全部评论
起手式是吧
2 回复 分享
发布于 2023-03-29 23:11 四川
熟悉的码风😂
1 回复 分享
发布于 2023-03-29 21:56 湖北
大佬在哪投的😢
1 回复 分享
发布于 2023-03-30 13:03 广东
此子恐怖如斯
1 回复 分享
发布于 2023-04-15 11:00 重庆
大佬可以说说第四题的思路吗
点赞 回复 分享
发布于 2023-03-29 21:11 江苏

相关推荐

03-13 21:15
江南大学 Java
多少分能进面啊?卡测评吗?做的我道心破碎了💔
小南瓜_66:A3 第四道题为什么用例过了 结果显示0%
投递携程等公司10个岗位 > 携程求职进展汇总
点赞 评论 收藏
分享
昨天 11:19
已编辑
门头沟学院 Java
已经一年没发牛客了,为什么呢,因为没脸发...&nbsp;一年前的我自认为在25届中技术一流,八股无敌,项目出色,但是一年校招的蹉跎让我差点转行。24年春招收割了十几个实习&nbsp;offer&nbsp;之后我去了某家大厂实习到9月份转正失败,那时候的我还没有意识到噩梦将来,7月因为投秋招提前批没反馈,于是开始投了几个实习转正岗位练手又拿了3个中大厂&nbsp;offer,这时的我沉浸在我自以为是的骄傲里。9月秋招正式批开始后我几乎把我能找到的所有的岗位都投了一遍,只收获了大厂海笔,0面试。10月份第一家给我面试的公司是数字马力(蚂蚁的内包),诚恳的说,当时收到这家面试是嚣张的,觉得我拿这个&nbsp;offer&nbsp;如探囊取物,就当个保底吧。...
中街牛奶提子:是啊,不应该在秋招的时候继续投实习岗。也劝26届的,八月末后,实习岗就不应该投,给人错误的行情认知。佬是学院本,觉得约面难,双非何尝不是一样呢,秋招战场的激烈和实习完全不同。当时我秋招的时候也是边面实习,当时面实习面一个过一个觉得自己很优越,觉得能收获一堆实习offer那秋招肯定也行。为什么要在秋招拿一堆实习offer增强自己所谓的虚荣心,当时就是贱,为了所谓的攀比虚荣心
点赞 评论 收藏
分享
评论
4
6
分享

创作者周榜

更多
牛客网
牛客企业服务