博客
关于我
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/

    你可能感兴趣的文章
    svn访问报错500
    查看>>
    sum(a.YYSR) over (partition by a.hy_dm) 不需要像group by那样需要分组函数。方便。
    查看>>
    ORCHARD 是什么?
    查看>>
    Struts2中使用Session的两种方法
    查看>>
    Stream API:filter、map和flatMap 的用法
    查看>>
    STM32工作笔记0032---编写跑马灯实验---寄存器版本
    查看>>
    order by rand()
    查看>>
    SSM(Spring+SpringMvc+Mybatis)整合开发笔记
    查看>>
    Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
    查看>>
    org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement profile
    查看>>
    sql查询中 查询字段数据类型 int 与 String 出现问题
    查看>>
    org.apache.commons.beanutils.BasicDynaBean cannot be cast to ...
    查看>>
    org.apache.dubbo.common.serialize.SerializationException: com.alibaba.fastjson2.JSONException: not s
    查看>>
    sqlserver学习笔记(三)—— 为数据库添加新的用户
    查看>>
    org.apache.http.conn.HttpHostConnectException: Connection to refused
    查看>>
    org.apache.ibatis.binding.BindingException: Invalid bound statement错误一例
    查看>>
    org.apache.ibatis.exceptions.PersistenceException:
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>