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[20][20][10][6],d[20][20][10];
int dir_id(char c){
    return strchr(dirs,c)-dirs;
}
int turn_id(char c){
    return strchr(turns,c)-turns;
}
int dr[]={-1,0,1,0};
int dc[]={0,1,0,-1};
struct Node{
    int r,c,dir;
};
Node p[20][20][10];
Node walk(Node u,int turn){
    int dir=u.dir;
    if (turn==1) dir=(dir+3)%4;
    if (turn==2) dir=(dir+1)%4;
    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,0,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[0]);
            for (int i=1;i<temp.size();i++){
                int turn=turn_id(temp[i]);
                has_edge[x][y][dir][turn]=1;
            }
        }
    }
}
int inside(int x,int y){
    return (x>0&&y>0)?1:0;
}
void printf_ans(Node u){
    vector<Node> nodes;
    while (1){
        nodes.push_back(u);
        if (d[u.r][u.c][u.dir]==0) 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=0;
    for (int i=nodes.size()-1;i>=0;i--){
        if (cnt%10==0) printf(" ");
        printf(" (%d,%d)",nodes[i].r,nodes[i].c);
        if (++cnt %10==0) printf("\n");
    }
    if (nodes.size()%10!=0) printf("\n");
}
void solve(){
    queue<Node>q;
    memset(d,-1,sizeof(d));
    Node u;
    u.r=r1;u.c=c1;u.dir=dir;
    d[u.r][u.c][u.dir]=0;
    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=0;i<3;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]<0){
                d[v.r][v.c][v.dir]=d[u.r][u.c][u.dir]+1;
                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大部分是刘汝佳第二部书上的

时间: 2024-08-05 23:18:38

UVa816,Ordering Tasks,WA的相关文章

Django-rest-framework(六)filter,ordering,search

filter queryset 使用request.user相关的queryset class PurchaseList(generics.ListAPIView): serializer_class = PurchaseSerializer def get_queryset(self): """ 返回purchaser 是request.user的queryset """ user = self.request.user return Purc

拓扑排序(Topological Order)UVa10305 Ordering Tasks

2016/5/19 17:39:07 拓扑排序,是对有向无环图(Directed Acylic Graph , DAG )进行的一种操作,这种操作是将DAG中的所有顶点排成一个线性序列,使得图中的任意一对顶点u,v满足如下条件: 若边(u,v)∈E(G),则在最终的线性序列中出现在v的前面 好了,说人话:拓扑排序的应用常常和AOV网相联系,在一个大型的工程中,某些项目不是独立于其他项目的,这意味着这种非独立的项目的完成必须依赖与其它项目的完成而完成,不妨记为u,v,则若边(u,v)∈E(G),代

UVA10305 Ordering Tasks【DFS】【拓扑排序】

Ordering Tasks Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been

Ordering Tasks From:UVA, 10305(拓扑排序)

Ordering Tasks From:UVA, 10305 Submit Time Limit: 3000 MS      Special Judge John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The inpu

M - Ordering Tasks

M - Ordering Tasks Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description   John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already be

UVa 10305 - Ordering Tasks 拓扑排序题解

Topological Sort题解.本题是简单的入门题目. Topological Sort的思想很简单,就是按没有入度的点,先输出,然后删除这个点的出度.然后输出下一组没有入度的点. 如何实现也是很简单的: 这里使用邻接表,建图的时候反过来建图,建立一个入度邻接表. 然后使用一个vis数组,记录访问过的节点,也可以根据这个信息知道哪些是已经输出的点,这个时候这些点的入度可以不算为当前入度了. #include <stdio.h> #include <vector> using

性能测试指标:TPS,吞吐量,并发数,响应时间

性能测试指标:TPS,吞吐量,并发数,响应时间 常用的网站性能测试指标有:TPS.吞吐量.并发数.响应时间.性能计数器等. 并发数并发数是指系统同时能处理的请求数量,这个也是反应了系统的负载能力. 响应时间响应时间是一个系统最重要的指标之一,它的数值大小直接反应了系统的快慢.响应时间是指执行一个请求从开始到最后收到响应数据所花费的总体时间. 吞吐量吞吐量是指单位时间内系统能处理的请求数量,体现系统处理请求的能力,这是目前最常用的性能测试指标. QPS(每秒查询数).TPS(每秒事务数)是吞吐量的

C#实现对站点、程序池状态的监控,以及URL能正常返回的监控,状态异常,邮件预警

需求:自动化组提出需要,要对IIS上的站点进行监控,异常停止后报警 需求分析:这站点的运行正常需要多方面的监控,如站点,程序池,资源,所以针对这需求做了三方面的监控. 站点状态的监控 站点对应的程序池的监控 URL的监控,监控url能返回200的状态码 数据库设计: 页面展示: 配置list页 配置Detail页 预警邮件: 核心代码: 配置页面代码 index.cshtml @model IEnumerable<Ctrip.Hotel.QA.Platform.Data.Dao.EnvRunSt

完善Article表,增加分类,和详细页面

我们为一个web应用增加新功能时的步骤是:修改model.py,更新数据库,然后编写视图函数来处于http请求,接着修改模板用于显示内容.如果增加了新的模板,就要增加 新的url. 我们的Article表中目前就存了标题,文章内容,和创建时间,这肯定是远远不够的,现在我们要给Article表增加更多的内容-以下是改变后的内容,我们增加了修改时间,分类,和摘要,分类是作为一个外键.外键是一种一对多的形式,就是一篇文章对应一个分类,而一个分类下可以有多篇文章,我们也创建了另一个类别的表. class