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

    你可能感兴趣的文章
    PYTHON调离线语音合成并实时播放
    查看>>
    python unittest高级特性!
    查看>>
    Python unittest:如何将标准输出消息临时重定向到缓冲区并测试其内容?
    查看>>
    Python urllib/Requests下载文件失败,但浏览器下载失败
    查看>>
    Python urllib2 文件上传问题
    查看>>
    Python urllib2.open 连接由对等错误重置
    查看>>
    python urllib2详解及实例
    查看>>
    Python url请求提示certificate verify failed unable to get local issuer certificate
    查看>>
    Python UTC 日期时间对象的 ISO 格式不包括 Z(祖鲁语或零偏移)
    查看>>
    python valueerror object2_python遇到错误记录
    查看>>
    python vars的作用
    查看>>
    Python vcrpy库:HTTP请求记录和重放
    查看>>
    Python virtualenv
    查看>>
    python vue3实现大文件分段续传(断点续传)--带暂停和继续功能
    查看>>
    Python WebDriver如何打印整个页面源(html)
    查看>>
    Python WebSocket自动化测试:构建高效接口测试框架
    查看>>
    Python Web开发
    查看>>
    Redis 配置文件杂项。
    查看>>
    Python web自动化测试 —— 文件上传
    查看>>
    Python web自动化测试 —— 文件上传!
    查看>>