zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)
题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light
题解:
题意自己翻译,此题首先肯定是要广搜的,不过要开一个1e5*1e5的数组好像有点困难,
所以用结构体来存每个点的下标,然后从源点开始广搜。定义一个pair<node,int>,第一个存节点信息,第二个存到当前节点的步数,因为还要处理到达每个节点的状态。
状态:走奇数步并且状态为1与走偶数步状态为0的结果是一样的,都是向左或向右移动。走偶数步并且状态为1与走奇数步状态为0的结果也是一样,可以向上或向下移动。
最后定义一个pair的队列。
代码:
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#include <utility>
#define IO ios::sync_with_stdio(0);\
cin.tie();cout.tie();
using namespace std;
;
struct node
{
int i,j,value;
int flag;
} res[N];
pair <node,int> p;
queue <pair<node,int > > q;
int main()
{
int T;
cin >> T;
while(T--)
{
memset(res,,sizeof(res));
;
cin >> n >> m;
; i <= n; i++)
; j <= m; j++)
cin >> x,res[++num].value = x,res[num].i = i,res[num].j=j;
int x1,y1,x2,y2;
cin >>x1>>y1>>x2>>y2;
;
res[(x1-)*m + y1].flag = ;
p.first = res[(x1-)*m + y1];
p.second = sum;
q.push(p);
,ff = ;
while(!q.empty())
{
pair <node,int> pp;
pp = q.front();
q.pop();
int i = pp.first.i,j = pp.first.j,value = pp.first.value,sum = pp.second;
if(i==x2&&j==y2)
{
ans = sum;
ff = ;
break;
}
)&&value==)||(!(sum&)&&value==))
{
<=n&&res[i*m+j].flag==)
{
pp.first.i = i+,pp.first.j = j,pp.first.value = res[(i)*m+j].value;
pp.first.flag = ;
res[(i)*m+j].flag = ;
pp.second = sum+;
q.push(pp);
}
>&&res[(i-)*m+j].flag==)
{
pp.first.i = i-,pp.first.j = j,pp.first.value = res[(i-)*m+j].value;
pp.first.flag = ;
res[(i-)*m+j].flag = ;
pp.second = sum+;
q.push(pp);
}
}
else
{
<=m&&res[(i-)*m+j+].flag==)
{
pp.first.i = i,pp.first.j = j+,pp.first.value = res[(i-)*m+j+].value;
pp.first.flag = ;
res[(i-)*m+j+].flag = ;
pp.second = sum+;
q.push(pp);
}
>&&res[(i-)*m+j-].flag==)
{
pp.first.i = i,pp.first.j = j-,pp.first.value = res[(i-)*m+j-].value;
pp.first.flag = ;
res[(i-)*m+j-].flag = ;
pp.second = sum+;
q.push(pp);
}
}
}
printf();
while(!q.empty())q.pop();
}
;
}
/*
4
2 3
1 1 0
0 1 0
1 3 2 1
2 3
1 0 0
1 1 0
1 3 1 2
2 2
1 0
1 0
1 1 2 2
1 2
0 1
1 1 1 1
*/
zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)的更多相关文章
- ZOJ 4016 Mergeable Stack(from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
模拟题,用链表来进行模拟 # include <stdio.h> # include <stdlib.h> typedef struct node { int num; str ...
- ZOJ 4019 Schrödinger's Knapsack (from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
题意: 第一类物品的价值为k1,第二类物品价值为k2,背包的体积是 c ,第一类物品有n 个,每个体积为S11,S12,S13,S14.....S1n ; 第二类物品有 m 个,每个体积为 S21,S ...
- Mergeable Stack 直接list内置函数。(152 - The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
题意:模拟栈,正常pop,push,多一个merge A B 形象地说就是就是将栈B堆到栈A上. 题解:直接用list 的pop_back,push_back,splice 模拟, 坑:用splice ...
- 152 - - G Traffic Light 搜索(The 18th Zhejiang University Programming Contest Sponsored by TuSimple )
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5738 题意 给你一个map 每个格子里有一个红绿灯,用0,1表示 ...
- The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack
题目链接 题意: 题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!! 代码: #include <std ...
- The 18th Zhejiang University Programming Contest Sponsored by TuSimple
Pretty Matrix Time Limit: 1 Second Memory Limit: 65536 KB DreamGrid's birthday is coming. As hi ...
- The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror) B"Even Number Theory"(找规律???)
传送门 题意: 给出了三个新定义: E-prime : ∀ num ∈ E,不存在两个偶数a,b,使得 num=a*b;(简言之,num的一对因子不能全为偶数) E-prime factorizati ...
- The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391 A Thanks, TuSimple! Time ...
- The 17th Zhejiang University Programming Contest Sponsored by TuSimple J
Knuth-Morris-Pratt Algorithm Time Limit: 1 Second Memory Limit: 65536 KB In computer science, t ...
随机推荐
- Sqlserver中如何创建链接服务器
链接服务器在跨数据库/跨服务器查询时非常有用(比如分布式数据库系统中),我将以图文方式详细说明如何利用SQL Server Management Studio在图形界面下创建链接服务器 方法/步骤 ...
- 使用kubeadm安装Kubernetes 1.12
使用kubeadm安装Kubernetes 1.12 https://blog.frognew.com/2018/10/kubeadm-install-kubernetes-1.12.html 测试环 ...
- 【java】AES加密解密|及Base64的使用
转载自:http://www.cnblogs.com/arix04/archive/2009/10/15/1511839.html AES加解密算法,使用Base64做转码以及辅助加密: packag ...
- java发送邮件(一)
一:前言 一直想做有关java发邮件的功能,但是了一直没有成功,特别的无语啊,所以今天有时间我终于成功了啊,虽然是最简单的,但是还是记载下来吧! 二:内容 这里主要需要的是spring-context ...
- 51Nod 1014 X^2 Mod P
注意潜在范围 x*x用long long #include <bits/stdc++.h> using namespace std; typedef long long LL; #defi ...
- windows 安装elk日志系统
1.前往https://www.elastic.co官网下载对应的elasticsearch .kibana和logstash他们的版本号一致. 2.elasticsearch 解压后前往bin文件下 ...
- OScached页面缓存的概念和安装
一.基本概述 OSCache标记库由OpenSymphony设计,它是一种开创性的JSP定制标记应用,提供了在现有JSP页面之内实现快速内存缓冲的功能.OSCache是个一个广泛采用的高性能的J2EE ...
- 【51NOD-0】1085 背包问题
[算法]背包DP [题解]f[j]=(f[j-w[i]]+v[i]) 记得倒序(一个物品只能取一次) #include<cstdio> #include<algorithm> ...
- [Unity]插件Node Editor介绍 实现类似状态机画布的扩展
Unity自带的动画状态机有一套对策划非常友好的UI.但是Unity官方没有公开这些控件的api.除了Asset Store里一些已有的方案,我在这里介绍一个在github上的开源项目,封装了底层,但 ...
- Python爬虫—破解JS加密的Cookie
前言 在GitHub上维护了一个代理池的项目,代理来源是抓取一些免费的代理发布网站.上午有个小哥告诉我说有个代理抓取接口不能用了,返回状态521.抱着帮人解决问题的心态去跑了一遍代码.发现果真是这样. ...