Codeforces 124 E

K210视觉项目上位机避坑指南:解决C#解析ESP8266 TCP图像流的乱码、卡顿与连接中断 本文详细解析了K210与ESP8266在视觉项目中的上位机开发问题,重点解决TCP图像流解析中的乱码、卡顿与连接中断问题。通过自定义协议、JPEG流重组、TCP连接优化等实战技巧,提升系统稳定性和性能,适用于嵌入式视觉开发者和C#上位机程序员。 阅读详情

最小生成树的好题!

需要构造只包含k个点的图,但是如果暴力去搞必然超时,所以只加入有可能成为MST中的边的边,最后求一遍最小生成树

First of all, we can note that if each graph vertex is portal, the answer will be a sum of all edges' weights in MST (minimal spanning tree). We can find MST by using Kruskal's algo.

In this problem, not an every vertex is portal. Let's fix this.

Start with a precalculation. Run Dijkstra's algo from all the portals, simultaneously. We will get d[i] — a distance between vertex i and p[i] — the nearest portal to vertex i.

Let's trace Kruskal's algo on a graph of portals. On the first iteration, it will choose the edge with the minimal cost, i.e. a shortest path between all the portals in the original graph.

Let the path leads from portal x to portal y. Note that there exists a path with the same length such as p[i] changes only once through it. Indeed, p[x] = x, p[y] = y, i.e. p[i] changed on the path. If it happens on edge , p[i] = x, a path will not be longer than the path from x to y.

As p[i] = x and p[i] = y, we can see that the length of this path will be d[i] + w(i, j) + d[j], where w(i, j) is the weight of edge (i, j). Kruskal's algo will add this value to the answer and merge portals x and y. The shortest-path trees of vertexes x and y will also be merged.

Note, that almost nothing changed. The next edge for Kruskal's algo can be find in a similar way — . If this edge connects x and y again, DSU makes us not to count this edge, otherwise this edge connects a different pair of edges and will be counted in an answer.

We can easily implement this. Just create a new graph of portals, with an edge (p[i], p[j]) of weight d[i] + w(i, j) + d[j] for every edge (i, j) of weight w(i, j) from original graph and run Kruskal's algo.

Finally, note that if the starting vertex is not a portal, we shall add d[1] to the answer.


#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define N 100100
using namespace std;
int n,m;
int head[N],cnt;
bool ok[N],vis[N];
struct Edge{
    int u,v,next;
    long long w;
}edge[N*2];
long long dis[N];
int pre[N],fa[N];
queue<int>q;
void addedge(int u,int v,long long w){
    edge[cnt].u=u;
    edge[cnt].v=v;
    edge[cnt].w=w;
    edge[cnt].next=head[u];
    head[u]=cnt++;
    edge[cnt].u=v;
    edge[cnt].v=u;
    edge[cnt].w=w;
    edge[cnt].next=head[v];
    head[v]=cnt++;
}
void init(){
    memset(head,-1,sizeof(head));
    memset(vis,0,sizeof(vis));
    memset(ok,0,sizeof(ok));
    for(int i=1;i<=n;i++)
        fa[i]=i;
    cnt=0;
}
void SPFA(){
    int i,j;
    for(i=1;i<=n;i++)
        if(ok[i]){
            dis[i]=0;
            pre[i]=i;
            vis[i]=1;
            q.push(i);
        }
        else
            dis[i]=-1;
    while(!q.empty()){
        int u=q.front();
        q.pop();
        vis[u]=0;
        for(i=head[u];i!=-1;i=edge[i].next){
            int v=edge[i].v;
            if(dis[v]==-1 || dis[v]>dis[u]+edge[i].w){
                dis[v]=dis[u]+edge[i].w;
                pre[v]=pre[u];
                if(!vis[v]){
                    vis[v]=1;
                    q.push(v);
                }
            }
        }
    }
}
bool cmp(struct Edge a,struct Edge b){
    return a.w<b.w;
}
int find(int u){
    if(fa[u]==u)return u;
    return fa[u]=find(fa[u]);
}
int main(){
    int i,k;
    int u,v,w,tem;
    scanf("%d %d",&n,&m);
    init();
    for(i=1;i<=m;i++){
        scanf("%d %d %d",&u,&v,&w);
        addedge(u,v,(long long)w);
    }
    scanf("%d",&k);
    for(i=1;i<=k;i++){
        scanf("%d",&tem);
        ok[tem]=1;
    }
    SPFA();
    for(i=0;i<m*2;i++){
        edge[i].w+=(dis[edge[i].u]+dis[edge[i].v]);
        edge[i].u=pre[edge[i].u];
        edge[i].v=pre[edge[i].v];
    }
    sort(edge,edge+m*2,cmp);
    long long sum=0;
    for(i=0;i<m*2;i++){
        u=find(edge[i].u);
        v=find(edge[i].v);
        if(u!=v){
            fa[u]=v;
            sum+=edge[i].w;
        }
    }
    printf("%lld\n",sum+dis[1]);
    return 0;
}


