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 ...
随机推荐
- JS闭包经典例题
上一篇文章谈论了闭包的概念和一些应用,并给出一个例题,这篇文章就此道例题进行讨论. function fun(n,o) { console.log(o); return { fun:function( ...
- iframe的一些简单记录
//获取当前所在IFrame的id var frameId = window.frameElement && window.frameElement.id || ''; //Jquer ...
- .Net Web开发中实现剪切板功能
我要实现的功能是:在列表页,通过一个按钮复制对应的文章Url,如下图: 如下代码: <a class="btn btn-success copy" href=&quo ...
- python re(正则模块)
参考文档:http://blog.csdn.net/wusuopubupt/article/details/29379367 ipython环境中,输入"?re",官方解释如下: ...
- c风格字符串函数
十一.C 风格字符串 1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat( ...
- JavaWEB开发中的/到底代表什么
- HDU 1398 Square Coins
题目大意:有面值分别为.1,4,9,.......17^2的硬币无数多个.问你组成面值为n的钱的方法数. 最简单的母函数模板题: #include <cstdio> #include &l ...
- hdoj 2896 病毒侵袭(AC自动机)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2896 思路分析:题目为模式匹配问题,对于一个给定的字符串,判断能匹配多少个模式:该问题需要静态建树,另 ...
- 快速注册Uber司机,兼职月入轻松过万
Uber是世界领先的即时用车网络平台.当前部分中国城市,Uber司机只需每周完成70单,可获得7000元的激励制度回报司机,月收入近3万元.[加入条件]1. 车辆为本地牌照2. 车龄在5年以内3. 裸 ...
- JAVA ThreadPoolExecutor(转)
原文链接:http://blog.csdn.net/historyasamirror/article/details/5961368 基础 在我看来,java比C++的一个大好处就是提供了对多线程的支 ...