神奇的场上原码

    #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
//red 0 yellow 1 nothing 2
using namespace std;
int map[101][101],n,m,ans=0x7fffffff,vis[101][101];
const int px[4]={1,-1,0,0},py[4]={0,0,1,-1};
struct node{
int lx,ly,x,y,step;
}chx[101][101];
int get_step(int lx,int ly,int x,int y,int fx,int fy,int s){
if(map[x][y]==0x7f7f7f7f and map[fx][fy]==0x7f7f7f7f)return 0x7fffffff;
if(map[x][y]==map[fx][fy])return 0;
if(map[x][y]+map[fx][fy]==1)return 1;
if(map[x][y]==0x7f7f7f7f)return map[lx][ly]==map[fx][fy]?0:1;
if(map[fx][fy]==0x7f7f7f7f)return 2;
}
void bfs(int xx,int yy){
queue<node> q;
q.push(node{-1,-1,xx,yy,0});
vis[xx][yy]=0;
while(!q.empty()){
int lx=q.front().lx;
int ly=q.front().ly;
int x=q.front().x;
int y=q.front().y;
int step=q.front().step;
q.pop();
if((x==n and y==n) or (step>vis[x][y])){
continue;
}
for(int i=0;i<=3;i++){
int fx=x+px[i];
int fy=y+py[i];
if(fx<=n and fx>=1 and fy<=n and fy>=1){
int fs=get_step(lx,ly,x,y,fx,fy,step);
if(fs!=0x7fffffff){
if(vis[fx][fy]>step+fs){
vis[fx][fy]=step+fs;
q.push(node{x,y,fx,fy,step+fs});
}
}
}
}
}
}
int main(){
// freopen("chess.in","r",stdin);
// freopen("chess.out","w",stdout);
memset(map,0x7f,sizeof(map));
memset(vis,0x7f,sizeof(vis));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
scanf("%d",&map[x][y]);
}
bfs(1,1);
printf("%d",vis[n][n]==0x7f7f7f7f?-1:vis[n][n]);
return 0;
}

现在再贴一个堆广搜(但是可能会被恶心地卡掉

    #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
const int INF=0x7f7f7f7f,px[4]={1,-1,0,0},py[4]={0,0,1,-1};
int n,m,map[101][101],d[101][101];
struct node{
int lx,ly,x,y,step;
bool operator < (const node & b)const{
return step>b.step;
}
};
int get_step(int lx,int ly,int x,int y,int fx,int fy){
if(map[x][y]==INF){
if(map[fx][fy]==INF)return INF;
if(map[lx][ly]==map[fx][fy]){
return 0;
} else return 1;
}
if(map[fx][fy]==INF)return 2;
if(map[x][y]==map[fx][fy]){
return 0;
}else return 1;
}
void bfs(int xx,int yy){
priority_queue<node> q;
q.push((node){-1,-1,xx,yy,0});
d[xx][yy]=0;
while(!q.empty()){
int lx=q.top().lx;
int ly=q.top().ly;
int x=q.top().x;
int y=q.top().y;
int step=q.top().step;
q.pop();
if(x==n and y==n){
return;
}
for(int i=0;i<=3;i++){
int fx=x+px[i];
int fy=y+py[i];
if(fx<=n and fx>=1 and fy<=n and fy>=1){
int fs=get_step(lx,ly,x,y,fx,fy);
if(fs!=INF and step+fs<d[fx][fy]){
d[fx][fy]=step+fs;
q.push((node){x,y,fx,fy,step+fs});
}
}
}
}
}
int main(){
memset(map,0x7f,sizeof(map));
memset(d,0x7f,sizeof(d));
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
scanf("%d",&map[x][y]);
}
bfs(1,1);
printf("%d\n",d[n][n]==0x7f7f7f7f?-1:d[n][n]);
return 0;
}

