寄寄寄寄寄寄寄寄寄寄寄寄寄寄寄寄寄寄|

TLE_Automation

园龄:2年9个月粉丝:19关注:23

AtCoder Beginner Contest 257 下分记录

A 题:

暴力拼串然后输出就行了。

string s;
signed main()
{
int n = read(), k = read();
for(int i = 1; i <= 26; i++) {
for(int j = 1; j <= n; j++) {
s += i + 'A' - 1;
}
}
cout << s[k - 1];
return 0;
}

B题:

比着题目模拟就行了。

int n, k, Q;
int a[N];
signed main()
{
n = read(), k = read(), Q = read();
for(int i = 1; i <= k; i++) a[i] = read();
for(int i = 1; i <= Q; i++) {
int x = read();
if(a[x] == n) continue;
if(a[x + 1] != a[x] + 1) a[x] = a[x] + 1;
}
for(int i = 1; i <= k; i++) cout << a[i] << " ";
return 0;
}

C 题:

我们设 qzh[i][0/1] 表示从 [1,i]0,1 个数。

然后做法就很显然了, 排序后就可以用前缀和来搞了。

时间复杂度 O(n)

int qzh[N][2], ans;
struct Node {
int w, male;
bool operator < (const Node &x) const {
return w < x.w;
}
}a[N];
signed main()
{
int n = read();
for(int i = 1; i <= n; i++) scanf("%1lld", &a[i].male);
for(int i = 1; i <= n; i++) scanf("%lld", &a[i].w);
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++) {
if(a[i].male == 1) qzh[i][1] = qzh[i - 1][1] + 1, qzh[i][0] = qzh[i - 1][0];
else qzh[i][1] = qzh[i - 1][1], qzh[i][0] = qzh[i - 1][0] + 1;
}
for(int i = 0; i <= n; i++) {
if(a[i].w == a[i + 1].w) continue;
ans = max(ans, qzh[i][0] + qzh[n][1] - qzh[i][1]);
}
cout << ans;
return 0;
}

本文作者:TLE_Automation

本文链接:https://www.cnblogs.com/tttttttle/p/16412522.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   TLE_Automation  阅读(31)  评论(5编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起