BZOJ 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课
题目
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
.xA
...
Bx.
Sample Output
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 障碍训练课的更多相关文章
- BZOJ 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课( BFS )
BFS... 我连水题都不会写了QAQ ------------------------------------------------------------------------- #inclu ...
- bzoj 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课【spfa】
洛谷的数据毒啊 把(i,j,k)作为一个点spfa,表示点(i,j)朝向k方向,然后向四个方向转移即可 #include<iostream> #include<cstdio> ...
- 1644: [Usaco2007 Oct]Obstacle Course 障碍训练课
1644: [Usaco2007 Oct]Obstacle Course 障碍训练课 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 383 Solved ...
- 【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这个点之前 ...
- bzoj1644 [Usaco2007 Oct]Obstacle Course 障碍训练课
Description 考虑一个 N x N (1 <= N <= 100)的有1个个方格组成的正方形牧场.有些方格是奶牛们不能踏上的,它们被标记为了'x'.例如下图: . . B x . ...
- BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币( dp )
背包dp.. -------------------------------------------------------------------------------- #include< ...
- BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币
1708: [Usaco2007 Oct]Money奶牛的硬币 Description 在创立了她们自己的政权之后,奶牛们决定推广新的货币系统.在强烈的叛逆心理的驱使下,她们准备使用奇怪的面值.在传统 ...
- BZOJ 1709: [Usaco2007 Oct]Super Paintball超级弹珠
Description 奶牛们最近从著名的奶牛玩具制造商Tycow那里,买了一套仿真版彩弹游戏设备(类乎于真人版CS). Bessie把她们玩游戏草坪划成了N * N(1 <= N<= 1 ...
- bzoj 1709: [Usaco2007 Oct]Super Paintball超级弹珠【枚举】
k是1e5范围的,吗? 注意到n只有100,这意味着k去重之后之后n^2,也就是1e4! 然后就可以愉快的n^4枚举了,枚举每个格子,再枚举每个敌人,如果当前格子射不到敌人则退出,否则满足所有敌人则a ...
随机推荐
- Android实现左右滑动指引效果
本文介绍Android中实现左右滑动的指引效果. 关于左右滑动效果,我在以前的一篇博文中提到过,有兴趣的朋友可以查看:http://www.cnblogs.com/hanyonglu/archive/ ...
- linux多线程示例
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h& ...
- Java 网络编程(三) 创建和使用URL访问网络上的资源
链接地址:http://www.cnblogs.com/mengdd/archive/2013/03/09/2951877.html 创建和使用URL访问网络上的资源 URL(Uniform Reso ...
- USACO Seciton 5.4 Canada Tour(dp)
因为dp(i,j)=dp(j,i),所以令i>j. dp(i,j)=max(dp(k,j))+1(0<=k<i),若此时dp(i,j)=1则让dp(i,j)=0.(因为无法到达此状态 ...
- php Smarty详细配置
1.在Smarty官网下载 路径:https://github.com/smarty-php/smarty/releases 2.把下载下来的Smarty解压出来 3.把解压出来的Smarty里面的l ...
- [转]关于 Swift 的一点初步看法
本文转自:http://onevcat.com/2014/06/my-opinion-about-swift/ 感谢原作者 虽然四点半就起床去排队等入场,结果还是只能坐在了蛮后面的位置看着大屏幕参加了 ...
- 射频识别技术漫谈(20)——RC系列射频接口芯片
目前基于13.56MHz的射频识别技术主要有ISO14443A.ISO14443B.ISO15693和FELICA技术.针对13.56MHz的射频识别技术,NXP开发了一系列名字以RC(Radio C ...
- 以程序的方式操纵NTFS的文件权限(陈皓)
http://blog.csdn.net/haoel/article/details/2905 http://blog.sina.com.cn/s/blog_7f91494101018nmn.html
- web应用中Spring ApplicationContext的动态更新
在web应用中时常需要修改配置,并动态的重新加载ApplicationContext.比如,设置和切换数据库.以下给出一个方法,并通过代码验证可行性. 方法的基本思路是,为WebApplication ...
- MapList 自己封装的
//// Source code recreated from a .class file by IntelliJ IDEA// (powered by Fernflower decompiler)/ ...