神奇的场上原码

    #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. Python系列-python文件操作

    原链接:https://blog.csdn.net/m0_37745438/article/details/79573414 python提供了一系列方法来对文件进行读取.写入等操作 一.打开文件的方 ...

  2. flask 操作mysql的两种方式-sql操作

    flask 操作mysql的两种方式-sql操作 一.用常规的sql语句操作 # coding=utf-8 # model.py import MySQLdb def get_conn(): conn ...

  3. PHP多个一维数组合并成二维数组的简易方法

    当我们需要进行数组遍历数据的时候,需要将多个一维数组进行二维的转换,方法很简单.如下: <?php $a= array('张三','李四','王五'); $b= array ('23','24' ...

  4. Oracle表空间的管理方式

    解释说明:表空间是一个逻辑概念:=> oracle 逻辑概念段区块管理方式: number one => tablespace number two=> segments Oracl ...

  5. 设计APP时我们该怎么做

    不得不承认,手机APP已经渗透到我们的生活中,根据数据统计,人们每天平均有3.9个小时是花费在手机APP的使用上的,可以预见,手机APP正在改变我们的生活.手机APP受到人们的欢迎,很多商家也看到了其 ...

  6. 初探java对象比较

    判断两个对象的属性值是否相等的方法, class Book{ private String title; private double price; public Book(String title, ...

  7. SSO-单点统一登录系统的设计与实现

    本文主要基于web类应用展开讨论,提供的是一种通用机制和方法,所以不论何种技术栈都可进行相应的具体实现. 实现目标 可以在相同或跨域环境下完成各应用的统一登录/注销 方案原理 本质上是采用了web应用 ...

  8. [LeetCode] Accounts Merge 账户合并

    Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...

  9. [LeetCode] 01 Matrix 零一矩阵

    Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance b ...

  10. UVALive - 3027:Corporative Network

    加权并查集 #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring&g ...