mcpc2017 Faulty Robot

 

问题 G: Faulty Robot

时间限制: 1 Sec  内存限制: 128 MB
提交: 56  解决: 19
[提交][状态][讨论版][命题人:admin]

题目描述

As part of a CS course, Alice just finished programming her robot to explore a graph having n nodes, labeled 1, 2, . . . , n, and m directed edges. Initially the robot starts at node 1.
While nodes may have several outgoing edges, Alice programmed the robot so that any node may have a forced move to a specific one of its neighbors. For example, it may be that node 5 has outgoing edges to neighbors 1, 4, and 6 but that Alice programs the robot so that if it leaves 5 it must go to neighbor 4.
If operating correctly, the robot will always follow forced moves away from a node, and if reaching a node that does not have a forced move, the robot stops. Unfortunately, the robot is a bit buggy, and it might violate those rules and move to a randomly chosen neighbor of a node (whether or not there had been a designated forced move from that node). However, such a bug will occur at most once (and might never happen). 
Alice is having trouble debugging the robot, and would like your help to determine what are the possible nodes where the robot could stop and not move again.
We consider two sample graphs, as given in Figures G.1 and G.2. In these figures, a red arrow indicate an edge corresponding to a forced move, while black arrows indicate edges to other neighbors. The circle around a node is red if it is a possible stopping node.

In the first example, the robot will cycle forever through nodes 1, 5, and 4 if it does not make a buggy move.
A bug could cause it to jump from 1 to 2, but that would be the only buggy move, and so it would never move on from there. It might also jump from 5 to 6 and then have a forced move to end at 7.
In the second example, there are no forced moves, so the robot would stay at 1 without any buggy moves. It might also make a buggy move from 1 to either 2 or 3, after which it would stop.

输入

The first line contains two integers n and m, designating the number of nodes and number of edges such that 1 ≤ n ≤ 103, 0 ≤ m ≤ 104. The next m lines will each have two integers a and b, 1 ≤ |a|, b ≤ n and |a| ≠ b. If a > 0, there is a directed edge between nodes a and b that is not forced. If a < 0, then there is a forced directed edge from −a to b. There will be at most 900 such forced moves. No two directed edges will be the same. No two starting nodes for forced moves will be the same.

输出

Display the number of nodes at which the robot might come to a rest.

样例输入

7 9
1 2
2 3
-1 5
2 6
5 1
-4 1
5 6
-6 7
-5 4

样例输出

2

提示

 

[提交][状态]

 

 

 

 

【题意】有n个节点,m条有向边,当某个顶点的出边有红色边时,必须走红色边。不过机器人的程序有点bug,可能会发生变异,变异的次数最多1次,最少0次。对于出边为黑色的边,只有当发生变异的时候才能够通过(即当机器人发生变异时可以选择任意颜色的出边);求该图中最多有几个休息点(即当前顶点出边没有红色边或者没有出边);

其中该图没有重边,同一个顶点不会有两条红色出边。

【思路】dfs暴力遍历,在搜索的同时判断当前节点的所有出边,没有出边或者出边全为黑标记并+1,存在红边时,继续搜索,对于黑边,如果当前可以遍历,则搜索该黑边,否则不搜索。

【代码如下】

 

#include<bits/stdc++.h>
using namespace std;

const int N=1e6+5;
const int INF=0x3f3f3f3f;
int vis[1100],head[1100],cnt,n,m,ans,ok[1100];
struct Edge{
    int flag,next,v;
}edge[11000];

void add(int u, int v, int flag){
    edge[cnt].v = v;
    edge[cnt].next = head[u];
    edge[cnt].flag = flag;
    head[u] = cnt ++;
}