2025高教社数学建模国赛A题 - 烟幕干扰弹的投放策略(完整参考论文) 摘要:本研究基于模拟遗传退火算法优化无人机投放烟幕弹策略,建立三维运动学模型分析遮蔽效果。针对不同战术场景(单机单弹至多机多弹),构建以遮蔽时间最大化为目标的非线性优化模型。通过改进遗传算法求解最优参数组合,结果显示在给定条件下单枚烟幕弹对M1导弹的有效遮蔽时长可达1.4秒。研究为无人机协同干扰提供了高效解决方案,验证了智能算法在复杂战术决策中的适用性。关键词:烟幕干扰;无人机投弹;运动学建模;时序优化;遗传算法。 阅读详情

相关推荐

告别切换烦恼!用Parallels Desktop的Host-Only网卡,在macOS上直接访问虚拟机里的公司内网

本文详细介绍了如何在macOS上使用Parallels Desktop的Host-Only网卡直接访问虚拟机内的公司内网,告别频繁切换操作系统的烦恼。通过配置Host-Only网络模式,实现主机与虚拟机的安全高效通信,特别适合需要频繁访问内网资源的IT从业者。文章包含分步指南、自动化脚本和常见问题解决方案,帮助用户优化工作流程。

weixin_28739079的博客 368

codeforces 197D Infinite Maze dfs

有一个无限的迷宫,由无数个n*m的小单元组成,类似于拼图,给定这个小单元,每个位置是空地或者障碍,再给定起点,问能否从起点走到无穷远的位置 刚开始的时候没有想清楚,实际上问题的本质在于,如果一个格子能从他相邻的两个不同的格子进入,那么一定可以走到无穷远的位置。 想明白这个就挺好写了,先从起点开始dfs,对于每个没有走到的位置标记是从哪个格子走到他的,然后如果从不同的格子走到了一个已经标

cadongllas的博客 678

【飞腾平台安装windows arm 11系统】

本文提供国内的百度网盘链接供下载使用:链接: https://pan.baidu.com/s/1_cftVdoX40k0M6zVTmFq8Q?3)快速迁移虚拟机技巧:如果是迁移已经安装好的虚拟机的使用场景,除了导出镜像外,也可直接复制安装好虚拟机的整个文件夹到指定的存储目录,选定好其中的任意qcow2文件后即可快速启动。可在飞腾软件平台点击网盘链接获取对应系统的deb包(麒麟和统信)以及phyvirt·app,下载地址:https://www.phytium.com.cn/developer/

firefly_cv的博客 9019

Codeforces- 124B-Permutations (深搜找全排列以及取出一个数的每一位)

Description You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rea

K键盘里的青春K 1471

智能客服系统知识库构建:长尾问题解决方案全解析

智能客服系统知识库构建:长尾问题解决方案全解析

嗨,欢迎来到我的 CSDN 博客小天地!一名深耕多年的技术发烧友。在这里,我将把日常工作中积累的宝贵经验,从复杂架构设计的精妙之处,到代码优化的实战技巧,毫无保留地分享给大家。 4126

文章详细介绍了进行DoIP(DiagnosticoverInternetProtocol)测试的完整过程,包括样件的正确接线、CANoe软件的环境配置、端口设置、VLAN配置、IP和MAC地址的设定

