牛客周赛 Round 7
牛客周赛 Round 7
A-游游的you矩阵_牛客周赛 Round 7 (nowcoder.com)
把四种字符凑一起看看有没有\(y,o,u\)就行
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,m; cin >> n >> m; vector<string> a(n); for(auto &i : a) cin >> i; int ans = 0; for(int i = 1;i < n;i ++){ for(int j = 1;j < m;j ++){ string s = ""; s += a[i][j]; s += a[i][j - 1]; s += a[i - 1][j]; s += a[i - 1][j - 1]; if(s.find('y') != -1 && s.find('o') != -1 && s.find('u') != -1) ans ++; } } cout << ans << '\n'; return 0; }
B-游游的01串操作_牛客周赛 Round 7 (nowcoder.com)
\(dp[i][1/0]\)表示字符\(i\)为\(1/0\)时的最小代价
貌似直接讨论首位为\(1/0\)然后后面跟着算也能做出来
#include<bits/stdc++.h> using i64 = long long; using namespace std; typedef pair<i64, i64> PII; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; s = " " + s; int n = s.size(); vector dp(n, vector<int>(2,0)); for(int i = 1;i < n;i ++){ dp[i][0] = dp[i - 1][1] + i * (s[i] - '0'); dp[i][1] = dp[i - 1][0] + i * ('1' - s[i]); } cout << min(dp[n - 1][0],dp[n - 1][1]) << '\n'; return 0; }
C-游游的正整数_牛客周赛 Round 7 (nowcoder.com)
有解情况下,那最少情况下需要\(n\)个\(r\),最多情况下需要\(m\)个\(l\),如果说最少情况下的\(n\)都大于了最多情况下的\(m\),那么肯定无解
感觉更像是结论题,也可能数据水了(?)
#include<bits/stdc++.h> using i64 = long long; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int a,b,l,r; cin >> a >> b >> l >> r; int n = ceil((b - a) * 1.0 / r), m = (b - a) * 1.0 / l; if(n > m) cout << -1 << '\n'; else cout << n << ' ' << m << '\n'; } return 0; }
D-游游的选数乘积_牛客周赛 Round 7 (nowcoder.com)
两数相乘要使得末尾有\(0\),那就要看这两数的因子里能否凑出\(2\)和\(5\),只有凑出了\(2\)和\(5\),才能得出\(10\),才能使末尾有\(0\),所以我们每次把每个数的\(2\)和\(5\)因子数计算出来,然后去寻找是否存在使得这个数的\(2\)和\(5\)因子数和另一个数相加能得到大于或等于\(x\)的结果,能得到那我们就加\(1\),这里是用一个二维数组把拥有相同数量\(2\)和\(5\)因子的统计起来,且\(1e9\)里最多只有\(30\)个\(2\)和\(13\)个\(5\),所以我们只要三十多就行了
#include<bits/stdc++.h> using i64 = long long; using namespace std; typedef pair<i64, i64> PII; int sum[35][35]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,x; cin >> n >> x; i64 ans = 0; for(int i = 0;i < n;i ++){ int a; cin >> a; int num2 = 0, num5 = 0; while(a % 5 == 0) num5 ++, a /= 5; while(a % 2 == 0) num2 ++, a /= 2; for(int j = 0;j < 32;j ++) for(int k = 0;k < 32;k ++) if(num5 + k >= x && num2 + j >= x) ans += sum[j][k]; sum[num2][num5] ++; } cout << ans << '\n'; return 0; }
本文作者:Ke_scholar
本文链接:https://www.cnblogs.com/Kescholar/p/17629462.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
标签:
,
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步