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;

    }


  • 相关阅读:
    docker容器跑tomcat遇到的坑
    PCL 编程多个点云合成
    PCL 常用小知识
    PCL点云库中的坐标系(CoordinateSystem)
    Ubuntu14.04(64位)下gcc-linaro-arm-linux-gnueabihf交叉编译环境搭建
    Windows cmd 快捷操作
    #Pragma Pack与内存分配
    线段上的整数点个数
    基于PCL绘制模型并渲染
    rosbag数据记录及转换图片、视频
  • 原文地址:https://www.cnblogs.com/mypsq/p/4348266.html
Copyright © 2011-2022 走看看