BZOJ 1455 罗马游戏

本文介绍了一道关于可并堆的编程题目,并通过使用GNU C++ PBDS库实现了一个解决方案。文中详细展示了如何利用pairing heap进行元素操作,包括插入、删除及合并等,适用于需要高效处理数据集合的场景。

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

可并堆的裸题,pbds练手用。

#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;
typedef __gnu_pbds::priority_queue <int, greater<int>, pairing_heap_tag> Heap;
erase(iterator) 根据迭代器删除元素
modify(iterator, val) 根据迭代器修改值
join(other), 使用之后另一个会被清空
其他同STL
#define others
#ifdef poj
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#endif // poj
#ifdef others
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/priority_queue.hpp>
#endif // others
//#define file
#define all(x) x.begin(), x.end()
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define eps 1e-8
const double pi = acos(-1.0);

typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
void umax(int &a, int b) {
    a = max(a, b);
}
void umin(int &a, int b) {
    a = min(a, b);
}
int dcmp(double x) {
    return fabs(x) <= eps?0:(x > 0?1:-1);
}
void file() {
    freopen("data_in.txt", "r", stdin);
    freopen("data_out.txt", "w", stdout);
}
const LL mod = 1e9+7;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

namespace solver {
/*
#include <ext/pb_ds/priority_queue.hpp>
using namespace __gnu_pbds;

*/
    const int maxn = 1100000;
    struct A {
        int val;
        int id;
        bool operator < (const A & b) const {
            return val > b.val || (val == b.val && id > b.id);
        }
    };
    typedef __gnu_pbds::priority_queue <A> Heap;
    Heap heap[maxn];
    int fa[maxn];
    int find(int x) {
        return x == fa[x]?x:fa[x] = find(fa[x]);
    }
    int vis[maxn];
    void solve() {
        int n, m;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            int v;
            cin >> v;
            heap[i].push({v, i});
            fa[i] = i;
        }
        cin >> m;
        for (int i = 1; i <= m; i++) {
            string str;
            cin >> str;
            if (str[0] == 'M') {
                int x, y;
                cin >> x >> y;
                if(vis[x] || vis[y]) continue;
                x = find(x);
                y = find(y);
                if(x != y) {
                    fa[x] = y;
                    heap[y].join(heap[x]);
                }
            } else {
                int x;
                cin >> x;
                if(vis[x]) {
                    cout << 0 << '\n';
                    continue;
                }
                x = find(x);
                A buf = heap[x].top();
                cout << buf.val << '\n';
                heap[x].pop();
                vis[buf.id] = 1;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
//    file();
    solver::solve();
    return 0;
}

/*
1,2,4,6,9,13,17,21,26,32,38,45,53,61,69,77,86,96,106,117,129,141,153,166,180,194,209,225,241,257,273,
*/
内容概要:本文探讨了在MATLAB/SimuLink环境中进行三相STATCOM(静态同步补偿器)无功补偿的技术方法及其仿真过程。首先介绍了STATCOM作为无功功率补偿装置的工作原理,即通过调节交流电压的幅值和相位来实现对无功功率的有效管理。接着详细描述了在MATLAB/SimuLink平台下构建三相STATCOM仿真模型的具体步骤,包括创建新模型、添加电源和负载、搭建主电路、加入控制模块以及完成整个电路的连接。然后阐述了如何通过对STATCOM输出电压和电流的精确调控达到无功补偿的目的,展示了具体的仿真结果分析方法,如读取仿真数据、提取关键参数、绘制无功功率变化曲线等。最后指出,这种技术可以显著提升电力系统的稳定性与电能质量,展望了STATCOM在未来的发展潜力。 适合人群:电气工程专业学生、从事电力系统相关工作的技术人员、希望深入了解无功补偿技术的研究人员。 使用场景及目标:适用于想要掌握MATLAB/SimuLink软件操作技能的人群,特别是那些专注于电力电子领域的从业者;旨在帮助他们学会建立复杂的电力系统仿真模型,以便更好地理解STATCOM的工作机制,进而优化实际项目中的无功补偿方案。 其他说明:文中提供的实例代码可以帮助读者直观地了解如何从零开始构建一个完整的三相STATCOM仿真环境,通过图形化的方式展示无功补偿的效果,便于进一步的学习与研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值