第十四届蓝桥杯三月真题刷题训练——第 12 天(3.15)

Think_bird 2023-03-15 03:50:28

0 的个数(暴力循环)

#include<bits/stdc++.h>

using namespace std;

int main()
{
    string a;
    cin >> a;
    for(int i = a.size() - 1, ans = 0; i >= 0; i -- )
    {
        if(a[i] != '0') 
        {
            cout << ans;
            break;
        }
        ans ++;
    }

    return 0;
}

超级质数(思维)

#include<bits/stdc++.h>

using namespace std;
// 2 3 5 7
//23 37 53 73
//237 373
int main()
{
    // int n; cin >> n;
    // for(int i=2;i<50;i++)if(!(n%i)){cout<<"no"; break;}
    cout << 373;
    return 0;
}

卡牌(二分查找)

#include<bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
long long n, m, l = 0, r = N, mid, ans;
long long a[N], b[N];
bool pd;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i ++ ) cin >> a[i];
    for (int i = 0; i < n; i ++ ) cin >> b[i];
    while (l < r)
    {
        pd = true, mid = l + r + 1 >> 1, ans = m;
        for (int i = 0; i < n; ++i)
        {
            if (a[i] >= mid) continue;
            if (a[i] + b[i] < mid || mid - a[i] > ans)
            {
                pd = false;
                break;
            }
            ans -= mid - a[i];
        }
        if(pd) l = mid; 
        else r = mid - 1;
    }
    cout << l;
    return 0;
}

染色时间(居然不是DP???

(看完题感觉像DP, 可能对题目理解有偏差, 但也不是特别懂为什么,只通过20%) 

#include<bits/stdc++.h>

using namespace std;

int n, m, ans;
int dp[510][510];

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i ++ ) for(int j = 0; j < m; j ++ ) cin >> dp[i][j];
    for(int i = 1; i < n; i ++ ) dp[i][0] += dp[i - 1][0];
    for(int i = 1; i < m; i ++ ) dp[0][i] += dp[0][i - 1];
    for(int i = 1; i < n; i ++ ) for(int j = 1; j < m; j ++ )
    dp[i][j] += min(dp[i - 1][j], dp[i][j - 1]), ans = max(ans, dp[i][j]);
    cout << ans;

    return 0;
}
...全文
52 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
执梗 执梗 2023-03-15
  • 打赏
  • 举报
回复

应该是最短路问题

50,854

社区成员

发帖
与我相关
我的任务
社区描述
和众多高校算法内卷分子,一起学习和交流算法那。浓郁的算法交流氛围,拒绝躺平,有效内卷。加入我们,私信我拉你入核心内卷群。
算法数据结构leetcode 个人社区
社区管理员
  • 执 梗
  • Dream-Y.ocean
  • ღCauchyོꦿ࿐
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

 刷题!

试试用AI创作助手写篇文章吧