bfs

位置+状态

just need to calculate min value(only it is useful), so O(1*x)

挺有趣的一道题。。。

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long const int maxn=1e6+; struct node
{
int d;
node *to;
}*e[maxn]; int qx[maxn*],qy[maxn*],qz[maxn*]; int f[maxn][]; int main()
{
node *p;
int n,m,x,y,z,xx,yy,zz,head,tail,s,t;
scanf("%d%d",&n,&m);
while (m--)
{
scanf("%d%d",&x,&y);
p=new node();
p->d=y;
p->to=e[x];
e[x]=p;
} scanf("%d%d",&s,&t);
qx[]=s,qy[]=,qz[]=;
head=,tail=;
while (head<tail)
{
head++;
x=qx[head];
y=qy[head];
z=qz[head]; p=e[x];
while (p)
{
xx=p->d;
yy=(y+)%;
zz=z+;
if (!f[xx][yy])
{
if (xx==t && yy==)
{
printf("%d",(zz-)/);
return ;
}
tail++;
qx[tail]=xx;
qy[tail]=yy;
qz[tail]=zz;
f[xx][yy]=zz;
}
p=p->to;
}
}
printf("-1");
return ;
}

AtCoder Beginner Contest 132 E - Hopscotch Addict的更多相关文章

  1. AtCoder Beginner Contest 132

    目录 Contest Info Solutions A. Fifty-Fifty B. Ordinary Number C. Divide the Problems D. Blue and Red B ...

  2. AtCoder Beginner Contest 132 解题报告

    前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...

  3. AtCoder Beginner Contest 132 F Small Products

    Small Products 思路: 整除分块+dp 打表发现,按整除分块后转移方向如下图所示,上面的块的前缀转移到下面的块 代码: #pragma GCC optimize(2) #pragma G ...

  4. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  5. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  6. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  7. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  8. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  9. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

随机推荐

  1. leetcode.字符串.696计数二进制子串-java

    1. 具体题目 给定一个字符串 s,计算具有相同数量0和1的非空(连续)子字符串的数量,并且这些子字符串中的所有0和所有1都是组合在一起的.重复出现的子串要计算它们出现的次数. 示例 1 : 输入: ...

  2. ArcGis相接面补节点c#

    相接(Touch)面执行切割后 新面与原相接面会缺少公共节点. private void AddPointToTouchesPolygon(IFeatureCursor newFeatureCurso ...

  3. IPC$渗透使用

    简介 IPC$(Internet Process Connection)是共享"命名管道"的资源,它是为了让进程间通信而开放的命名管道,通过提供可信任的用户名和口令,连接双方可以建 ...

  4. ARM 汇编指 跳转指令 b , bl

    1. 跳转指令 [ b ] [ bl ]   指令格式:<opcode><cond> <address> 不带返回的跳转指令:b mov r0, #0x12 mov ...

  5. Eureka配置详解(转)

    Eureka客户端配置       1.RegistryFetchIntervalSeconds 从eureka服务器注册表中获取注册信息的时间间隔(s),默认为30秒 2.InstanceInfoR ...

  6. java.lang.ThreadLocal的作用和原理?列举在哪些程序中见过ThreadLocal的使用?

    java.lang.ThreadLocal的作用和原理?列举在哪些程序中见过ThreadLocal的使用? 说明类java.lang.ThreadLocal的作用和原理.列举在哪些程序中见过Threa ...

  7. js数组中对象去重 (reduce() 方法)

    一个数组中含有对象,并且去掉数组中重复的对象.主要代码如下: var arrData = [ {id: , name: "小明"}, {id: , name: "小张&q ...

  8. HBase的应用场景及特点

    一.Hbase能做什么?1. 海量数据存储:上百亿行 x 上百万列并没有列的限制当表非常大的时候才能发挥这个作用, 最多百万行的话,没有必要放入hbase中2. 准实时查询:百亿行 x 百万列,在百毫 ...

  9. post请求传文件

    public static JSONObject doFormDataPost(File file, String sURL) throws IOException { HttpClient cont ...

  10. 牛客多校第十场 B Coffee Chicken 递归

    题意: 给你一个“斐波那契”字符串数列,第n项由第n-1项和第n-2项拼接而成,输出某项的某位及其后10位. 题解: 递归求解即可. #include<bits/stdc++.h> usi ...