2022“杭电杯”中国大学生算法设计超级联赛(4)个人记录

本文档涵盖从简单签到题的解决方案,到复杂问题如分段函数计算、线性基操作、区间动态规划和高效贪心算法的实例。深入解析了各类信息技术题目,适合算法爱好者和学习者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述在这里插入图片描述简单的签到题全部输出“NO”即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>P;
const ll maxn = 1e5 + 7;
const ll inf = 1e18 + 7;
const ll mod = 1e9 + 7;
ll t, n, x, k,m,from,to;
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--) {
        cin >> n;
        cout << "No\n";
    }
    return 0;
}

在这里插入图片描述在这里插入图片描述在这里插入图片描述签到题,分段函数,分类讨论。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>P;
const ll maxn = 1e5 + 7;
const ll inf = 1e18 + 7;
const ll mod = 1e9 + 7;
ll t, n, x, k,m,from,to;
struct node {
    ll l, r;
    friend bool operator<(node a, node b) {
        if (a.r == b.r)return a.l < b.l;
        else return a.r < b.r;
    }
};
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--) {
        cin >> n;
        ld ans1 = 0;
        ld ans2 = 0;
        for (int i = 0; i < n; i++) {
            cin >> x;
            //一种
            if (ans1 + x <= 100)ans1 += x;
            else if (ans1 + x > 100 && ans1 + x <= 200) {
                if (ans1 < 100)ans1 = 100 + (x - (100 - ans1)) * 0.8;
                else ans1 += x * 0.8;
            }
            else if (ans1 + x > 200) {
                if (ans1 < 100) {
                    ld temp =(x - (100 - ans1));
                    if (temp <= 125)ans1 = 100 + temp * 0.8;
                    else ans1 = 200 + (temp - 125) * 0.5;
                }
                else if (ans1 >= 100 && ans1 < 200) {
                    if (ans1 + x * 0.8 <= 200)ans1 = ans1 + x * 0.8;
                    else {
                        ans1 = 200 + (x - (200-ans1)*1.25) * 0.5;
                    }
                }
                else ans1 += x * 0.5;
            }
            //二种
            if (ans2 < 100)ans2 += x;
            else if (ans2 >= 100 && ans2 < 200)ans2 += x * 0.8;
            else ans2 += x * 0.5;
        }
        cout << fixed << setprecision(3) << ans1 << " " << ans2 << "\n";
    }
    return 0;
}

在这里插入图片描述在这里插入图片描述
在这里插入图片描述线性基模板题,稍微变化下。

#include <iostream>
#include <cstring>
#define ll long long
using namespace std;

struct Linebasis{
    ll p[65], b[65];
    int cnt;
    bool flag;
    void init(){
        memset(p, 0, sizeof p);
        memset(b, 0, sizeof b);
        cnt = 0;
        flag = false;
    }
    bool insert(ll x){
        for (int i = 62; i >= 0; i--){
            if((x >> i) & 1){
                if(!p[i]){
                    p[i] = x;
                    break;
                }
                x ^= p[i];
            }
        }
        if(x)
            cnt++;
        else
            flag = true;
        return x > 0;
    }
    ll querymax(ll x = 0){
        ll res = x;
        for (int i = 62; i >= 0; i--){
            if((res^p[i])>res)
                res ^= p[i];
        }
        return res;
    }
} base;

int t, n;
ll tmp;

int main(){
    cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while(t--){
        base.init();
        cin >> n;
        for (int i = 0; i<n; i++){
            cin >> tmp;
            base.insert(tmp);
        }
        cout << base.querymax() << endl;
    }
    return 0;
}

在这里插入图片描述在这里插入图片描述在这里插入图片描述区间dp。

//g[i][j]代表[i,j]区间合法的括号序列方案数(最终答案)
//f[i][j]代表(i,j)区间合法,i,j点上括号匹配的方案数
//g[i][j]+=g[i][k]+f[k+1][r];
//f[i][j]=g[i+1][j-1]*e%mod;
//e代表i,j两个位置能够配对的方案数。
//i=j=0时e=m,具有全部括号种类的配对方案数
//i=0||j=0||i+j=0时,只有一种配对方案
//其他情况不能组成配对
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll>P;
const ll maxn = 1e5 + 7;
const ll inf = 1e18 + 7;
const ll mod = 1e9 + 7;
ll t, n, x, k,m,from,to;
struct node {
    ll l, r;
    friend bool operator<(node a, node b) {
        if (a.r == b.r)return a.l < b.l;
        else return a.r < b.r;
    }
};
ll arr[510];
ll g[510][510], f[510][510];
void init() {
    for (int i = 0; i < 510; i++) {
        for (int j = 0; j < 510; j++) {
            g[i][j] = 0;
            f[i][j] = 0;
        }
        arr[i] = 0;
    }
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--) {
        init();
        cin >> n >> m;
        for (ll i = 1; i <= n; i++)cin >> arr[i];
        if (n & 1) {
            cout << 0 << "\n"; continue;
        }
        for (ll i = 0; i <= n; i++)g[i + 1][i] = 1;
        for (ll len = 2; len <= n; len += 2) {
            for (ll l = 1; l + len - 1 <= n; l++) {
                ll r = l + len - 1;
                ll e = 0;
                if (arr[l] >= 0 && arr[r] <= 0) {
                    if (arr[l] == 0 && arr[r] == 0)e = m;
                    else if (arr[l] == 0 || arr[r] == 0 || (arr[l] + arr[r] == 0))e = 1;
                    else e = 0;
                    f[l][r] = g[l + 1][r - 1] * e % mod;
                }
                for (ll k = l; k <= r; k+=2) {
                    g[l][r] =(g[l][r]+g[l][k-1]*f[k][r]) % mod;
                }
            }
        }
        cout << g[1][n] % mod << "\n";
    }
    return 0;
}

在这里插入图片描述在这里插入图片描述贪心,当时没想出来,下附jiangly大佬的代码OTZ(题解Ologn,大佬On线性!)
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值