Educational Codeforces Round 52

本文提供了四个不同问题的代码解决方案,包括贪心算法解决巧克力购买问题、图论问题中的孤立顶点计数、数组操作使元素相等及复杂路径规划问题。通过精心设计的数据结构和算法优化,实现了高效求解。

1065A - Vasya and Chocolate

贪心比较按照哪种买法最优然后全部按照最优买法买即可(有剩余就单独买)

solved

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map> 
#include <stack>
#include <sstream>
#include <set>
// #pragma GCC optimize(2)

//#define int long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define fi first
#define se second
//你冷静一点,确认思路再敲!!! 

using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int > PII;
priority_queue< PII, vector<PII>, greater<PII> > que;
stringstream ssin; //  ssin << string   while ( ssin >> int)
const ll LINF = 0x7fffffffffffffffll;

const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
ll _, s, a, b, c;

inline ll read() {
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
    return x*f;
}


int main()
{
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    _ = read();
    while (_--) {
        s = read(); a = read(); b = read(); c = read();
        if (1.0 * a * c / (a + b) < c) {
            ll tmp = s / c;
            ll ans = tmp / a * b + tmp;
            cout << ans << '\n';
        } else {
            cout << s / c << '\n';
        }
    }
    #ifndef ONLINE_JUDGE
        system("pause");
    #endif
}
View Code

1065B - Vasya and Isolated Vertices

本题求两问,对于第一问,显然让每天边都匹配两个点是最优的,那么直接输出max(0, n - 2 * m) 即可。

第二问可以直接枚举来得到。

solved

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map> 
#include <stack>
#include <sstream>
#include <set>
// #pragma GCC optimize(2)

//#define int long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define fi first
#define se second
//你冷静一点,确认思路再敲!!! 

using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int > PII;
priority_queue< PII, vector<PII>, greater<PII> > que;
stringstream ssin; //  ssin << string   while ( ssin >> int)
const ll LINF = 0x7fffffffffffffffll;

const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
ll n, m;
ll ans1, ans2;

inline ll read() {
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
    return x*f;
}

bool ck(ll mid) {
    ll nn = n - mid;
    if (nn < 0) return false;
    if (nn == 0) return true;
    
    if ((nn * (nn - 1)) / 2 >= m && nn <= 2 * m) return true;
    return false;
}

int main()
{
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    n = read(); m = read();
    ans1 = max(0ll, n - 2 * m);
    ll maxx = 0;
    for (ll i = 0; i <= n; ++i) {
        if (i == 0 && m == 0) {
            maxx = n;
            break;
        }
        if ((i * (i - 1) / 2 >= m && i <= 2 * m)) {
            maxx = n - i;
            break;
        }
    }
    ans2 = maxx;
    
    cout << ans1 << " " << ans2 << '\n';
    #ifndef ONLINE_JUDGE
        system("pause");
    #endif
}
View Code

1065C - Make It Equal

直接模拟即可

solved

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map> 
#include <stack>
#include <sstream>
#include <set>
// #pragma GCC optimize(2)

//#define int long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define fi first
#define se second
//你冷静一点,确认思路再敲!!! 

using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int > PII;
priority_queue< PII, vector<PII>, greater<PII> > que;
stringstream ssin; //  ssin << string   while ( ssin >> int)
const ll LINF = 0x7fffffffffffffffll;

const int N = 4e5 + 5, M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
ll n, k;
ll a[N];
map<ll, ll>ma;

inline ll read() {
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
    return x*f;
}

int main()
{
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    n = read(); k = read();
    ll Min = 1e18, Max = 0;
    for (int i = 1; i <= n; ++i) {
        a[i] = read();
        ma[a[i]]++;
        Min = min(Min, a[i]);
        Max = max(Max, a[i]);
    }
    
    bool flag = 0;
    ll ans = 1;
    ll now = Max;
    ll kk = k;
    while (now > Min) {
        if (kk >= ma[now]) {
            kk -= ma[now];
            flag = 1;
            now--;
            ma[now] += ma[now + 1];
        } else if (kk < ma[now]) {
            kk = k;
            ans++;
            continue;
        }
    }
    if (!flag) ans = 0;
    cout << ans << '\n';
    
    // #ifndef ONLINE_JUDGE
    //     system("pause");
    // #endif
}
View Code

