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 ...
随机推荐
- 使用AAUTO语言开发的云桌面登录客户端
AAUTO是一个国产小众语言,和lua算是近亲,官方网站 www.aau.cn. 使用aauto的优点我认为对于我来说最主要的有以下两点: 1.无需臃肿的框架类似.NET FRAMEWORK.Adob ...
- Spring Boot 中使用 MyBatis 整合 Druid 多数据源
2017 年 10 月 20 日 Spring Boot 中使用 MyBatis 整合 Druid 多数据源 本文将讲述 spring boot + mybatis + druid 多数据源配置方 ...
- MongoDB 数据库(2)
db.collectionName 集合对象 获取集合对象 db.getCollection('collection_name') e.g. db.getCollection("class0 ...
- 集合框架源码学习之LinkedList
0-1. 简介 0-2. 内部结构分析 0-3. LinkedList源码分析 0-3-1. 构造方法 0-3-2. 添加add方法 0-3-3. 根据位置取数据的方法 0-3-4. 根据对象得到索引 ...
- python3中处理url异常
import urllib.request import urllib.error url = 'http://c.telunyun.com/Chart/getJsonData?market=1' d ...
- ew做socks5代理
这个工具和之前讲过的xxoo类似.链接:https://www.cnblogs.com/nul1/p/8883271.html https://zhuanlan.zhihu.com/p/3282215 ...
- linux安装lamp
github https://github.com/zblogcn/zblogphp Installation If your server system: CentOS yum -y install ...
- Java中基于HotSpot虚拟机的垃圾收集器
名称 过程 优缺点 Serial 进行垃圾收集时,必须暂停其他所有的工作进程,直到它收集结束.是一个单线程收集器. Stop the world. 新生代收集器. 手工设置新生代的大小:-Xmn Ed ...
- hadoop入门学习
hadoop入门学习:http://edu.csdn.net/course/detail/1397hadoop hadoop2视频:http://pan.baidu.com/s/1o6uy7Q6HDF ...
- C++学习之路(七):以const,enum,inline替换#define
这篇博文主要是编程中的一些问题和技巧.如题目所示,这些关键字的作用不再进行描述.直接描述功能和实例代码. 首先,在头文件中对类进行定义,是不会为类分配内存空间的,在这一点上类定义可以和普通变量类型的声 ...