原题目

As part of a CS course,Alice just finished programming her robot to explore a graph having nn nodes,labeled 1,2,...,n,1,2,...,n, and mm directed edges. Initially the robot starts at node 11.

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 55 has outgoing edges to neighbors 1, 41,4, and 66 but that Alice programs the robot so that if it leaves 55 it must go to neighbor 44.

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.

题意

一个有向图从①出发,最多有一次不走红边而走其他出边的机会(bug),问能停在几个点上

思路

一道很简单调了一个晚上Orz的搜索题
结构体存储边的信息,将红边放在每个点的头部,能优化一下常数
从①开始进行DFS,可以根据之前有没有出过bug,选择按红边走或者不按红边走,如果选择不按红边走就在搜索参数上面调整为出过bug,直到到一个不能再操作的点为止,答案+1

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>using namespace std;
const int maxn=1e3+10;
struct node
{int to,tp;node(int to,int tp):to(to),tp(tp){}
};
vector<node> g[maxn];
bool vis[maxn],fst[maxn];                                            //vis是是否进行过搜索的点,fst是标记最后停下来的点
int n,m,cnt;void dfs(int cur,bool bug)
{int sz=g[cur].size();if(sz==0){if(!fst[cur])   fst[cur]=1,cnt++;return ;}else if(g[cur][0].tp==1){if(!fst[cur])fst[cur]=1,cnt++;}if(bug){if(g[cur][0].tp==2&&!vis[g[cur][0].to])vis[g[cur][0].to]=1,dfs(g[cur][0].to,bug);return ;}else{for(int i=0;i<sz;++i){if(!vis[g[cur][i].to]){vis[g[cur][i].to]=1;if(g[cur][i].tp==2){dfs(g[cur][i].to,0);         //使用fst标记答案点是为了防止`出现或者不出现bug都按红边而出现的重复计数`dfs(g[cur][i].to,1);}else{dfs(g[cur][i].to,1);}}}}
}int main()
{cin>>n>>m;if(m==0){cout<<0;return 0;}int s,e;for(int i=1;i<=m;++i){scanf("%d%d",&s,&e);if(s>0) g[s].push_back(node(e,1));else g[-s].insert(g[-s].begin(),node(e,2));}dfs(1,0);cout<<cnt;return 0;
}

看到了跟dalao之间的差距,得更加努力了,猛练自然强,加油!!

转载于:https://www.cnblogs.com/JNzH/p/11297068.html

[ICPC USA]Faulty Robot相关推荐

  1. ajax machine tool,Machine Tool

    The world's largest Machine Tool Reference Archive - a growing collection of articles about Manufact ...

  2. 2015-01-11 在SQL2008创建一个数据库

    将下列内容存储到以sql为后缀名的文件中即可,然后在拖到SQL 2008 Manager中进行 执行 就可以完成数据库的创建了 ------------------------------------ ...

  3. 习题6_5 巡逻机器人(Patrol Robot, ACM/ICPC Hanoi 2006, UVa1600)

    越障可以拐弯,一个障碍可能被不同路线所经过,所以普通的dfs不行,再加一个维度step,表示走到此结点越过的障碍数 #include<cstdio> #include<cstring ...

  4. UVa1600 习题6-5 巡逻机器人 (Patrol Robot,ACM/ICPC Hanoi 2006)

    原题链接: UVa-1600 题目大意: 模拟机器人要从一个m*n(m和n的范围都在1到20的闭区间内)的网格的左上角(1,1)走到右下角(m,n).网格中的一些格子是空地,用0表示,其它格子是障碍, ...

  5. 习题6-5 巡逻机器人(Patrol Robot, ACM/ICPC Hanoi 2006, UVa1600)

    同Uva816,本题在本质上也是迷宫问题,连续穿越的次数k起到了关键作用,故用三元组表示状态. #include <iostream> #include <string> #i ...

  6. 2020-2021 ICPC, NERC, Southern and Volga Russian Regional Contest K. The Robot

    翻译: 有一个机器人在一个没有尽头的方格场上.最初,机器人位于坐标为(0,0)的单元中.他将执行由一串大写拉丁字母"L"."R"."D".& ...

  7. Bubble Cup 14 - Finals Online Mirror (Unrated, ICPC Rules, Teams Preferred, Div. 2) J. Robot Factor

    翻译: 你已经收到了Bubble机器人的数据.你知道你的任务是制造工厂设施,但在你开始之前,你需要知道工厂有多大,有多少房间.当你查看数据时,你会发现你有这个结构的尺寸,它是矩形的:N x M. 然后 ...

  8. Bubble Cup 14 - Finals Online Mirror (Unrated, ICPC Rules, Teams Preferred, Div. 2) J. Robot Factory

    传送门 题意: 给你一个矩阵,矩阵中的每一个数的二进制串可以表示出该位置周围的围墙信息,让你求出所有的房间大小. 思路: 建图,搜索,一气呵成. #include<iostream> #i ...

  9. As Easy as CAB(2016 ICPC Mid-Central USA Region)

    题意: 输入 字母(用变量名 AA 代替) n // 分别代表这个串中最大的字母(这个是按照原有字母表的顺序确定的)  . n个串 按照 新规定字母表的大小顺序 给出由小到大排序好的 n 个字符串,求 ...

  10. 2017 ACM ICPC Asia Shenyang Regional Contest 题解(10 / 13)【每日亿题2 / 16】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A.(2017 ICPC shenyang I)Little Boxes B.(2017 ICP ...

最新文章

  1. 集群概述及原理笔记(1)
  2. STM32 基础系列教程 39 - Lwip_tftp
  3. 【CyberSecurityLearning 58】PHP代码注入
  4. 5渲染判断if_React 16 渲染流程
  5. 孤儿进程和僵死进程处理方法
  6. DevOps vs. Agile:它们有什么共同点?
  7. 树莓派开始玩转linux pdf_用树莓派构建 Kubernetes 集群 | Linux 中国
  8. python爬虫ssl错误_Python爬虫:Requests的SSLError:certificate verify failed问题解决方案6条...
  9. 消息中间件—Kafka 的设计思想
  10. mysql workbench企业_甲骨文发布MySQL Workbench 6.0版本
  11. ul在Firefox和IE下的不同表现
  12. Springmvc 的post请求的json格式参数
  13. linux搭建vsftp服务器_Linux(CentOS 7)搭建VSFTP服务器
  14. html---表单实例代码
  15. kali安装火狐浏览器
  16. 品牌出海:如何做好本土化运营?
  17. python入门教程陈孟林_Python快速入门指南,没基础没关系
  18. 码元、符号、波特率、比特率等概念的了解
  19. 类似qq的汉字拼音首字查询
  20. 神经网络整合算法是什么,神经网络整合算法实例

热门文章

  1. 【百战GAN】StyleGAN原理详解与人脸图像生成代码实战
  2. 制作你软盘镜像_codestorm_新浪博客
  3. 妖精为什么吃不到唐僧肉
  4. linux系统it固定资产管理系统包_固定资产管理系统的细节分析
  5. 网易视频云:新一代列式存储格式Parquet
  6. Andriod程序的结构
  7. 扫描件如何转换成pdf及word文档?
  8. flyway 实现 java 自动升级 SQL 脚本
  9. win7系统提示0x80072F8F错误代码的解决方法(刷新你的认知)
  10. 网游无间道:你所忽略的托儿