zoukankan      html  css  js  c++  java
  • 牛客寒假5-I.炫酷镜子

    链接:https://ac.nowcoder.com/acm/contest/331/I

    题意:

    小希拿到了一个镜子块,镜子块可以视为一个N x M的方格图,里面每个格子仅可能安装`\`或者`/`的镜子,会反射90°光线,也可能没有安装镜子,使用`.`代替。

    但她看不清楚里面的镜子构造是怎样的。

    你是这块镜子块的主人,所以你想计算这块镜子块(从输入的上方往下射入光线)从左到右每一格射入依次分别会从最下面的哪一格子射出,如果无法射出,输出-1。

    思路:

    模拟。出了范围判断是在最下面。

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN = 500+10;
    
    int Next[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    char Mirror[MAXN][MAXN];
    
    int main()
    {
        int n,m;
        cin >> n >> m;
        for (int i = 1;i <= n;i++)
        {
            for (int j = 1;j <= m;j++)
                cin >> Mirror[i][j];
        }
    
    
        for (int i = 1;i <= m;i++)
        {
            int dir = 2;
            int x = 1,y = i;
            while (x > 0 && x <= n && y > 0 && y <= m)
            {
                if (Mirror[x][y] == '\')
                {
                    if (dir == 0)
                        dir = 3;
                    else if (dir == 1)
                        dir = 2;
                    else if (dir == 2)
                        dir = 1;
                    else
                        dir = 0;
                }
                if (Mirror[x][y] == '/')
                {
                    if (dir == 0)
                        dir = 1;
                    else if (dir == 1)
                        dir = 0;
                    else if (dir == 2)
                        dir = 3;
                    else
                        dir = 2;
                }
                x += Next[dir][0];
                y += Next[dir][1];
            }
            if (x == n + 1)
                cout << y << endl;
            else
                cout << -1 << endl;
        }
    
        return 0;
    }
    

      

  • 相关阅读:
    Why use strong named assemblies?
    Dependency Walker
    “等一下,我碰!”——常见的2D碰撞检测
    MOBA游戏的网络同步技术
    VS2017如何配置openGL环境
    UE4关于Oculus Rift (VR)开发忠告
    UE4 的json读写方式
    Blueprint 编译概述
    UE4编码规范
    Unreal Enginer4特性介绍
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10353799.html
Copyright © 2011-2022 走看看