关于Tester和DUT的地址,其实最主要的就是DUT的IP、MAC和逻辑地址,如果不知道Tester的IP、MAC和逻辑地址,可以配置为与DUT同一网段的就可以。ps:最重的是知道DUT的IP、逻辑、MAC地址,如果有VLAN也需要知道,Tester的地址可以根据DUT地址进行设定,其余的值可根据DoIP的报文查到相关参数。ps:如果在通信中没有建立VLAN,但是源地址和目的地址都填写正确,此时就要考虑是否是遗漏了VLAN,建立一个VLAN,在重新试试是否可通信。此处与硬件连接是相对应的,要注意!

qq_40965861的博客 1140

Codeforces Round #124 (Div. 1) E. Opening Portals

cf

zstu_zy的博客 192

CODESYS V3.5 SP17编程环境全攻略:从安装到多语言编程实战

本文全面解析CODESYS V3.5 SP17编程环境,从安装配置到多语言编程实战技巧。详细介绍了运行时环境设置、六种IEC 61131-3语言的特性对比与混合编程策略,以及高级功能开发如自定义算法模块和实时通信配置。适合工业自动化工程师快速掌握这一强大工具。

weixin_30632089的博客 502

Educational Codeforces Round 124 (Rated for Div. 2) (A-D题解)

源代码:ACM/OpenjudgeNow/Codeforces at master · abmcar/ACM (github.com) 更好的阅读体验: 折跃坐标 A. Playoff 题目大意: 思路: 比较简单的数学思路 我们发现每轮会刷掉奇数位的选手 不难发现和证明 最终剩下的一定是$2^n-1 $ 代码: void solution() { cin >> n; cout << (1 << n) - 1 << endl; } B. P

Abmcar的博客 1327

五、2K0300 久久派开发板的GPIO控制与Shell脚本自动化实战

本文详细介绍了基于龙芯2K0300处理器的久久派开发板的GPIO控制方法,通过sysfs文件系统实现LED控制和传感器读取。重点讲解了Shell脚本自动化实战,包括LED闪烁、流水灯效果和传感器数据采集,为物联网项目开发提供完整解决方案。

silver的专栏 699

标题:Stata17安装后遇到Java安装问题解决方法

设置JAVA_HOME环境变量:在Windows上,您需要设置JAVA_HOME环境变量以告诉Stata Java的安装路径。d. 输入变量名为JAVA_HOME,变量值为Java安装路径。注意:请确保您的Java版本与Stata兼容,并使用正确的Java安装路径。设置Stata的Java安装路径:现在,您需要告诉Stata Java的安装路径。如果您看到Java版本信息,则表示Java已成功安装。如果没有安装,请先下载并安装Java。确认Java已安装:首先,请确保您的计算机上已经正确安装了Java。

CyberSparkZ的博客 2880

CodeForces 124B Permutations 枚举全排列

题目:https://cn.vjudge.net/problem/CodeForces-124B 题意:给出n个k位数,将每个数字的各个位置上的数重新排列,让重排后的数字极差最小,求极差。 注:(1)数字可以有前导零。 (2)重排时,所有数字按照相同规则重新排列。 (3)1 ≤ n, k ≤ 8 思路:既然重排时所有数字规则都相同,那么我们只需要枚举全排列作为重排的规则,在计算出每种重排...

Rewriter_huanying的博客 480

Deepseek Engram 论文全面解读

以下是对 DeepSeek 与北京大学于联合发布的论文《》(简称Engram 论文)的。

lpfasd123的博客 375

Educational Codeforces Round 124 补题题解 (前四题)

目录A PlayoffB Prove Him Wrong 比赛效果不错,在大佬的讲解下过了两道题,继续加油 比赛传送门 官方题解 A Playoff 简单思维 #include<bits/stdc++.h> using namespace std; #define int long long int dp[35]; void init() { dp[1] = 2; for(int i = 2; i <= 31; i ++ ){ dp[i] = dp[i - 1].

qiaodxs的博客 1373

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Codeforces Round #124 (Div. 2)

