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

A组

蛇形填数

#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>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 10;
int n;
int g[N][N];
bool st[N];

void dfs(int t, int u)
{
    st[u] = true;
    for (int j = 0; j < 7; j ++ )
        if (g[u][j + 1] && (t >> j & 1) && !st[j + 1])
            dfs(t, j + 1);
}

bool check(int x)
{
    int t = x, cnt = 0;
    memset(st, 0, sizeof st);
    for (int j = 0; j < 7; j ++ )
        if (t >> j & 1 && !st[j + 1])
        {
            dfs(t, j + 1);
            cnt ++ ;
        }
    return cnt == 1;
}

int main()
{
    for (int i = 1; i <= 6; i ++ )
    {
        g[i][i + 1] = g[i + 1][i] = 1;
    }
    
    g[2][7] = g[7][2] = 1;
    g[3][7] = g[7][3] = 1;
    g[5][7] = g[7][5] = 1;
    g[1][6] = g[6][1] = 1;
    
    int ans = 0;
    for (int i = 1; i < (1 << 7); i += 1)
    {
        if (check(i)) ans ++ ;
    }
    
    cout << ans << endl;
    
    return 0;
}

B组

直线

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 200000;

int n;
struct Line
{
    double k, b;
    bool operator< (const Line& t) const
    {
        if (k != t.k) return k < t.k;
        return b < t.b;
    }
}l[N];

int main()
{
    for (int x1 = 0; x1 < 20; x1 ++ )
        for (int y1 = 0; y1 < 21; y1 ++ )
            for (int x2 = 0; x2 < 20; x2 ++ )
                for (int y2 = 0; y2 < 21; y2 ++ )
                    if (x1 != x2)
                    {
                        double k = (double)(y2 - y1) / (x2 - x1);
                        double b = y1 - k * x1;
                        l[n ++ ] = {k, b};
                    }

    sort(l, l + n);
    int res = 1;
    for (int i = 1; i < n; i ++ )
        if (fabs(l[i].k - l[i - 1].k) > 1e-8 || fabs(l[i].b - l[i - 1].b) > 1e-8)
            res ++ ;
    cout << res + 20 << endl;

    return 0;
}

货物摆放

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main()
{
    LL n;
    cin >> n;
    vector<LL> d;
    for (LL i = 1; i * i <= n; i ++ )
        if (n % i == 0)
        {
            d.push_back(i);
            if (n / i != i) d.push_back(n / i);
        }

    int res = 0;
    for (auto a: d)
        for (auto b: d)
            for (auto c: d)
                if (a * b * c == n)
                    res ++ ;
    cout << res << endl;

    return 0;
}

C组

明码

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
  // 请在此输入您的代码
  cout << (long long)pow(9, 9) << endl;
  return 0;
}

第几个幸运数字

#include <iostream>
#include <cmath>
typedef long long LL;
using namespace std;
int main()
{
  // 请在此输入您的代码
  LL cnt = 0;
  LL x = 59084709587505;
  for (int i = 0; pow(3, i) <= x; i ++ )
    for (int j = 0; pow(5, j) <= x; j ++ )
      for (int k = 0; pow(7, k) <= x; k ++ )
        if ((LL)pow(3, i) * pow(5, j) * pow(7, k) <= x) cnt ++ ;
  cout << cnt - 1 << 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、付费专栏及课程。

余额充值