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. HBase启动错误提示别的机器60000已经存在

    已经用cm  安装好了cdh,需要在上面添加HBase,并且做一个HBase故障转移功能,现在需要配置2个HMaster 在不同的机器上. 启动出现异常信息: 2015-12-23 14:44:38, ...

  2. json条件查询

    完整Demo <html> <head> <script type="text/javascript" src="http://www.w3 ...

  3. 【BZOJ 3569】DZY Loves Chinese II

    题面 Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图 ...

  4. Linux 系统分区与目录介绍

    分区 分区类型 主分区:总共最多只能分四个 扩展分区: 只能有一个,也算作主分区的一种,也就是说主分区加扩展分区最多有四个. 但是扩展分区不能存储数据和格式化,必须再划分成逻辑分区才能使用. 逻辑分区 ...

  5. R语言 运算符

    R语言运算符 运算符是一个符号,通知编译器执行特定的数学或逻辑操作. R语言具有丰富的内置运算符,并提供以下类型的运算符. 运算符的类型 R语言中拥有如下几种运算符类型: 算术运算符 关系运算符 逻辑 ...

  6. eclipse背景设置什么颜色缓解眼睛疲劳

    eclipse背景设置什么颜色缓解眼睛疲劳 1.打开window->Preference,弹出Preference面板 2.展开General标签,选中Editors选项,展开. 3.选中 Te ...

  7. NX二次开发-UFUN输入表达式TAG,得到表达式字符串UF_MODL_ask_exp_tag_string

    NX9+VS2012 #include <uf.h> #include <uf_modl.h> UF_initialize(); //创建表达式 tag_t NewExpTag ...

  8. vue webpack打包后.css文件里面的背景图片路径错误解决方法

    资源相对引用路径 问题描述 一般情况下,通过webpack+vuecli默认打包的css.js等资源,路径都是绝对的. 但当部署到带有文件夹的项目中,这种绝对路径就会出现问题,因为把配置的static ...

  9. JS对象的可枚举属性和不可枚举属性

    昨天在写文章(转载)的时候发现了有些对象的方法是分可枚举性和不可枚举性的.简单的查了一下资料,今天来捋一捋啥是对象的可枚举啥是不可枚举. 可枚举性: 对象的每一个属性都有一个描述对象,用来描述和控制该 ...

  10. POJ3241 最小曼哈顿距离生成树 - 真有趣哇

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门  原题目描述在最下面.  给你n个坐标, ...