博客
关于我
luogu P7262 Get Your Wish
阅读量:637 次
发布时间:2019-03-14

本文共 2613 字,大约阅读时间需要 8 分钟。

为了解决这个问题,我们需要模拟话筒内部水滴在新的重力方向下的流动情况。我们需要检查是否有水滴会流到关键电子元件上,如果有的话,话筒就会坏掉。

方法思路

  • 读取输入数据:首先读取话筒的大小和重力方向,然后读取话筒内部的状态矩阵。
  • 记录水滴位置:遍历状态矩阵,记录所有水滴的位置。
  • 模拟水滴流动:根据重力方向,模拟每个水滴的流动路径,检查是否会流到关键电子元件上。
  • 判断结果:如果有任何水滴流到关键电子元件上,输出"GG",否则输出"OK"。
  • 解决代码

    #include 
    #include
    #include
    #include
    #include
    #define LL long longusing namespace std;int n, m;char c;int x, y;char a[1002][1002];int b[1002][2]; // b[k][0]是i,b[k][1]是jint tot = 0;bool judge = true;void simulate() { if (c == 'v') { // 下方向,水滴向下流动 for (int k = 1; k <= tot; ++k) { int i = b[k][0]; int j = b[k][1]; int di = i + 1; while (di <= n && a[di][j] != 'x') { ++di; } if (a[di][j] == 'x' || di > n) { judge = false; return; } } } else if (c == '^') { // 上方向,水滴向上流动 for (int k = 1; k <= tot; ++k) { int i = b[k][0]; int j = b[k][1]; int di = i - 1; while (di >= 1 && a[di][j] != 'x') { --di; } if (a[di][j] == 'x' || di < 1) { judge = false; return; } } } else if (c == '>') { // 右方向,水滴向右流动 for (int k = 1; k <= tot; ++k) { int i = b[k][0]; int j = b[k][1]; int dj = j + 1; while (dj <= m && a[i][dj] != 'x') { ++dj; } if (a[i][dj] == 'x' || dj > m) { judge = false; return; } } } else if (c == '<') { // 左方向,水滴向左流动 for (int k = 1; k <= tot; ++k) { int i = b[k][0]; int j = b[k][1]; int dj = j - 1; while (dj >= 1 && a[i][dj] != 'x') { --dj; } if (a[i][dj] == 'x' || dj < 1) { judge = false; return; } } }}int main() { cin >> n >> m >> c; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> a[i][j]; if (a[i][j] == 'o') { tot++; b[tot][0] = i; b[tot][1] = j; } } } if (tot > 0) { simulate(); } if (judge) { cout << "OK" << endl; } else { cout << "GG" << endl; } return 0;}

    代码解释

  • 读取输入:使用标准输入读取n、m和重力方向c,然后读取n行m列的状态矩阵。
  • 记录水滴位置:遍历状态矩阵,记录所有水滴的位置到数组b中。
  • 模拟流动:根据重力方向,分别处理水滴向下、向上、向右、向左流动的情况,检查是否有水滴流到关键电子元件上。
  • 判断结果:如果有任何水滴流到关键电子元件上,设置标志位judge为false,否则保持为true。最后根据标志位输出结果。
  • 转载地址:http://wpvoz.baihongyu.com/

    你可能感兴趣的文章
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    no session found for current thread
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NO.23 ZenTaoPHP目录结构
    查看>>
    no1
    查看>>
    NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    Node JS: < 一> 初识Node JS
    查看>>
    Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
    查看>>
    Node-RED中使用JSON数据建立web网站
    查看>>
    Node-RED中使用json节点解析JSON数据
    查看>>
    Node-RED中使用node-random节点来实现随机数在折线图中显示
    查看>>
    Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
    查看>>
    Node-RED中使用node-red-contrib-image-output节点实现图片预览
    查看>>
    Node-RED中使用node-red-node-ui-iframe节点实现内嵌iframe访问其他网站的效果
    查看>>