Noip2017 普及 T3 Chess的更多相关文章

  1. noip2017普及 兔纸游玩记

    初中的最后一场比赛...就这样结束了吧...QAQ时间...真够快的qwq 应该是初中的最后一篇游记了吧,尽量写多点... 这是一篇,初三 老年菜兔的 noip2017 普及游玩记吧! DAY 0  ...

  2. NOIP2017普及组解题报告

    刚参加完NOIP2017普及,只考了210,于是心生不爽,写下了这篇解题报告...(逃 第一次写博,望dalao们多多指导啊(膜 第一题score,学完helloworld的人也应该都会吧,之前好多人 ...

  3. NOIP2017 Day1 T3 逛公园

    NOIP2017 Day1 T3 更好的阅读体验 题目描述 策策同学特别喜欢逛公园.公园可以看成一张\(N\)个点\(M\)条边构成的有向图,且没有 自环和重边.其中1号点是公园的入口,\(N\)号点 ...

  4. [NOIP2017普及组]跳房子(二分,单调队列优化dp)

    [NOIP2017普及组]跳房子 题目描述 跳房子,也叫跳飞机,是一种世界性的儿童游戏,也是中国民间传统的体育游戏之一. 跳房子的游戏规则如下: 在地面上确定一个起点,然后在起点右侧画 nn 个格子, ...

  5. 「LOJ 6373」NOIP2017 普及组题目大融合

    NOIP2017 普及组题目大融合 每个读者需要有某个后缀的书,可以暴力map,复杂度\(o(9*nlog(n))\),也可以反串建trie树,复杂度\(o(9*n)\). 故可以求出需要的最少的RM ...

  6. P3956 [NOIP2017 普及组] 棋盘

    P3956 [NOIP2017 普及组] 棋盘 题目 题目描述 有一个 m×m 的棋盘,棋盘上每一个格子可能是红色.黄色或没有任何颜色的.你现在要从棋盘的最左上角走到棋盘的最右下角. 任何一个时刻,你 ...

  7. NOIP2017普及组比赛总结

    期中考总结&NOIP2017总结 2017年11月11日,我第二次参加NOIP普及组复赛.上一年,我的得分是250分,只拿到了二等奖.我便把目标定为拿到一等奖,考到300分以上. 早上8点多, ...

  8. [NOIP2017普及组]棋盘

    题目 题目描述 有一个m × m的棋盘,棋盘上每一个格子可能是红色.黄色或没有任何颜色的.你现在要从棋盘的最左上角走到棋盘的最右下角. 任何一个时刻,你所站在的位置必须是有颜色的(不能是无色的),你只 ...

  9. noip2017普及题解

    https://www.luogu.org/problemnew/show/3954 https://www.luogu.org/problemnew/show/3955 https://www.lu ...

随机推荐

  1. Jetty入门(1-2)eclipse集成jetty插件并发布运行应用

    一.eclipse集成jetty插件 1.从市场安装jetty插件 2.使用jetty插件发布应用和配置运行环境 debug配置默认共用上述run配置 3.使用jetty插件启动运行和停止运行选中的应 ...

  2. PV 动态供给 - 每天5分钟玩转 Docker 容器技术(153)

    前面的例子中,我们提前创建了 PV,然后通过 PVC 申请 PV 并在 Pod 中使用,这种方式叫做静态供给(Static Provision). 与之对应的是动态供给(Dynamical Provi ...

  3. 算法 排序lowB三人组 冒泡排序 选择排序 插入排序

    参考博客:基于python的七种经典排序算法   [经典排序算法][集锦]     经典排序算法及python实现 首先明确,算法的实质 是 列表排序.具体就是操作的列表,将无序列表变成有序列表! 一 ...

  4. Windows10+Docker搭建分布式Redis集群(SSH服务镜像)(二)

    前言:上篇文章我们搭建好了Docker,下面我们开始使用Docker创建镜像,Docker命令就不介绍了.这里宿主是Windows10,cmd的管理和后期文件的复制不是很方便,将创建支持SSH的Cen ...

  5. [翻译] TensorFlow Programmer's Guide之Frequently Asked Questions(问得频率最多的几个问题)

    目录: 特点和兼容性(Features and Compatibility) 建立一个TensorFlow图(Building a TensorFlow graph) 运行一个TensorFlow计算 ...

  6. Android P新功能特性抢先看

    2018年3月8日,Google推出了Android P Preview版本,并提供官方镜像下载. 为了让广大开发者能够及时了解Android P的新功能特性,提前为您的app进行良好适配,WeTes ...

  7. 浅析开源数据库MySQL架构

    数据库是所有应用系统的核心,故保证数据库稳定.高效.安全地运行是所有企业日常工作的重中之重.数据库系统一旦出现问题无法提供服务,有可能导致整个系统都无法继续工作.所以,一个成功的数据库架构在高可用设计 ...

  8. SQL Server 2008 R2 安装注意事项

    上个星期自己第一次安装SQL Server 2008 R2,安装失败几次,结果用了将近1天的时间安装,最后成功了. 心得:1.安装SQL Server 2008 R2时,最好在第一次就安装成功.在百度 ...

  9. [LeetCode] Shortest Completing Word 最短完整的单词

    Find the minimum length word from a given dictionary words, which has all the letters from the strin ...

  10. day 1——字典树练习

    cojs 173. 词链 ★☆   输入文件:link.in   输出文件:link.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述]给定一个仅包含小写字母的英文单词表, ...