CCC 2023 题解 和 思考过程

1|0Trianglane


水题,只要分情况判断中间和两侧有边叠牢的情况,每次减2

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std ;
typedef long long ll ;
const int N = 200010 ;
int n, ans ;
int a[N], b[N] ;
int main() {
scanf("%d", &n) ;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ans += a[i] ;
for (int i = 1; i <= n; i++) scanf("%d", &b[i]), ans += b[i] ;
ans *= 3 ;
for (int i = 1; i < n; i++) if (a[i] == 1 && a[i + 1] == 1) ans -= 2 ;
for (int i = 1; i < n; i++) if (b[i] == 1 && b[i + 1] == 1) ans -= 2 ;
for (int i = 1; i <= n; i++)
if (i % 2 == 1 && a[i] == 1 && b[i] == 1) ans -= 2 ;
printf("%d\n", ans) ;
system("pause") ;
return 0 ;
}

2|0Symmetric Mountains


这题也不难,就利用对称性。
对于奇数长的段枚举中点,向两边扩展
对于偶数段的就枚举中间两个点

错了1次 没考虑 n=1 的情况 但考试无限次测评 没关系

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std ;
typedef long long ll ;
const int N = 5010 ;
int n ;
int a[N], ans[N] ;
int main() {
scanf("%d", &n) ;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]) ;
memset(ans, 0x3f, sizeof(ans)) ;
for (int i = 1; i <= n; i++) {
int l = i, r = i, tot = 0 ;
while (1 <= l && r <= n) {
tot += abs(a[l] - a[r]) ;
ans[r - l + 1] = min(ans[r - l + 1], tot) ;
l-- ; r++ ;
}
l = i, r = i + 1, tot = 0 ;
while (1 <= l && r <= n) {
tot += abs(a[l] - a[r]) ;
ans[r - l + 1] = min(ans[r - l + 1], tot) ;
l--, r++ ;
}
}
for (int i = 1; i <= n; i++) printf("%d ", ans[i]) ;
system("pause") ;
return 0 ;
}

3|0Palindromic Poster


这个题挺好 构造题 第一遍没有想清楚


__EOF__

作  者哈奇莱特
出  处https://www.cnblogs.com/lighthqg/p/17789129.html
关于博主:这个人很懒 什么也没有留下
版权声明:未获得本人同意请勿随意转载
声援博主:制作不易 点个赞吧

posted @   哈奇莱特  阅读(79)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
0
0
关注
跳至底部
点击右上角即可分享
微信分享提示