UVa816,Ordering Tasks,WA
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
const char*dirs="NESW";
const char*turns="FLR";
int r0,c0,dir,r1,c1,r2,c2,has_edge[][][][],d[][][];
int dir_id(char c){
return strchr(dirs,c)-dirs;
}
int turn_id(char c){
return strchr(turns,c)-turns;
}
int dr[]={-,,,};
int dc[]={,,,-};
struct Node{
int r,c,dir;
};
Node p[][][];
Node walk(Node u,int turn){
int dir=u.dir;
if (turn==) dir=(dir+)%;
if (turn==) dir=(dir+)%;
Node t;
t.r=u.r+dr[dir];t.c=u.c+dc[dir];t.dir=dir;
return t;
}
int init(){
char ch;
memset(d,,sizeof(d));
cin>>r0>>c0>>ch>>r2>>c2;
int dir=dir_id(ch);
r1=r0+dr[dir];c1=c0+dc[dir];
Node t;
t.r=r1;t.c=c1;t.dir=dir;
p[r1][c1][dir]=t;
int x,y;
while (cin>>x&&x){
cin>>y;
string temp;
while (cin>>temp&&temp!="*"){
dir=dir_id(temp[]);
for (int i=;i<temp.size();i++){
int turn=turn_id(temp[i]);
has_edge[x][y][dir][turn]=;
}
}
}
}
int inside(int x,int y){
return (x>&&y>)?:;
}
void printf_ans(Node u){
vector<Node> nodes;
while (){
nodes.push_back(u);
if (d[u.r][u.c][u.dir]==) break;
u=p[u.r][u.c][u.dir];
}
Node t;
t.r=r0;t.c=c0;t.dir=dir;
nodes.push_back(t);
int cnt=;
for (int i=nodes.size()-;i>=;i--){
if (cnt%==) printf(" ");
printf(" (%d,%d)",nodes[i].r,nodes[i].c);
if (++cnt %==) printf("\n");
}
if (nodes.size()%!=) printf("\n");
}
void solve(){
queue<Node>q;
memset(d,-,sizeof(d));
Node u;
u.r=r1;u.c=c1;u.dir=dir;
d[u.r][u.c][u.dir]=;
q.push(u);
while (!q.empty()){
Node u=q.front();q.pop();
if (u.r==r2&&u.c==c2){
printf_ans(u);
return;
}
for (int i=;i<;i++){
Node v=walk(u,i);
if (has_edge[u.r][u.c][u.dir][i]&&inside(v.r,v.c)&&d[v.r][v.c][v.dir]<){
d[v.r][v.c][v.dir]=d[u.r][u.c][u.dir]+;
p[v.r][v.c][v.dir]=u;
q.push(v);
}
}
}
printf("No Solution Possible\n");
}
int main()
{
string Name;
while (cin>>Name&&Name!="END"){
cout<<Name<<endl;
init();
solve();
}
}
WA代码,至今不知道错哪了........哪位大神若是有时间帮我看看吧,code大部分是刘汝佳第二部书上的
UVa816,Ordering Tasks,WA的更多相关文章
- uva10905同一思路的两种做法,前一种WA,后一种AC
这道题应该算一道普通的排序吧,实际上就是另一种形式地比大小,自己最开始是用int型存,后来觉着不行,改用long,结果还是WA,这是第一个程序. 第二个程序是改用string处理,确实比int方便很多 ...
- Django-rest-framework(六)filter,ordering,search
filter queryset 使用request.user相关的queryset class PurchaseList(generics.ListAPIView): serializer_class ...
- locust===官方说明文档,关于tasks
安装: >>> pip install locust locust在官方simple_code中如下: from locust import HttpLocust, TaskSet ...
- 【ACM】那些年,我们挖(WA)过的最短路
不定时更新博客,该博客仅仅是一篇关于最短路的题集,题目顺序随机. 算法思想什么的,我就随便说(复)说(制)咯: Dijkstra算法:以起始点为中心向外层层扩展,直到扩展到终点为止.有贪心的意思. 大 ...
- 拓扑排序(Topological Order)UVa10305 Ordering Tasks
2016/5/19 17:39:07 拓扑排序,是对有向无环图(Directed Acylic Graph , DAG )进行的一种操作,这种操作是将DAG中的所有顶点排成一个线性序列,使得图中的任意 ...
- Ordering Tasks(拓扑排序+dfs)
Ordering Tasks John has n tasks to do. Unfortunately, the tasks are not independent and the executio ...
- UVA.10305 Ordering Tasks (拓扑排序)
UVA.10305 Ordering Tasks 题意分析 详解请移步 算法学习 拓扑排序(TopSort) 拓扑排序的裸题 基本方法是,indegree表示入度表,vector存后继节点.在tops ...
- Ordering Tasks UVA - 10305 图的拓扑排序
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- 性能测试指标:TPS,吞吐量,并发数,响应时间
性能测试指标:TPS,吞吐量,并发数,响应时间 常用的网站性能测试指标有:TPS.吞吐量.并发数.响应时间.性能计数器等. 并发数并发数是指系统同时能处理的请求数量,这个也是反应了系统的负载能力. 响 ...
随机推荐
- 201521123060《Java程序设计》第2周学习总结
1. 本周学习总结 a.进一步熟悉了Eclipse的使用和java程序的编写: b.学习了java数据的基本类型:整数类型,浮点类型等: c.学习了算数运算符,赋值运算符,位运算符,关系运算符,逻辑运 ...
- Markdown编辑后
一个例子: 例子开始 1. 本章学习总结 今天主要学习了三个知识点 封装 继承 多态 2. 书面作业 Q1. java HelloWorld命令中,HelloWorld这个参数是什么含义? 今天学了一 ...
- paxos 算法原理学习
下面这篇关于paxos分布式一致性的原理,对入门来说比较生动有趣,可以加深下影响.特此博客中记录下. 讲述诸葛亮的反穿越 0.引子 一日,诸葛亮找到刘备,突然献上一曲<独角戏>,而后放声大 ...
- Eclipse读取含有extjs的项目文件时卡死或者编写ExtJS时卡
新建一个Eclipse或MyEclipse项目时,关掉验证. 项目右键-->Properties-->Builders--> 不勾选(JavaScript Validator.Val ...
- 自定义Django的中间件
分析Django的生命周期,我们知道所有的http请求都要经过Django的中间件. 假如现在有一个需求,所有到达服务端的url请求都在系统中记录一条日志,该怎么做呢? Django的中间件的简介 D ...
- [python学习笔记] python程序打包成exe文件
安装 pyinstaller pip3 install pyinstaller 命令 pyinstaller -F -w -i ../ui/icon.ico --clean ../Login.py 参 ...
- Hadoop安全(1)——————美团Hadoop安全实践
http://tech.meituan.com/hadoop-security-practice.html 前言 在2014年初,我们将线上使用的 Hadoop 1.0 集群切换到 Hadoop 2. ...
- 关于CSDN, cnblog, iteye和51cto四个博客网站的比较与分析
http://blog.csdn.net/pkucl1/article/details/6629819 CSDN: http://blog.csdn.net/ cnblog: http://www ...
- Free Goodies UVA - 12260 贪心
Free Goodies Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Submit ...
- Ubuntu16笔记本双显卡安装NVIDIA驱动
blockquote { direction: ltr; color: rgb(0, 0, 0) } blockquote.western { font-family: "Liberatio ...