题目链接: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. Kafka消息delivery可靠性保证(Message Delivery Semantics)

    原文见:http://kafka.apache.org/documentation.html#semantics kafka在生产者和消费者之间的传输是如何保证的,我们可以知道有这么几种可能提供的de ...

  2. LightOJ 1419 – Necklace Polya计数+费马小定理求逆元

    题意:给你n个珠子可以染成k种颜色,旋转后相同的视为一种,问共有几种情况 思路:开始按照一般的排列组合做发现情况太多且要太多运算,查了下发现此题是组合中Polya定理模板题- 学的浅只能大致一说公式S ...

  3. C11性能之道:转移和转发

    1.move C++11中可以将左值强制转换为右值,从而避免对象的拷贝来提升性能.move将对象的状态或者所有权从一个对象转移到另一个对象,没有内存拷贝.深拷贝和move的区别如图: 从图可以看出,深 ...

  4. PHP扩展--Oracle客户端(oci8)安装

    下载Oracle客户端 官方下载地址: Linux X86-64 同意协议,下载以下文件: oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm ...

  5. asyncio Lock,Queue

    # # total = 0 # # async def add(): # #1. dosomething1 # #2. io操作 # # 1. dosomething3 # global total ...

  6. EntitySpace 常用语句

    EntitySpace 这个是很早期的ORM框架,最近发现这个破解的也都不能用了.有谁知道能用的,联系我. 1. where带几个条件的 query.Where(query.ProductTempSt ...

  7. 20151024_002_C#基础知识(ArrayList,Hashtable,List,Dictionary)

    1:ArrayList 和 Hashtable(哈希表) 1.1:ArrayList ArrayList list = new ArrayList(); list.Add(); list.AddRan ...

  8. javascript性能

    1.js文件放在底部 js文件具有阻塞机制,放在头部,需要等待js下载解析完毕之后才能下载渲染页面,因此需要放在底部

  9. Caffe学习笔记4图像特征进行可视化

    Caffe学习笔记4图像特征进行可视化 本文为原创作品,未经本人同意,禁止转载,禁止用于商业用途!本人对博客使用拥有最终解释权 欢迎关注我的博客:http://blog.csdn.net/hit201 ...

  10. MySQL多线程复制故障(slave_pending_jobs_size_max)

    MySQL多线程复制故障(slave_pending_jobs_size_max) http://www.xuchanggang.cn/archives/1079.html