wszzx 发表于 2024-9-12 22:09:57


无回帖,不论坛,这才是人道。无回帖,不论坛,这才是人道。

wszzx 发表于 2024-9-12 22:11:56

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

typedef long long ll;

#define INF (ll) 1e+18

ll n;
ll x, dp0 = 0, dp1 = -INF, tmp;
//dp0 表示所有从前 i 个物品中选偶数个物品的最大价值
//dp1 表示所有从前 i 个物品中选奇数个物品的最大价值

int main(){
        scanf("%lld", &n);
       
        for (ll i = 0; i < n; i ++){
                scanf("%lld", &x);
                tmp = dp0;
                dp0 = max(dp1 + 2 * x, dp0);
                dp1 = max(tmp + x, dp1);
        }
       
        printf("%lld\n", max(dp0, dp1));
        return 0;
}

wssy 发表于 2024-9-12 22:12:57

感恩无私的分享与奉献 强烈支持楼主ing…… 强烈支持楼主ing……

wssy 发表于 2024-9-12 22:13:21

感恩无私的分享与奉献 强烈支持楼主ing…… 强烈支持楼主ing……

wssy 发表于 2024-9-12 22:21:54

感恩无私的分享与奉献 强烈支持楼主ing…… 强烈支持楼主ing……

wssy 发表于 2024-9-12 22:27:13

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

int a, b;

int main(){
        scanf("%d%d", &a, &b);
       
        if(a == b){
                printf("1\n");
                return 0;
        }
        if(abs(a - b) % 2 == 0){
                printf("3\n");
                return 0;
        }
        if(abs(a - b) % 2 == 1){
                printf("2\n");
                return 0;
        }
}

wssy 发表于 2024-9-12 22:29:46

        e = b, ne = h, h = idx ++;                           

wssy 发表于 2024-9-12 22:38:14

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> pos = {-1, -1};// 0: left, 1: right
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int a;
      char s;
      cin >> a >> s;
      int hand = (s == 'R');
      if (pos != -1) ans += abs(pos - a);
      pos = a;
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> pos = {-1, -1};// 0: left, 1: right
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int a;
      char s;
      cin >> a >> s;
      int hand = (s == 'R');
      if (pos != -1) ans += abs(pos - a);
      pos = a;
    }
    cout << ans << endl;
}
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> pos = {-1, -1};// 0: left, 1: right
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int a;
      char s;
      cin >> a >> s;
      int hand = (s == 'R');
      if (pos != -1) ans += abs(pos - a);
      pos = a;
    }
    cout << ans << endl;
}

megahaux 发表于 2024-9-12 22:57:10

支持楼主发布,感谢ing,这个教程非常好

gan816 发表于 2024-9-13 08:27:46


强烈支持楼主ing…… 强烈支持楼主ing……
页: 1 2 3 [4] 5 6 7 8
查看完整版本: [百度云网盘]奥林匹克小丛书初中卷