牛客周赛49
比赛链接:牛客周赛49
赛时感受
A
思路
直接计算
代码
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 10; int main() { ll a, b; cin >> a >> b; cout << a - b * 11 << endl; return 0; }
B
思路
可以发现5可以分为2和3,2和3继续分裂的使得血量为2的史莱姆和血量为3的史莱姆使用的魔法轮数所以相等,继续得出使得血量为奇数x和血量偶数x+1的史莱姆死亡使用的魔法轮数相等。所以只需要记录每轮使用了多少次魔法,把每轮使用的魔法次数相加就是结果了。
代码
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 10; int main() { ll h, num = 0, now = 1; cin >> h; while (h) { h /= 2; num *= 2; num += now; } cout << num << endl; return 0 ; }
C
思路
典题,最大连续子序列,把数组的每个元素都减去x,然后就可以发现是求最大连续子序列。
代码
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 10; ll a[N]; int main() { ll n, x; cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] -= x; } ll now = 0, num = 0; for (int i = 1; i <= n; i++) { now += a[i]; if (now < 0) { now = 0; } if (num <= now) { num = now; } } cout << num << endl; return 0 ; }
D
思路
代码
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 10; ll a[N]; ll cal(ll x) { if (x % 4 == 0) { return x; } else if (x % 4 == 1) { return 1; } else if (x % 4 == 2) { return x + 1; } else { return 0; } } void solve() { ll l, r, res = 0; cin >> l >> r; cout << (cal(l - 1) ^ cal(r)) << endl; } int main() { int t; cin >> t; while (t--) { solve(); } return 0 ; }
E
思路
简单数学函数交点问题,转换一下就是求二元一次方程的解的个数,但是会卡long long,需要使用double或者__int128,同时考虑x^2的系数为0的时候就是两条直线的交点问题,判断是否重合,重合就是无数个交点,否则没有交点。
代码
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = 1e5 + 10; ll a1, b1, c1, a2, b2, c2; __int128 x, y, z; void solve() { cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; x = a1 * b2, y = b1 * b2 + a2, z = c1 * b2 + c2; if (x != 0) { if ((y * y - 4 * x * z) < 0) { cout << 0 << endl; } else if ((y * y - 4 * x * z) == 0) { cout << 1 << endl; } else { cout << 2 << endl; } } else { if (y == 0 && z == 0) { cout << "INF" << endl; } else if (y == 0) { cout << 0 << endl; } else { cout << 1 << endl; } } } int main() { ll t; cin >> t; while (t--) { solve(); } return 0; }
F
思路
代码
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现