AtCoder Beginner Contest 132 E - Hopscotch Addict
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的更多相关文章
- AtCoder Beginner Contest 132
目录 Contest Info Solutions A. Fifty-Fifty B. Ordinary Number C. Divide the Problems D. Blue and Red B ...
- AtCoder Beginner Contest 132 解题报告
前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...
- AtCoder Beginner Contest 132 F Small Products
Small Products 思路: 整除分块+dp 打表发现,按整除分块后转移方向如下图所示,上面的块的前缀转移到下面的块 代码: #pragma GCC optimize(2) #pragma G ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
随机推荐
- axios以form-data形式的传递参数遇到的坑
axios默认的Content-type是application/json;charset=UTF-8,如果想要以表单的形式传递参数,只要修改{headers:{'Content-Type':'app ...
- 关于redis闪退的案例
我需要恢复之前备份的文件:dump.rdb,文件大小2.2G 于是将dump.rdb放在redis的安装目录下,然后启动redis. ./redis-server redis.conf 然后我在另一个 ...
- Spark Streaming设计
- 【学术篇】SPOJ FTOUR2 点分治
淀粉质入门第一道 (现在个人认为spoj比bzoj要好_(:з」∠)_ 关于点分治的话推荐去看一看漆子超的论文>>>这里这里<<< 之前一直试图入点分治坑, 但是因 ...
- Codeforces 1151E 统计贡献
题意:给你一个数组a,设函数f(l, r)为数组a中权值在[l, r]之间的连通块的数目,比如a = [1, 3, 2, 1], f(1, 2) = 2, 连通块是位置1和位置3,4.问Σ(i = 1 ...
- NX二次开发-UF_MODL_ask_distance_tolerance获取建模的长度公差
NX9+VS2012 #include <uf.h> #include <uf_modl.h> #include <uf_ui.h> UF_initialize() ...
- Python爬虫-《神雕侠侣》
Python3.5 爬取<神雕侠侣>http://www.kanunu8.com/wuxia/201102/1610.html 武侠迷,所以喜欢爬取武侠小说 #!/usr/bin/pyth ...
- java.sql.SQLException: ORA-12704: 字符集不匹配
INFO:HibernateSimpleDao----queryForListWithSql:SELECT site_id as id ,MAX(case attr_name when 'siteNa ...
- 专题:“find -perm”
Search for files which have read and write permission for their owner, and group, but which other us ...
- 神经网络中使用Batch Normalization 解决梯度问题
BN本质上解决的是反向传播过程中的梯度问题. 详细点说,反向传播时经过该层的梯度是要乘以该层的参数的,即前向有: 那么反向传播时便有: 那么考虑从l层传到k层的情况,有: 上面这个 便是问题所在.因为 ...