void dfs(int x, int cur){
    int fb=0,sum=0;
    for(int i = head[x]; ~i; i = edge[i].next){
        int v = edge[i].v, flag = edge[i].flag;
        sum ++;
       // printf("%d******%d\n",v,cur);
        if(flag && !vis[v]){
            vis[v] = 1;
            dfs(v,cur);
            vis[v] = 0;
        }
        else if(!flag){   //printf("%d*****%d\n",v,cur);
            //ans ++;
            //vis[v] = 1;
            if(cur) dfs(v,cur-1);
            fb ++;
        }
    }
    //printf("%d   %d   %d   %d\n",x,fb,sum,cur);
    if(sum == fb && !ok[x]) ans ++,ok[x]=1;//printf("%d******\n",x);
}

int main(){
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    memset(ok,0,sizeof(ok));
    cnt = ans = 0;
    for(int i = 0; i < m; i ++){
        int u,v;
        scanf("%d%d",&u,&v);
        if(u<0) add(abs(u),v,1);
        else add(u,v,0);
    }
    memset(vis,0,sizeof(vis));
    vis[1] = 1;
    dfs(1,1);
    printf("%d\n",ans);
    return 0;
}
/*
6 8
1 2
-2 3
3 4
-3 6
-6 2
6 5
5 2
5 1

7 9
-1 2
-2 3
-3 1
1 4
-4 2
2 5
5 4
-3 6
3 7
*/

 

 

 

 

 

内容概要:本文提出了一种基于改进扩散模型的高海拔地区新能源高波动出力场景生成方法,并提供了完整的Python代码实现。该方法针对高海拔地区风能、光伏等新能源出力波动剧烈、不确定性高的特点,通过优化扩散模型的结构与训练策略,有效捕捉历史数据的概率分布特征与时序相关性,从而生成高质量、多样化的出力场景。文中详细阐述了模型的数学推导、网络架构设计、损失函数优化及采样算法改进,并通过实验证明其在拟合精度、场景多样性与稳定性方面优于传统生成模型,为电力系统在高比例新能源接入下的规划、调度与风险评估提供了可靠的场景输入支持。; 适合人群:具备一定Python编程能力和机器学习基础,从事新能源发电预测、电力系统分析、智能优化、场景生成等方向研究的科研人员、高校研究生及工程技术人员。; 使用场景及目标:①用于高海拔地区风电、光伏出力的不确定性建模与多场景生成;②支撑含高渗透率新能源的电力系统随机优化调度、鲁棒决策与风险评估;③为相关学术研究、论文复现与算法改进提供可运行的技术方案与代码基础; 阅读建议:建议读者结合所提供的完整资源(代码、数据集、说明文档)进行实践操作,重点关注扩散模型的前向加噪与反向去噪过程的设计细节,以及如何将其适配于新能源时序数据的生成任务,通过参数调优与对比实验深入理解模型的生成机制与性能边界。
内容概要:本文围绕基于静态约束法的配电网电动汽车接入容量评估展开研究,提出了一种在新型电力系统背景下评估主动配电网对电动汽车承载能力的方法。研究通过构建数学模型,结合潮流计算与关键约束条件(如电压越限、线路过载等),量化分析配电网可承受的最大电动汽车充电负荷容量,旨在识别规模化电动汽车接入带来的潜在运行风险,并为电网规划与运行提供科学依据。文中配套提供了完整的Matlab代码实现,便于仿真验证与结果复现。此外,该研究与分布式光伏承载力评估、电动汽车可调能力分析等方向形成技术联动,展现了多主题协同的研究体系。; 适合人群:具备电力系统分析基础理论知识及Matlab编程能力的高校研究生、科研机构研究人员,以及从事新能源并网、智能配电网规划与运行等相关领域的工程技术人员。; 使用场景及目标:①用于学术研究中的模型复现与论文撰写支撑;②评估实际配电网中电动汽车大规模接入的可行性与安全边界,指导充电基础设施布局;③作为高校教学案例,帮助学生深入理解电网承载力评估的核心原理、建模方法与仿真技术; 阅读建议:建议结合文中提及的相关研究方向(如二阶锥规划、多面体聚合方法等)进行对比学习,充分利用所提供的Matlab代码与网盘资料开展仿真实验,重点关注约束条件的设定逻辑与潮流计算模块的实现细节,以深化对评估模型机理与工程应用价值的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值