题目链接: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(广搜)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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表示 ...

  5. The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack

    题目链接 题意: 题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!! 代码: #include <std ...

  6. 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 ...

  7. 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 ...

  8. The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)

    http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391 A     Thanks, TuSimple! Time ...

  9. 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 ...

随机推荐

  1. zTab layui多标签页组件

    zTab zTab是一个layui多标签页插件,仿照了layuiAdmin的iframe版Tab实现 当前版本v1.0 码云地址:https://gitee.com/sushengbuyu/zTab ...

  2. Chromedriver 的安装与配置

    首先是下载网址:https://sites.google.com/a/chromium.org/chromedriver/downloads(需要FQ,用Browser浏览器即可翻进,版本要和Chro ...

  3. DotNet 学习笔记 OWIN

    Open Web Interface for .NET (OWIN) ----------------------------------------------------------------- ...

  4. Centos服务器ssh免密登录以及搭建私有git服务器

    一.概述 服务器的免密登录和git服务器的搭建,关键都是要学会把自己用的机器的公钥添加到服务器上,让服务器“认识”你的电脑,从而不需要输入密码就可以远程登录服务器上的用户 免密登录当然是登录root用 ...

  5. Jquery checkbox 遍历

    checkbox 全选\全部取消 $("#ChkAll").click(function(){    $("#divContent input[type='checkbo ...

  6. linux 3389连接工具Rdesktop

    简单使用 工作机换成战斗机了,改用ubuntu,原来的windows7上东西笔记多,还不想重装.用rdesktop来远程连接windows: sudo apt-get install rdesktop ...

  7. 【Matlab】绘制饼状统计图

    a=tabulate(b); % b为需要绘制饼图的原始数据列,生成新的一个矩阵a label={'1','2','3'} % 设定饼图每块扇形代表的内容 percent=num2str(a(:,3) ...

  8. python基础===中文手册,可查询各个模块

    http://python.usyiyi.cn/translate/python_352/index.html

  9. mips64高精度时钟引起ktime_get时间不准,导致饿狗故障原因分析【转】

    转自:http://blog.csdn.net/chenyu105/article/details/7720162 重点关注关中断的情况.临时做了一个版本,在CPU 0上监控所有非0 CPU的时钟中断 ...

  10. 浅谈linux的死锁检测 【转】

    转自:http://www.blog.chinaunix.net/uid-25942458-id-3823545.html 死锁:就是多个进程(≥2)因为争夺资源而相互等待的一种现象,若无外力推动,将 ...