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 ...
随机推荐
- centos7部署汉化版gitlab
=============================================== 2018/6/5_第7次修改 ccb_warlock 更新说 ...
- phoenix 利用CsvBulkLoadTool 批量带入数据并自动创建索引
需要先创建表: CREATE TABLE IF NOT EXISTS population ( state CHAR() NOT NULL, city VARCHAR NOT NULL, popula ...
- GP下CalculateField的用法
以前用过这个类做字段计算,许久不用有些忘却,记录一下使用方式 public static void CalculateField(IFeatureLayer featureLayer,IField f ...
- [工具]Editplus添加son格式化支持
EditPlus安装包和json.js文件地址 不喜欢CSDN的积分下载和登录下载,不喜欢百度网盘,就这么倔强 https://github.com/michael-deve/CommonData-E ...
- springmvc3.2集成redis集群
老项目需要集成redis集群 因为spring版本才从2.x升级上来,再升级可能改动较大,且并非maven项目升级麻烦,故直接集成. jar包准备: jedis-2.9.0.jar -- 据说只有这 ...
- 5.Struts2框架中的ServletAPI如何获取
1.完全解耦合的方式 如果使用该种方式,Struts2框架中提供了一个类,ActionContext类,该类中提供一些方法,通过方法获取Servlet的API 一些常用的方法如下 * static A ...
- Wordpress 文章编辑页面添加 metabox
add_meta_box($id,$title,$callback,$screen,$context:,$priority); 参数 $id (字符串)(必需)Meta模块的 HTML"ID ...
- 解决 AUTH` failed: ERR Client sent AUTH, but no password is set [tcp://127.0.0.1:6379]
页面报错: ConnectionException In AbstractConnection.php line 155 AUTH` failed: ERR Client sent AUTH, but ...
- leetcood学习笔记-110-平衡二叉树
---恢复内容开始--- 题目描述: 方法一: class Solution(object): def isBalanced(self, root): """ :type ...
- delphi常见的错误
******************************* * 编 译 错 误 信 息 * ******************************* ';' not allowed befo ...