D-Three Pieces

最短路+dp  dp[x][y][rep][3][pos] 表示再点(x, y)换了rep次棋后当前使用一个棋子且已经枚举完1-pos位置的最小值

因为是双关键字,可以考虑使用加阈值转化为单关键词或者直接在dp方程式中表示 

unsolved

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map> 
#include <stack>
#include <sstream>
#include <set>
// #pragma GCC optimize(2)

//#define int long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define rush() int T;scanf("%d",&T);for(int Ti=1;Ti<=T;++Ti)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int > PII;
priority_queue< PII, vector<PII>, greater<PII> > que;
stringstream ssin; //  ssin << string   while ( ssin >> int)
const ll LINF = 0x7fffffffffffffffll;

const int M = 4e5 + 5, mod = 1e9 + 7, INF = 0x3f3f3f3f;
int n, N;
int MAP[15][15];
int nx[8] = {-1, -2, -2, -1, 1, 2, 2, 1};
int ny[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
int dp[15][15][205][4][105];

inline ll read() {
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
    return x*f;
}

struct node {
    int x, y, cost, repl, now, num;
    bool operator<(const node &a) const {
        return cost > a.cost;
    }
//    friend bool operator < (node a,node b){
//        return a.cost > b.cost;
//    }
}s, e;

bool check(node u) {
    if (u.x >= 1 && u.x <= n && u.y >= 1 && u.y <= n && dp[u.x][u.y][u.repl][u.now][u.num] > u.cost)
        return true;
    return false;
}

bool ck(int x, int y) {
    if (x < 1 || x > n || y < 1 || y > n) return false;
    return true;
}

void solve() {
    priority_queue<node>q;        
    mm(dp, 0x3f);
    dp[s.x][s.y][0][0][1] = 0;
    dp[s.x][s.y][0][1][1] = 0;
    dp[s.x][s.y][0][2][1] = 0;
    
    q.push({s.x, s.y, 0, 0, 0, 1});
    q.push({s.x, s.y, 0, 0, 1, 1});
    q.push({s.x, s.y, 0, 0, 2, 1});
    
    while (!q.empty()) {
        node u = q.top();
        q.pop();
        if (dp[u.x][u.y][u.repl][u.now][u.num] < u.cost) continue;
        if (u.repl > 200) continue;
        node h;
        // 判断换子
        for (int i = 0; i < 3; ++i) {
            if (i == u.now) continue;
            h = u;
            h.repl++; h.now = i; h.cost++;
            if (!check(h)) continue;
            dp[h.x][h.y][h.repl][h.now][h.num] = h.cost;
            q.push(h);
        }
        
        if (u.now == 0) {  //骑士垂直走 
            for (int i = 1; i <= n; ++i) {
                if (u.x == i) continue;
                h = u;
                h.x = i; h.cost++;
                if (h.num + 1 == MAP[h.x][h.y]) h.num++;
                if (!check(h)) continue;
                dp[h.x][h.y][h.repl][h.now][h.num] = h.cost;
                q.push(h);
            }
            
            for (int i = 1; i <= n; ++i) {
                if (u.y == i) continue;
                h = u;
                h.y = i; h.cost++;
                if (h.num + 1 == MAP[h.x][h.y]) h.num++;
                if (!check(h)) continue;
                dp[h.x][h.y][h.repl][h.now][h.num] = h.cost;
                q.push(h);
            }
            
        } else if (u.now == 1) {   // 马走日字
        
            for (int i = 0; i < 8; ++i) {
                int xx = u.x + nx[i], yy = u.y + ny[i];
                if (xx < 1 || xx > n || yy < 1 || yy > n) continue;
                h = u;
                h.x = xx; h.y = yy; h.cost ++;
                if (h.num + 1 == MAP[h.x][h.y]) h.num++;
                if (!check(h)) continue;
                dp[h.x][h.y][h.repl][h.now][h.num] = h.cost;
                q.push(h);
            } 
            
        } else if (u.now == 2) {  // 象走斜线 
        
            for (int i = 1; i <= n; ++i) {   // -1, -1
                int xx = u.x + i * (-1), yy = u.y + i * (-1);
                if (!ck(xx, yy)) break;
                h = u;
                h.cost++; h.x = xx; h.y = yy;
                if (h.num + 1 == MAP[h.x][h.y]) h.num++;
                if (!check(h)) continue;
                dp[h.x][h.y][h.repl][h.now][h.num] = h.cost;
                q.push(h);
            }
            for (int i = 1; i <= n; ++i) {   //  -1, 1
                int xx = u.x + i * (-1), yy = u.y + i * 1;
                if (!ck(xx, yy)) break;
                h = u;
                h.cost++; h.x = xx; h.y = yy;
                if (h.num + 1 == MAP[h.x][h.y]) h.num++;
                if (!check(h)) continue;
                dp[h.x][h.y][h.repl][h.now][h.num] = h.cost;
                q.push(h);
            }
            for (int i = 1; i <= n; ++i) {     // 1, -1
                int xx = u.x + i * 1, yy = u.y + i * (-1);
                if (!ck(xx, yy)) break;
                h = u;
                h.cost++; h.x = xx; h.y = yy;
                if (h.num + 1 == MAP[h.x][h.y]) h.num++;
                if (!check(h)) continue;
                dp[h.x][h.y][h.repl][h.now][h.num] = h.cost;
                q.push(h);
            }
            for (int i = 1; i <= n; ++i) {   // 1, 1
                int xx = u.x + i * 1, yy = u.y + i * 1;
                if (!ck(xx, yy)) break;
                h = u;
                h.cost++; h.x = xx; h.y = yy;
                if (h.num + 1 == MAP[h.x][h.y]) h.num++;
                if (!check(h)) continue;
                dp[h.x][h.y][h.repl][h.now][h.num] = h.cost;
                q.push(h);
            }
        }
    }
    
    int Min = 1e9, u = 0;
    for (int i = 0; i <= 200; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (dp[e.x][e.y][i][j][n * n] < Min) {
                Min = dp[e.x][e.y][i][j][n * n];
                u = i;
            }
        }
    }
    
    printf("%d %d\n", Min, u);
}

