zoukankan      html  css  js  c++  java
  • 111

    #include"stdio.h"
    #include"string.h"
    #include"iostream"
    using namespace std;
    const int M=41111;
    int f[M];
    struct st
    {
         int x,y;
    }node[M];
    int finde(int x,int L,char ch)
    {
         if(x!=f[x])
         {
              int t=f[x];
              f[x]=finde(f[x],L,ch);
              //printf("-->%d %d ",t,x);
              if(ch=='E')
              {
                   node[x].x=node[x].x+L;
                   node[x].y=node[x].y;
              }
              else if(ch=='W')
              {
                   node[x].x=node[x].x-L;
                   node[x].y=node[x].y;
              }
              else if(ch=='N')
              {
                   node[x].x=node[x].x;
                   node[x].y=node[x].y+L;
              }
              else if(ch=='S')
              {
                   node[x].x=node[x].x;
                   node[x].y=node[x].y-L;
              }


         }
         return f[x];
    }
    void make(int a,int b,int L,char ch)
    {
         int x=finde(a,L,ch);
         int y=finde(b,L,ch);
         if(x!=y)
         {
              f[y]=x;
              if(ch=='E')
              {
                   node[y].x=node[x].x+L;
                   node[y].y=node[x].y;
              }
              else if(ch=='W')
              {
                   node[y].x=node[x].x-L;
                   node[y].y=node[x].y;
              }
              else if(ch=='N')
              {
                   node[y].x=node[x].x;
                   node[y].y=node[x].y+L;
              }
              else if(ch=='S')
              {
                   node[y].x=node[x].x;
                   node[y].y=node[x].y-L;
              }
         }


    }
    int main()
    {
         int i,m,n,a,b,L;
         char ch[3];
         while(scanf("%d%d",&n,&m)!=-1)
         {
              for(i=1;i<=n;i++)
                   f[i]=i;
              while(m--)
              {
                   scanf("%d%d%d%s",&a,&b,&L,ch);
                   make(a,b,L,ch[0]);
              }
              for(i=1;i<=n;i++)
              printf("%d %d ",node[i].x,node[i].y);
         }
         return 0;

    }


  • 相关阅读:
    json解析与序列化
    js实现千位分隔符
    map.(parseInt)方法详解
    js实现翻转一个字符串
    一个满屏 品 字布局 如何设计?
    new操作符实现过程
    常见的函数式编程模型
    Azure DevOps Server 2019 (TFS)安装教程
    在Azure DevOps Server (TFS) 中修改团队项目名称
    你好,Azure DevOps Server 2019;再见,Team Foundation Server
  • 原文地址:https://www.cnblogs.com/mypsq/p/4348266.html
Copyright © 2011-2022 走看看