http://codeforces.com/contest/197 这次看到cf 九点多就开始了,很开心的注册下于是就悲剧了, A题,题目开始看错了,以为每次只能放一个盘子,想了半天博弈都没想出来,之后看到别人的代码才发现。先手肯定尽可能的放满整个桌子,这样后手就必败;如果先手一个盘子都放不了,那么先手就输了; B题   水题;分情况讨论; C题   贪心,从后向前扫描贪心,如果遇

态度决定高度 3039

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Educational Codeforces Round 124 (Rated for Div. 2)简训

Educational Codeforces Round 124 (Rated for Div. 2)简训 涉及的知识点:搜索,思维

C_eeking的博客 1122

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

[codeforces 1374E1] Reading Books (easy version) 巧妙配对

Codeforces Round #653 (Div. 3) 参与排名人数11687 [codeforces 1374E1] Reading Books (easy version) 巧妙配对 总目录详见https://blog.csdn.net/mrcrack/article/details/103564004 在线测评地址http://codeforces.com/contest/1374/problem/E1 Problem Lang Verdict Time...

mrcrack的博客 572

Educational Codeforces Round 124 (Rated for Div. 2)

Dashboard - Educational Codeforces Round 124 (Rated for Div. 2) - Codeforceshttps://codeforces.com/contest/1651 A. Playoff 签到题,第一轮以后剩下的都是奇数,奇数又取最大,答案就是2的n次方-1 #include<bits/stdc++.h> using namespace std; #define endl '\n' const int maxn = 0; co

m0_57221330的博客 291

Educational Codeforces Round 2 E.Lomsat gelral(树形dp)

从叶子节点向上更新控制颜色即可,但是必须用map映射而且要将小树合并到大树当中,否则会MLE

idealism_xxm的专栏 608

CodeForces - 600E Lomsat gelral (树上启发式合并)

Lomsat gelral You are given a rooted tree with root in vertex1. Each vertex is coloured in some colour. Let's call colourcdominating in the subtree of vertexvif there are no other colours th...

YOONGI 325

刷题之Educational Codeforces Round 124 (Rated for Div. 2)

文章目录刷题之Educational Codeforces Round 124 (Rated for Div. 2)1651A. Playoff1651B. Prove Him Wrong1651C. Fault-tolerant Network1651D. Nearest Excluded Points 刷题之Educational Codeforces Round 124 (Rated for Div. 2) 题单链接:Educational Codeforces Round 124 (Rated fo

xxayt的博客 474

CodeForces 124C【连通块】

思路: a素数->b合数 c素数->b合数 a,c属于一类 so,预处理相同的,并且计数。1000怎么搞都无压力; 我这里也预处理了字母个数,从集合大的枚举下来,每次拿字母个数最多的去匹配。 #include using namespace std; typedef long long LL; const int N=1e3+10; bool isprime(int x) {

ONE MORE TRY 713

【Codeforces】CF 600 E

#启发式合并 #树链剖分 #数据结构 #莫队

Antonio915的博客 1438

Codeforces 124c Lexicographically Maximum Subsequence

题意:输出给定字符串的字典序最大子串。 思路:统计所有出现过的字符,按字典序从大到小取,取完当前后取下一个,直到结尾。 #include #include #include using namespace std; int n,m,i,j,k,len; char a[500010]; int num[50],ch,shu; int main() { while(scanf("%

dominating的修行之路 840

Lomsat gelral CodeForces - 600E(树上启发式合并)

Lomsat gelral CodeForces - 600E You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let’s call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more t

黑大帅的博客 344

codeforces Codeforces Round #407 Div2题解 B,C,D,E

题目链接:about:http://codeforces.com/contest/789B仔细想一想,对于一个l r 区间的最大值,其实就是求一个最大连续子序列。不过这个地方有点特殊,区间都是以开头为正数的。然后正负正负。但仔细想想就会发现其实就只有两种情况:对于这整个差的绝对值得序列:1.正负正负…….2.负正负正……所以我们构造这样的两个序列,求这两个序列的最大子序列。 . Masha a

now_ing的博客 294
上一篇: ZOJ 3613
下一篇: HDU 4328
Benzema67
博客等级 码龄15年 120粉丝 357原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址