CodeForces Round #553 Div2
A. Maxim and Biology
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; int N; string s; int minn = 0x3f3f3f3f; int main() { scanf("%d", &N); cin >> s; for(int i = 0; i <= N - 4; i ++) { int cnt = 0; for(int j = i; j < i + 4; j ++) { if(j == i) { if(s[j] == 'Z') cnt += 1; else cnt += min(s[j] - 'A', ('Z' - s[j] + 1)); } if(j == i + 1) cnt += min(abs(s[j] - 'C'), ('Z' - s[j] + 3)); if(j == i + 2) cnt += min(abs(s[j] - 'T'), (s[j] - 'A' + 7)); if(j == i + 3) cnt += min(abs(s[j] - 'G'), ('Z' - s[j] + 7)); } minn = min(minn, cnt); } printf("%d\n", minn); return 0; } /* 9 AAABBBCCC */
C. Problem for Nazar
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; long long l, r; long long sum(long long x) { if(x <= 0) return 0; int flag = 1; long long t = 1; long long sum1 = 0, sum2 = 0; for(long long i = 0; i < x; ) { long long nx = min(i + t, x); if(flag) sum1 += (nx - i); else sum2 += (nx - i); t *= 2; i = nx; flag ^= 1; } long long ans = sum2 % mod * ((sum2 + 1) % mod) % mod + sum1 % mod * (sum1 % mod) % mod; return ans % mod; } int main() { cin >> l >> r; cout << (sum(r) - sum(l - 1) + mod) % mod << endl; return 0; }
D. Stas and the Queue at the Buffet
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int N; struct Node { long long a; long long b; }node[maxn]; bool cmp(const Node &n, const Node &m) { return (n.a - n.b) > (m.a - m.b); } int main() { scanf("%d", &N); for(int i = 1; i <= N; i ++) cin >> node[i].a >> node[i].b; sort(node + 1, node + 1 + N, cmp); long long ans = 0; for(int i = 1; i <= N; i ++) ans += (node[i].a * (i - 1) + node[i].b * (N - i)); cout << ans << endl; return 0; }
E. Number of Components
代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int N; long long a[maxn]; int main() { scanf("%d", &N); for(int i = 1; i <= N; i ++) cin >> a[i]; long long ans = 0; for(int i = 1; i <= N; i ++) { if(a[i] > a[i - 1]) ans += (a[i] - a[i - 1]) * (N - a[i] + 1); else if(a[i] != a[i - 1]) ans += (a[i - 1] - a[i]) * a[i]; } cout << ans << endl; return 0; }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 用 C# 插值字符串处理器写一个 sscanf
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· DeepSeek 解答了困扰我五年的技术问题。时代确实变了!
· 本地部署DeepSeek后,没有好看的交互界面怎么行!
· 趁着过年的时候手搓了一个低代码框架
· 推荐一个DeepSeek 大模型的免费 API 项目!兼容OpenAI接口!