Trianglane
水题,只要分情况判断中间和两侧有边叠牢的情况,每次减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 ;
}
Symmetric 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 ;
}
Palindromic Poster
这个题挺好 构造题 第一遍没有想清楚
标签:int,题解,ans,long,2023,include,CCC From: https://www.cnblogs.com/lighthqg/p/17789129.html