zoj 3811 Untrusted Patrol 牡丹江网络赛c题

本文探讨了一种复杂环境下仓库安全管理的问题,通过引入安全巡逻机制和传感器技术,确保所有库存得到有效检查。利用链式邻接表数据结构解决路径连通性和巡逻路径验证,确保每项物资都得到适当关注。
Untrusted Patrol

Time Limit: 3 Seconds      Memory Limit: 65536 KB

Edward is a rich man. He owns a large factory for health drink production. As a matter of course, there is a large warehouse in the factory.

To ensure the safety of drinks, Edward hired a security man to patrol the warehouse. The warehouse has N piles of drinks and M passageways connected them (warehouse is not big enough). When the evening comes, the security man will start to patrol the warehouse following a path to check all piles of drinks.

Unfortunately, Edward is a suspicious man, so he sets sensors on K piles of the drinks. When the security man comes to check the drinks, the sensor will record a message. Because of the memory limit, the sensors can only record for the first time of the security man's visit.

After a peaceful evening, Edward gathered all messages ordered by recording time. He wants to know whether is possible that the security man has checked all piles of drinks. Can you help him?

The security man may start to patrol at any piles of drinks. It is guaranteed that the sensors work properly. However, Edward thinks the security man may not works as expected. For example, he may digs through walls, climb over piles, use some black magic to teleport to anywhere and so on.

Input

There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:

The first line contains three integers N (1 <= N <= 100000), M (1 <= M <= 200000) and K (1 <= K <= N).

The next line contains K distinct integers indicating the indexes of piles (1-based) that have sensors installed. The following M lines, each line contains two integers Ai and Bi (1 <= AiBi <=N) which indicates a bidirectional passageway connects piles Ai and Bi.

Then, there is an integer L (1 <= L <= K) indicating the number of messages gathered from all sensors. The next line contains L distinct integers. These are the indexes of piles where the messages came from (each is among the K integers above), ordered by recording time.

Output

For each test case, output "Yes" if the security man worked normally and has checked all piles of drinks, or "No" if not.

Sample Input
2
5 5 3
1 2 4
1 2
2 3
3 1
1 4
4 5
3
4 2 1
5 5 3
1 2 4
1 2
2 3
3 1
1 4
4 5
3
4 1 2
Sample Output
No
Yes



题意是有n个仓库,其中m个装了传感器,可以得到保安到达此仓库的信息,给出了各个仓库之间的连接关系,从一个仓库只能到有路径相连的仓库。
给出传感器记录的顺序,判断保安是否按照所给路径巡逻(即没有跨越两个没有路径相连的仓库)。
这题主要是学到了链式邻接表,比邻接矩阵可以存储更多的点和边。

代码:

#include<stdio.h>
#include<string.h>
#define N 100005
#define M 400005

int ts[N],vis[N];//ts用来记录此点是否有传感器,vis标记是否访问过此点
int p[M],q[M],next[M],first[M],kk[M];//邻接表的各个数组,p、q表示一个边的两个点,first表示与此点链接的上一条边,next表示与此边相邻的下一条边
int cnt,counts;//记录访问的边数和点数

void dfs(int u)//搜索
{
    int e,v;

    e=first[u];//从给出的u点的第一条边开始搜索
    while(e!=0)
    {
        v=q[e];//第一条边的起点
        //printf("dfs%d\t\t%d\t\n",e,v);
        if(vis[v]==0)
        {
            vis[v]=1;
            if(ts[v]==1)//如果有传感器信息
            {
                cnt++;//边数++
                counts++;//带传感器的点数++
                ts[v]=0;//取消标记传感器
            }
            else
            {
                cnt++;//边数++
                dfs(v);//深度搜索相连的下一条边
            }
        }
        e=next[e];//下一条边
    }
}

