欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > 2025牛客寒假算法基础集训营3个人补题ACEFLM

2025牛客寒假算法基础集训营3个人补题ACEFLM

2025/2/22 15:49:39 来源:https://blog.csdn.net/nobkin/article/details/145767560  浏览:    关键词:2025牛客寒假算法基础集训营3个人补题ACEFLM

A-智乃的博弈游戏_2025牛客寒假算法基础集训营3

思路:如果是奇数,取 n - 2个,然后1 - 1必赢,如果是偶数,取n - 3个,然后2 - 1必输

// Code Start Here	int n;cin >> n;if(n & 1)cout <<"Yes\n";else cout <<"No\n";

C-智乃的Notepad(Easy version)_2025牛客寒假算法基础集训营3

思路:观察到题目所给的含义,由于此题限制m = 1,查询区间为全体区间,很容易想到字典树来存储,然后跑一遍搜索。关键在于如何利用共享前缀来减少按键次数,以及如何通过退格符来进一步减少不必要的字符输入。

我们对于:

nowcoder

nowdays

now
三个单词的前缀部分共享,因此无需多次输入now,只需要

now - nowdays - now - nowcoder即可

共计 3 + 4 + 4 + 5 = 16次

dfs过程中记录一下最大深度即可

const int N = 1e6 + 5;struct Trie {int ch[N][30], cnt[N], idx = 0;map<char, int> mp;void init() {LL id = 0;for(char c = 'a'; c <= 'z'; c ++) mp[c] = ++ id;}void insert(string s) {int u = 0;for(int i = 0; i < s.size(); i ++) {int v = mp[s[i]];if(! ch[u][v]) ch[u][v] = ++ idx;u = ch[u][v];cnt[u] ++;}}LL ans = 0;int max_dep = 0;void dfs(int u, int cur_dep) {max_dep = max(max_dep, cur_dep);for(int i = 1; i < 27; i ++) {if(ch[u][i]) {ans ++;// cerr << char('a' + i - 1) << " ";dfs(ch[u][i], cur_dep + 1);ans ++;}}}
};
void solve(){int n, m;  cin >> n >> m;Trie tr;tr.init();for(int i = 0;i<n;i++){string s;cin >> s;tr.insert(s);}tr.dfs(0, 0);cout << tr.ans - tr.max_dep;
}

E-智乃的小球_2025牛客寒假算法基础集训营3

思路:一道物理题,观察到要求最大的最小值,二分即可,主要是中间的check有点复杂

    int n, k;cin >> n >> k;vector<int> R, L;for (int i = 0; i < n; ++i) {int p, v;cin >> p >> v;if (v == 1) R.push_back(p);else L.push_back(p);}sort(R.begin(), R.end());sort(L.begin(), L.end());int m = 0;for (auto p : R) {auto it = upper_bound(L.begin(), L.end(), p);m += L.end() - it;}if (m < k) return cout << "No" , 0;cout << "Yes\n";int Maxt = 0;int i = 0, j = L.size() - 1;while (i < R.size() && j >= 0) {if (R[i] < L[j]) {Maxt = max(Maxt, L[j] - R[i]);++ i;} else {-- j;}}int l = 0, r = Maxt;int ans = Maxt;while (l <= r) {int mid = l + r >> 1;int cnt = 0;int s = 0, e = 0;for (auto p : R) {int ql = p;int qr = p + mid;while (s < L.size() && L[s] < ql) ++s;while (e < L.size() && L[e] <= qr) ++e;cnt += e - s;}if (cnt >= k) {ans = mid;r = mid - 1;} else {l = mid + 1;}}cout << fixed << setprecision(6) << ans / 2.0;

F-智乃的捉迷藏_2025牛客寒假算法基础集训营3

思路:根据题意设不等式,借出来答案 >= n     <= 2n存在

int T;cin >> T;while (T--){int n, a, b, c;cin >> n >> a >> b >> c;if (n <= a + b + c && a + b + c <= 2 * n){cout << "Yes\n";} else{cout << "No\n";}}

L-智乃的三角遍历_2025牛客寒假算法基础集训营3

思路:手动模拟一下发现都有解,左下->右下->然后向上走一层,一层一层轮回正好可以

    int n; cin>>n;int tot = 0;for(int i=1;i<=n+1;++i){for(int j=1;j<=i;++j){a[i][j] = ++tot;}}cout<<"Yes\n";int st=1;for(int i=1;i<=n+1;++i,st^=1){if(st) for(int j=1;j<=i;++j) cout<<a[i][j]<<' ';else for(int j=i;j>=1;--j) cout<<a[i][j]<<' ';}for(int i=n;i>=1;--i,st^=1){if(st) {cout<<a[i][1]<<' ';for(int j=2;j<=i;++j) cout<<a[i+1][j]<<' '<<a[i][j]<<' ';}else{ for(int j=i;j>=2;--j) cout<<a[i][j]<<' '<<a[i+1][j]<<' ';cout<<a[i][1]<<' ';}}

M-智乃的牛题_2025牛客寒假算法基础集训营3

思路:模拟即可

    string s;cin >> s;map<char,int> mp;for(auto op : s){mp[op]++;}if(mp['c']>=1 &&mp['d']>=1 &&mp['e']>=1 &&mp['n']>=1 &&mp['o']>=2 &&mp['r']>=1 &&mp['w']>=1 ){cout <<"happy new year\n";}else cout <<"I AK IOI\n";

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词