AI

gpt4free gpt12345 top
986edff49a09b869e883df619f0a3cdd3a93cb65
最大数列和

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int a[n+5];
int pre[n+5];//存储第i个数之前间隔一个相加 直到数组开头 的和的值
for(int i=1;i<=n;i++) {
cin>>a[i];
}
pre[0]=0;
pre[1]=a[1];
pre[2]=a[2];
for(int i=3;i<=n;i++) {
pre[i]=pre[i-2]+a[i];
}
int k;
cin>>k;
int ans=-1e18;
for(int i=1;i<=n;i++) {
if(i+2*k>n) break;
ans=max(ans,pre[i+(2*k-2)]-pre[i-2]);
}
cout<<ans<<endl;
return 0;
}

好日期

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <bits/stdc++.h>
using namespace std;
//鍒ゆ柇涓€骞存槸鍚︿负闂板勾 涓洪棸骞村垯2鏈堟湁29澶?骞冲勾鍒欏彧鏈?8澶?
bool isLeapYear(int year) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
return true;
} else {
return false;
}
}
//鍒ゆ柇涓€涓湀鏈夋病鏈夌31澶?
bool check(int month) {
int a[7]={1,3,5,7,8,10,12};
for(int i=0;i<7;i++) {
if(month == a[i]) {
return true;//鏈?1tian
}
}
return false;//30天
}
int main() {
int ans=0;
//1901 1 1鏄槦鏈熶簩 k=2;
int k=2;//k=(k+10)%7
for(int i=1901;i<=2024;i++) {
bool isLeap=isLeapYear(i);
for(int j=1;j<=12;j++) {
if(check(j)) {
//31澶?
//1鍙?
if(k==1) ans++;
//11鍙?
k=(k+10)%7;
if(k==1) ans++;
//21鍙?
k=(k+10)%7;
if(k==1) ans++;
//31鍙?
k=(k+10)%7;
if(k==1) ans++;
//涓轰笅涓湀鐨勭涓€澶╅摵璺?
k=(k+1)%7;
}
else {
//30澶?
if(j!=2) {
//1鍙?
if(k==1) ans++;
//11鍙?
k=(k+10)%7;
if(k==1) ans++;
//21鍙?
k=(k+10)%7;
if(k==1) ans++;
//涓轰笅涓湀绗竴澶╅摵璺?
k=(k+10)%7;
}
else if(j==2) {
//1鍙?
if(k==1) ans++;
//11鍙?
k=(k+10)%7;
if(k==1) ans++;
//21鍙?
k=(k+10)%7;
if(k==1) ans++;
if(isLeap) {
k=(k+9)%7;
}
else {
k=(k+8)%7;
}
}
}
}
}
cout<<ans<<endl;
return 0;
}

最长对勾

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int longestVSequence(const vector<int>& a) {
int n = a.size();
vector<int> inc(n, 1); // 递增子序列长度
vector<int> dec(n, 1); // 递减子序列长度

// 计算递增子序列长度
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (a[j] < a[i]) {
inc[i] = max(inc[i], inc[j] + 1);
}
}
}

// 计算递减子序列长度
for (int i = n - 1; i >= 0; --i) {
for (int j = i + 1; j < n; ++j) {
if (a[j] < a[i]) {
dec[i] = max(dec[i], dec[j] + 1);
}
}
}

// 找到最长的“凹”形子序列
int max_length = 0;
for (int i = 0; i < n; ++i) {
if (inc[i] > 1 && dec[i] > 1) { // 必须有严格递增和严格递减部分
max_length = max(max_length, inc[i] + dec[i] - 1);
}
}

return max_length;
}

int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}

cout << longestVSequence(a) << endl;
return 0;
}
[视频内嵌代码]