题目

1644: [Usaco2007 Oct]Obstacle Course 障碍训练课

Time Limit: 5 Sec  Memory Limit: 64 MB

Description

考虑一个 N x N (1 <= N <= 100)的有1个个方格组成的正方形牧场。有些方格是奶牛们不能踏上的,它们被标记为了'x'。例如下图:

. . B x .
. x x A .
. . . x .
. x . . .
. . x . .

贝茜发现自己恰好在点A处,她想去B处的盐块舔盐。缓慢而且笨拙的动物,比如奶牛,十分讨厌转弯。尽管如此,当然在必要的时候她们还是会转弯的。对于一个给定的牧场,请你计算从A到B最少的转弯次数。开始的时候,贝茜可以使面对任意一个方向。贝茜知道她一定可以到达。

Input

第 1行: 一个整数 N 行

2..N + 1: 行 i+1 有 N 个字符 ('.', 'x', 'A', 'B'),表示每个点的状态。

Output

行 1: 一个整数,最少的转弯次数。

Sample Input

3
.xA
...
Bx.

Sample Output

2

HINT

 

Source

题解

这是一个宽搜,只有在转弯的时候才需要将花费+1。感觉有点烦不想写了QAQ。

代码

 /*Author:WNJXYK*/
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int T;
int n,m,w;
struct Edge{
int v;
int t;
int nxt;
Edge(){}
Edge(int a,int b,int c){
v=a;t=b;nxt=c;
}
};
Edge e[];
int nume;
int head[]; inline void addSingleEdge(int x,int y,int w){
e[++nume]=Edge(y,w,head[x]);
head[x]=nume;
}
inline void addEdge(int x,int y,int w){
addSingleEdge(x,y,w);
addSingleEdge(y,x,w);
} queue<int> que;
int dist[];
bool inque[];
int intime[]; inline void solve(){
bool isPrint=false;
while(!que.empty()) que.pop();
memset(dist,/,sizeof(dist));
memset(inque,false,sizeof(inque));
memset(intime,,sizeof(intime));
que.push();
dist[]=;
inque[]=true;
intime[]++;
while(!que.empty()){
int now=que.front();
que.pop();
for (int i=head[now];i;i=e[i].nxt){
int v=e[i].v;int w=e[i].t;
if (dist[v]>dist[now]+w){
intime[v]++;
if (intime[v]>n){
printf("YES\n");
isPrint=true;
break;
}
dist[v]=dist[now]+w;
if (!inque[v]){
inque[v]=true;
que.push(v);
}
}
}
if (isPrint) break;
inque[now]=false;
}
if (isPrint==false) printf("NO\n");
}
inline void read(){
scanf("%d%d%d",&n,&m,&w);
memset(head,,sizeof(head));
nume=;
for (int i=;i<=m;i++){
int x,y,t;
scanf("%d%d%d",&x,&y,&t);
addEdge(x,y,t);
}
for (int i=;i<=w;i++){
int x,y,t;
scanf("%d%d%d",&x,&y,&t);
addSingleEdge(x,y,-t);
}
} int main(){
scanf("%d",&T);
for (;T--;){
read();
solve();
}
return ;
}

BZOJ 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课的更多相关文章

  1. BZOJ 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课( BFS )

    BFS... 我连水题都不会写了QAQ ------------------------------------------------------------------------- #inclu ...

  2. bzoj 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课【spfa】

    洛谷的数据毒啊 把(i,j,k)作为一个点spfa,表示点(i,j)朝向k方向,然后向四个方向转移即可 #include<iostream> #include<cstdio> ...

  3. 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课

    1644: [Usaco2007 Oct]Obstacle Course 障碍训练课 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 383  Solved ...

  4. 【BZOJ】1644: [Usaco2007 Oct]Obstacle Course 障碍训练课(bfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1644 这和原来一题用dp来做的bfs很像啊orz.. 我们设f[i][j][k]代表i,j这个点之前 ...

  5. bzoj1644 [Usaco2007 Oct]Obstacle Course 障碍训练课

    Description 考虑一个 N x N (1 <= N <= 100)的有1个个方格组成的正方形牧场.有些方格是奶牛们不能踏上的,它们被标记为了'x'.例如下图: . . B x . ...

  6. BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币( dp )

    背包dp.. -------------------------------------------------------------------------------- #include< ...

  7. BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币

    1708: [Usaco2007 Oct]Money奶牛的硬币 Description 在创立了她们自己的政权之后,奶牛们决定推广新的货币系统.在强烈的叛逆心理的驱使下,她们准备使用奇怪的面值.在传统 ...

  8. BZOJ 1709: [Usaco2007 Oct]Super Paintball超级弹珠

    Description 奶牛们最近从著名的奶牛玩具制造商Tycow那里,买了一套仿真版彩弹游戏设备(类乎于真人版CS). Bessie把她们玩游戏草坪划成了N * N(1 <= N<= 1 ...

  9. bzoj 1709: [Usaco2007 Oct]Super Paintball超级弹珠【枚举】

    k是1e5范围的,吗? 注意到n只有100,这意味着k去重之后之后n^2,也就是1e4! 然后就可以愉快的n^4枚举了,枚举每个格子,再枚举每个敌人,如果当前格子射不到敌人则退出,否则满足所有敌人则a ...

随机推荐

  1. Open virtual effects in Ubuntu 12.04LTS

    Need install below packages: compiz compiz-core compiz-fusion-plugins-extra+ compiz-fusion-plugins-m ...

  2. iOS 切割图片

    - (UIImage *)CutImageWithImage:(UIImage *)image withRect:(CGRect)rect { //使用CGImageCreateWithImageIn ...

  3. LeetCode Backpack

    Given n items with size Ai, an integer m denotes the size of a backpack. How full you can fill this ...

  4. 在Mac pro上如何配置adb命令?

    在Mac pro上如何将Android SDK的adb命令添加到环境变量中,这里将进行说明! 方法/步骤 1 启动终端,可以在Spotlight中搜索“终端” 2 进入当前用户的HOME目录,命令如下 ...

  5. php 不能同时提交form

    注意:提交form到相应的页面时,不能在form中嵌套一个form,否则,不能提交

  6. Tensorflow 神经网络

    Tensorflow让神经网络自动创造音乐 前几天看到一个有意思的分享,大意是讲如何用Tensorflow教神经网络自动创造音乐.听起来好好玩有木有!作为一个Coldplay死忠粉,第一想法就是自动生 ...

  7. Wmic-linux

    Description Windows Management Instrumentation Command-line (WMIC) uses Windows Management Instrumen ...

  8. PCB抄板评估需要关注的因素

    减少PCB抄板的反复是可能的,但这依赖于抄板前期工作的完成情况.多数时候,越是到产品抄板的后期越容易发现问题,更为痛苦的是要针对发现的问题进行更改.然而,尽管许多人都清楚这个经验法则,但实际情况却是另 ...

  9. 从事web前端两年半后的迷茫

    做了两年半的重构,突然有种迷茫的感觉,好像瓶颈了,不知道自己该怎么继续走下去,以前刚毕业的时候,总觉得自己有好多的东西要学在前端方面,所以有那个促使自己去学习的动力,每当没工作任务的时候,自己总是去主 ...

  10. kinect for windows - SkeletonBasics-D2D详解之一

    之前的文章介绍了深度图的获取,但是深度图只是提供了一些数据,这些数据给上层应用使用还是偏底层一些,我们希望在这个基础上,获取一些信息,比如手挥动,人跑步,或者运动等等,那么这个文章开始我们来讲述kin ...