int main()
{
    int v,u,i,e,m,T,n,k,l;

    scanf("%d",&T);
    while(T--)
    {
        int x;
        memset(first,0,sizeof(first));
        memset(ts,0,sizeof(ts));
        memset(vis,0,sizeof(vis));
        //memset(next,0,sizeof(next));
        scanf("%d%d%d",&n,&m,&k);
        for(i=0;i<k;i++)
        {
            scanf("%d",&x);
            ts[x]=1;//将带传感器的标记
        }
        for(i=1;i<=m;i++)//构造邻接表,边数为m,则用i和i+m存放相反的两条边,即为没有方向
        {
            scanf("%d%d",&u,&v);
            p[i+m]=q[i]=v;
            q[i+m]=p[i]=u;
            next[i]=first[u];
            first[u]=i;
            next[i+m]=first[v];
            first[v]=i+m;
        }
        scanf("%d",&l);
        for(i=0;i<l;i++)
            scanf("%d",&kk[i]);
        if(l<k)printf("No\n");//记录到达信息不全,肯定是没有全走完
        else
        {
            ts[kk[0]]=0;//把第一个到的有传感器的点搞成0
            vis[kk[0]]=1;
            for(i=0,counts=1,cnt=1;i<l;i++)//从第一个由传感器检测到的点开始搜索
            {
                if(ts[kk[i]]==1)//如果有没搜索到的有传感器的点即跳出
                    break;
                dfs(kk[i]);
            }
            //printf("%d  %d\n",counts,cnt);
            if(counts==l&&cnt==n)//如果搜索的边数==n并且点数等于传感器记录的点数就yes
                printf("Yes\n");
            else printf("No\n");
        }
    }
}


内容概要:本文系统介绍了基于二维离散时间卡尔曼滤波器的目标跟踪技术,重点研究了在二维平面动态环境中,受不同噪声强度影响下的目标运动状态估计与轨迹预测方法。通过构建目标运动的状态空间模型,利用卡尔曼滤波算法对含有噪声的测量数据进行递归处理,有效实现了对目标位置与速度的最优估计,显著提升了复杂噪声环境下的跟踪精度与系统鲁棒性。文中配套提供了完整的Matlab仿真代码,便于读者复现算法流程并开展参数调优实验,尤其针对过程噪声与测量噪声协方差的设置进行了对比分析,揭示其对滤波性能的关键影响。; 适合人群:具备信号处理、控制理论或导航制导基础知识,熟悉Matlab编程环境,从事自动化、电子工程、航空航天及相关领域的研究生、科研人员或工程技术人员。; 使用场景及目标:①应用于无人机、机器人、雷达系统等需要实时精确目标跟踪的场景;②帮助理解卡尔曼滤波器的核心原理及其在实际工程问中的建模与实现方式;③通过调整噪声参数研究滤波器收敛性、稳定性和跟踪误差的变化规律,进而优化系统设计;④为后续研究扩展至非线性滤波(如EKF、UKF)或多传感器融合提供基础支撑。; 阅读建议:建议读者结合文中的Matlab代码进行仿真实践,主动修改系统噪声和观测噪声参数,观察滤波轨迹与真实轨迹的偏差变化,深入掌握卡尔曼增益的动态调节机制与“预测-更新”循环的工作原理。同时推荐关注公众号“荔枝科研社”获取更多技术资料与代码资源支持。
内容概要:本文系统介绍了2024年最新提出的两种智能优化算法——青蒿素优化算法与霜冰优化算法(RIME),并通过Matlab代码实现对二者进行了深入对比研究。文档不仅阐述了两种算法的核心原理与数学模型,还全面展示了其在电力系统优化、新能源调度、路径规划、机器学习参数调优等复杂工程问中的应用性能差异。文中涵盖了微电网调度、电动汽车充电优化、无人机三维路径规划、风光互补制氢系统调度等多个前沿科研方向的典型案例,并配套提供了完整的Matlab仿真代码与模型资源,便于读者复现高水平学术论文成果并开展创新性研究。; 适合人群:具备一定编程基础,熟练掌握Matlab/Simulink环境,正在从事智能优化算法相关研究的研究生、高校教师及工程技术人员,尤其适用于专注于能源系统优化、智能交通、智能制造、自动化控制等领域的科研工作者。; 使用场景及目标:①深入理解青蒿素算法与RIME算法的基本思想、迭代机制与收敛特性;②通过实际代码复现EI、顶刊级别论文中的优化模型;③在具体科研项目中对比两类算法的寻优能力、稳定性与计算效率,完成算法选型与改进;④拓展新型优化算法在多能互补系统、智能路径规划、分布式调度等交叉学科中的创新应用。; 阅读建议:建议读者结合网盘提供的完整代码资源,按照文档中给出的应用实例循序渐进地实践操作,重点关注不同场景下的参数设置策略、算法收敛曲线分析与鲁棒性表现,同时关注公众号“荔枝科研社”获取持续的技术支持与更新资料。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值