教育盘

 找回密码
 立即注册
快捷导航
发新帖

[初中数学] [百度云网盘]奥林匹克小丛书初中卷

  [复制链接]
 楼主| 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[idx] = b, ne[idx] = h[a], h[a] = 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[hand] != -1) ans += abs(pos[hand] - a);
        pos[hand] = 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[hand] != -1) ans += abs(pos[hand] - a);
        pos[hand] = 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[hand] != -1) ans += abs(pos[hand] - a);
        pos[hand] = a;
    }
    cout << ans << endl;
}
回复

使用道具 举报

megahauxVIP会员 永久VIP 发表于 2024-9-12 22:57:10
支持楼主发布,感谢ing,这个教程非常好
回复

使用道具 举报

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

强烈支持楼主ing…… 强烈支持楼主ing……
回复

使用道具 举报

发新帖
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|Q群563295900|教育盘 ( 鄂ICP备2021011568号 )

GMT+8, 2026-11-28 18:36 , Processed in 2.584297 second(s), 44 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表