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 ...
随机推荐
- php 获取周几
date("l"); //date就可以获取英文的星期比如Sunday date("w"); //这个可以获取数字星期比如123,注意0是星期日 获取中文星期几 ...
- Linux下iptables安全配置
Linux下配置IPTables,只开放特定端口,禁用其他网络. *filter :INPUT DROP [0:0] :FORWARD DROP [0:0] :OUTPUT ACCEPT [0:0] ...
- spoj COT2 - Count on a tree II
COT2 - Count on a tree II http://www.spoj.com/problems/COT2/ #tree You are given a tree with N nodes ...
- 几分钟内学习 Clojure
1.基本例子 ; 分号作为注释的开始 ; Clojure 用一种把元素用括号括起来的像列表一样的方式来书写,元素之间用空格隔开 ; clojure 解释器会把第一个元素当做是函数或者宏调用,其他的都作 ...
- 最简单的图文教程,几步完成Git的公私钥配置
操作的前提是,你有git账号,并且在自己的电脑上已经装好了TorToiseGit工具.下面开始简单的教程: 第一步:Windows-->所有程序-->TortoiseGit-->Pu ...
- 【zoj3645】高斯消元求解普通线性方程
题意: 给你一个方程组(含有12个方程),求(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11) 方程组的形式是一个二次方程组 (ai1-x1)^2 + (ai2-x2)^2 +( ...
- BigDecimal的用法详解
BigDecimal 由任意精度的整数非标度值 和32 位的整数标度 (scale) 组成.如果为零或正数,则标度是小数点后的位数.如果为负数,则将该数的非标度值乘以 10 的负scale 次幂. f ...
- Optimizing subroutine calls based on architecture level of called subroutine
A technique is provided for generating stubs. A processing circuit receives a call to a called funct ...
- PHP下载APK文件
PHP下载APK文件(代码如下) /** * //这里不要随便打印文字,否则会影响输出的文件的 * (例如下载没问题,但是apk安装时候提醒解析安装包错误) * @return array */ pu ...
- ACdream 1157 Segments CDQ分治
题目链接:https://vjudge.net/problem/ACdream-1157 题意: Problem Description 由3钟类型操作: 1)D L R(1 <= L < ...