蓝桥杯百校真题大联赛第3期(二)

A组

最大降雨量

#include <iostream>
using namespace std;
int main()
{
  // 请在此输入您的代码
  cout << 49 - 15 << endl;
  return 0;
}

迷宫

#include <iostream>
#include <queue>
using namespace std;
int n = 30, m = 50;
char g[35][55];
bool st[35][55];
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, -1, 1, 0};

struct node
{
  int x, y, step;
  string s;
}t, p;
queue<node> q;

string dr = "DLRU";

string bfs()
{
  p = {0, 0, 0, ""};
  q.push(p);
  st[0][0] = true;

  while (q.size())
  {
    t = q.front();
    q.pop();

    if (t.x == n - 1 && t.y == m - 1) return t.s;

    for (int i = 0; i < 4; i ++ )
    {
      int x = t.x + dx[i], y = t.y + dy[i];
      if (x < 0 || x >= n || y < 0 || y >= m) continue;
      if (g[x][y] == '1') continue;
      if (st[x][y]) continue;

      // printf("%d %d\n", x, y);

      p = {x, y, t.step + 1, t.s + dr[i]};
      q.push(p);
      st[x][y] = true;
    }
  }
}

int main()
{
  // 请在此输入您的代码
  for (int i = 0; i < n; i ++ ) scanf("%s", g[i]);

  cout << bfs() << endl;

  return 0;
}

B组

蛇形填数

#include <iostream>
using namespace std;
int main()
{
  // 请在此输入您的代码
  int dx[4] = {0, 1, 1, -1};
  int dy[4] = {1, -1, 0, 1};

  int r = 1, c = 1, t = 1, d = 0;
  while (r != 20 || c != 20)
  {
    if (d == 0)
    {
      r = r + dx[d];
      c = c + dy[d];
      t ++ ;
    }
    else if (d == 1)
    {
      while (c >= 2)
      {
        r = r + dx[d];
        c = c + dy[d];
        t ++ ;
        
        if (r == 20 && c == 20) 
        {
            cout << t << endl;
            return 0;
        }
      }
    }
    else if (d == 2)
    {
      r = r + dx[d];
      c = c + dy[d];
      t ++ ;
    }
    else
    {
      while (r >= 2)
      {
        r = r + dx[d];
        c = c + dy[d];
        t ++ ;
        if (r == 20 && c == 20) 
        {
            cout << t << endl;
            return 0;
        }
      }
    }
    d = (d + 1) % 4;
  }
  return 0;
}

跑步锻炼

#include <iostream>
using namespace std;

int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool is_leap(int y, int m)
{
  if (m != 2) return false;
  return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
}

bool check(int y, int m, int d)
{
  if (m < 1 || m > 12) return false;
  if (d < 1 || d > months[m] + is_leap(y, m)) return false;
  return true;
}

int main()
{
  // 请在此输入您的代码
  int sum = 0, w = 5;
  for (int i = 20000101; i <= 20201001; i ++ )
  {
    int y = i / 10000, m = i % 10000 / 100, d = i % 100;
    if (check(y, m, d))
    {
      if (d == 1 || w + 1 == 1) sum += 2;
      else sum += 1;
      w = (w + 1) % 7;
    }
  }
  cout << sum << endl;
  return 0;
}

C组

卡片

#include <iostream>
using namespace std;

int a[10];

bool check(int x)
{
  while (x)
  {
    if (--a[x % 10] < 0) return false;
    x /= 10;
  }
  return true;
}

int main()
{
  // 请在此输入您的代码
  int i;
  for (i = 0; i <= 9; i ++ ) a[i] = 2021;
  for (i = 1; i; i ++ )
  {
    if (!check(i)) break;
  }
  cout << i - 1 << endl;
  return 0;
}

相乘

#include <iostream>
using namespace std;
const int N = 1000000007;
int main()
{
  // 请在此输入您的代码
  long long a = 2021;
  for (int i = 1000000007; i; i -- )
  {
    if (a * i % N == 999999999) 
    {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
#include <iostream>
using namespace std;
const int N = 1000000007;
int main()
{
  // 请在此输入您的代码
  cout << 17812964 << endl;
  return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Shirandexiaowo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值