• 引子(模拟)


    模拟题,很水啦.............

    判断好字符就好了

      1 #include<iostream>
      2 #include<cstdio>
      3 #include<cstring>
      4 #include<string>
      5 #include<algorithm>
      6 #include<cmath>
      7 #include<set>
      8 #include<vector>
      9 #include<map>
     10 #include<queue>
     11 #define MAXN 1101
     12 using namespace std;
     13 int ans[MAXN*MAXN];
     14 priority_queue<pair<int,int> >q;
     15 struct no{int x1;int y1;int x2;int y2;}T[MAXN*MAXN];
     16 char a[MAXN][MAXN];
     17 int belong[MAXN][MAXN];
     18 int conn[MAXN*10][1001];
     19 int m,n;
     20 void find(int i,int j,int x)
     21 {
     22      int l=j-1,r=j+1;
     23      while(a[i][l]!='|')
     24      {
     25            l--;
     26      }
     27      while(a[i][r]!='|')
     28      {
     29            r++;
     30      }
     31      T[x].y1=l;T[x].y2=r;
     32      int up=i-1,dow=i+1;
     33      while(a[up][j]!='-')up--;
     34      while(a[dow][j]!='-')dow++;
     35      T[x].x1=up,T[x].x2=dow;
     36      for(int j=l;j<=r;++j)
     37      {
     38          belong[up][j]=x;belong[dow][j]=x;
     39      }
     40      for(int i=up;i<=dow;++i)
     41      {
     42          belong[i][l]=x;belong[i][r]=x;
     43          if(a[i][l-1]=='-')
     44          {
     45              conn[x][i]=l;
     46              //printf("conn[%d][%d]
    ",x,i);
     47          }
     48          else if(a[i][r+1]=='-')
     49          conn[x][i]=r;
     50      }
     51      //printf("T[%d].x1=%d T[%d].x2=%d T[%d].y1=%d T[%d].y2=%d
    ",x,T[x].x1,x,T[x].x2,x,T[x].y1,x,T[x].y2);
     52      return ;
     53 }
     54 int BFS(int x,int y)
     55 {
     56      //printf("x=%d y=%d
    ",x,y);
     57      int l=x,r=y,ok_l=0,ok_r=0;//0 向左 1 向下
     58      if(a[l][r+1]=='-')ok_r=1;
     59      if(a[l][r-1]=='-')ok_r=-1;
     60      l+=ok_l;r+=ok_r;
     61      //printf("ok_r=%d %d %d
    ",ok_r,l,r);
     62      while(belong[l][r]==0)
     63      {
     64            //printf("l=%d r=%d
    ",l,r);
     65            r+=ok_r;
     66            l+=ok_l;
     67            if(a[l][r]=='+')
     68            {
     69                if(ok_r!=0)
     70                {
     71                   ok_r=0;
     72                   ok_l=1;    
     73                }
     74                else if(ok_l!=0)
     75                {
     76                    ok_l=0;
     77                    if(a[l][r+1]=='-')ok_r=1;
     78                    else ok_r=-1;
     79                }
     80            }
     81      }
     82      return belong[l][r];
     83 }
     84 void DFS(int x)
     85 {
     86     for(int i=T[x].x2;i>=T[x].x1;--i)
     87     {
     88         if(conn[x][i]!=0)
     89         {
     90            int nxt=BFS(i,conn[x][i]);
     91            //printf("nxt=%d
    ",nxt);
     92            DFS(nxt);     
     93         }
     94     }
     95     ans[++ans[0]]=x;
     96     //printf("ans=%d
    ",x);
     97 }
     98 signed main()
     99 {
    100      scanf("%d%d",&n,&m);
    101      for(int i=1;i<=n;++i)
    102      {
    103          scanf("%s",a[i]+1);
    104      }
    105      for(int i=1;i<=n;++i)
    106      {
    107          int j=1;
    108          while(j<=m)
    109          {
    110              int x=0;int r=j;
    111              if(a[i][j]>='0'&&a[i][j]<='9')
    112              {
    113                  while(a[i][r]>='0'&&a[i][r]<='9')
    114                  {
    115                        x=x*10+a[i][r]-'0';
    116                        r++;
    117                  }
    118                  find(i,j,x);
    119              }
    120              j=r;j++;
    121          }
    122      }
    123      DFS(1);
    124      for(int i=1;i<=ans[0];++i)
    125      {
    126          printf("%d
    ",ans[i]);
    127      }
    128 }
    View Code
  • 相关阅读:
    springboot(10)logback日志配置
    springboot(9)springboot整合redis
    springboot(8)springboot整合mybatis
    springboot(7)springboot整合freemarker和thymeleaf
    springboot(6)过滤器 监听器 拦截器
    springboot(5)单元测试及MockMVC类的使用及自定义异常处理
    springboot(4)springboot热部署插件及idea热部署及配置文件注解注入
    springboot(3)使用MultipartFile上传数据文件及项目打成jar包
    springboot(2)内置序列化框架为Jackson及springboot文件目录结构
    git rebase
  • 原文地址:https://www.cnblogs.com/Wwb123/p/11342600.html
Copyright © 2020-2023  润新知