int main()
{
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    n = read();
    N = n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            int x;
            x = read();
            MAP[i][j] = x;
            if (x == 1) {
                s.x = i; s.y = j;
            } else if (x == n * n) {
                e.x = i; e.y = j;
            }
        }
    }
    solve();
    
//    #ifndef ONLINE_JUDGE
//        system("pause");
//    #endif
}
View Code
内容概要:本文详细介绍了一种基于Simulink的表贴式永磁同步电机(SPMSM)有限控制集模型预测电流控制(FCS-MPCC)仿真系统。通过构建PMSM数学模型、坐标变换、MPC控制器、SVPWM调制等模块,实现了对电机定子电流的高精度跟踪控制,具备快速动态响应和低稳态误差的特点。文中提供了完整的仿真建模步骤、关键参数设置、核心MATLAB函数代码及仿真结果分析,涵盖转速、电流、转矩和三相电流波形,验证了MPC控制策略在动态性能、稳态精度和抗负载扰动方面的优越性,并提出了参数自整定、加权代价函数、模型预测转矩控制和弱磁扩速等优化方向。; 适合人群:自动化、电气工程及其相关专业本科生、研究生,以及从事电机控制算法研究与仿真的工程技术人员;具备一定的电机原理、自动控制理论和Simulink仿真基础者更佳; 使用场景及目标:①用于永磁同步电机模型预测控制的教学演示、课程设计或毕业设计项目;②作为电机先进控制算法(如MPC、MPTC)的仿真验证平台;③支撑科研中对控制性能优化(如动态响应、抗干扰能力)的研究需求; 阅读建议:建议读者结合Simulink环境动手搭建模型,深入理解各模块间的信号流向与控制逻辑,重点掌握预测模型构建、代价函数设计与开关状态选择机制,并可通过修改电机参数或控制策略进行拓展实验,以增强实践与创新能力。
根据原作 https://pan.quark.cn/s/23d6270309e5 的源码改编 湖北省黄石市2021年中考数学试卷所包含的知识点广泛涉及了中学数学的基础领域,涵盖了实数、科学记数法、分式方程、几何体的三视图、立体几何、概率统计以及代数方程等多个方面。 接下来将对每道试题所关联的知识点进行深入剖析:1. 实数与倒数的定义:该题目旨在检验学生对倒数概念的掌握程度,即一个数a的倒数表达为1/a,因此-7的倒数可表示为-1/7。 2. 科学记数法的运用:科学记数法是一种表示极大或极小数字的方法,其形式为a×10^n,其中1≤|a|<10,n为整数。 此题要求学生运用科学记数法表示一个天文单位的距离,将1.4960亿千米转换为1.4960×10^8千米。 3. 分式方程的求解方法:考察学生解决包含分母的方程的能力,题目要求找出满足方程3/(2x-1)=1的x值,需通过消除分母的方式转化为整式方程进行解答。 4. 三视图的辨认:该题目测试学生对于几何体三视图(主视图、左视图、俯视图)的认识,需要识别出具有两个相同视图而另一个不同的几何体。 5. 立体几何与表面积的计算:题目要求学生计算由直角三角形旋转形成的圆锥的表面积,要求学生对圆锥的底面积和侧面积公式有所了解并加以运用。 6. 统计学的基础概念:题目涉及众数、平均数、极差和中位数的定义,要求学生根据提供的数据信息选择恰当的统计量。 7. 方程的整数解求解:考察学生在实际问题中进行数学建模的能力,通过建立方程来计算在特定条件下帐篷的搭建方案数量。 8. 三角学的实际应用:题目通过在直角三角形中运用三角函数来求解特定线段的长度。 利用正弦定理求解AD的长度是解答该问题的关键。 9. 几何变换的应用:题目要求学生运用三角板的旋转来求解特定点的...
Python基于改进粒子群IPSO与LSTM的短期电力负荷预测研究内容概要:本文围绕“Python基于改进粒子群IPSO与LSTM的短期电力负荷预测研究”展开,提出了一种结合改进粒子群优化算法(IPSO)与长短期记忆网络(LSTM)的混合预测模型。通过IPSO算法优化LSTM网络的关键参数(如学习率、隐层节点数等),有效提升了模型在短期电力负荷预测中的精度与收敛速度。文中详细阐述了IPSO算法的改进策略(如引入自适应惯性权重、变异机制等),增强了全局搜索能力与避免早熟收敛,并利用实际电力负荷数据进行实验验证,结果表明该IPSO-LSTM模型相较于传统LSTM、PSO-LSTM等方法在预测准确性(如MAE、RMSE指标)方面表现更优。研究为电力系统调度、能源管理提供了高精度的负荷预测技术支持。; 适合人群:具备一定Python编程基础、熟悉基本机器学习算法的高校研究生、科研人员及电力系统相关领域的技术人员,尤其适合从事负荷预测、智能优化算法应用研究的专业人士。; 使用场景及目标:①应用于短期电力负荷预测,提升电网调度的精确性与稳定性;②为优化算法(如粒子群算法)与深度学习模型(如LSTM)的融合应用提供实践案例;③可用于学术研究、毕业论文复现或电力企业智能化改造的技术参考。; 阅读建议:建议读者结合文中提到的IPSO与LSTM原理进行理论学习,重点关注参数优化机制的设计思路,并动手复现实验部分,通过对比不同模型的预测结果加深理解。同时可拓展尝试将该方法应用于其他时序预测场景。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值