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. 启动多个mysql实例

    如果使用./support-files/mysql.server 文件启动,则默认读取/etc/my.cnf 配置文件,这种方式有时候启动不了 会提示报错 :The server quit witho ...

  2. qt5.9.1 VS2017 qalgorithms.h

    qt5.9.1只有VS2017 64位支持, 在32位工程下会出现关于qalgorithms.h的错误,参考以下内容修改该头文件解决: https://codereview.qt-project.or ...

  3. AXD 的使用以及源代码说明

    汇编源代码说明 ;=============================================================================== ;  引用头文件 ;= ...

  4. Java判断链表是否为回文链表

    请判断一个链表是否为回文链表. 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 思路:1.通过快慢指针,来遍历链表 ...

  5. leetcode-数组的相对排序

    Python解法: def relativeSortArray(arr1, arr2): arr = [0 for _ in range(110)] new = [] for a in range(l ...

  6. C/C++ 智能指针

    // 转载自 :https://www.cnblogs.com/wuyepeng/p/9741241.html { 为什么要使用智能指针:我们知道c++的内存管理是让很多人头疼的事,当我们写一个new ...

  7. git Web

    { …or create a new repository on the command line   echo "# Kotlin" >> README.md git ...

  8. 在sublime上安装markdown插件(win10)

    1.markdown插件安装 --ctrl+shift+p --在命令框中选中 package control:install package 选中它  按回车 --在命令框中输入 markdown, ...

  9. JS中 reduce() 的用法

    过去有很长一段时间,我一直很难理解 reduce() 这个方法的具体用法,平时也很少用到它.事实上,如果你能真正了解它的话,其实在很多地方我们都可以用得上,那么今天我们就来简单聊聊JS中 reduce ...

  10. 接口(Interfaces)与反射(reflection) 如何利用字符串驱动不同的事件 动态地导入函数、模块

    标准库内部如何实现接口的 package main import ( "fmt" "io" "net/http" "os" ...