[笔试强训day08]

文章目录

  • [HJ108 求最小公倍数](#HJ108 求最小公倍数)
  • [NC95 数组中的最长连续子序列](#NC95 数组中的最长连续子序列)
  • [DP39 字母收集](#DP39 字母收集)

HJ108 求最小公倍数

HJ108 求最小公倍数

cpp 复制代码
#include<iostream>

using namespace std;

int a,b;

int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int main()
{
    cin>>a>>b;
    int t=gcd(a,b);
    int ans=a*b/t;
    cout<<ans<<endl;
    return 0;
}

NC95 数组中的最长连续子序列

NC95 数组中的最长连续子序列

cpp 复制代码
class Solution {
public:

    int MLS(vector<int>& arr) {
        int n=arr.size();
        sort(arr.begin(),arr.end());
        int ans=0;
        for(int i=0;i<n;)
        {
            int j=i+1,cnt=1;
            while(j<n)
            {
                if(arr[j]-arr[j-1]==1)
                {
                    cnt++;
                    j++;
                }
                else if(arr[j]-arr[j-1]==0) j++;
                else break;
            }
            ans=max(cnt,ans);
            i=j;
        }
        return ans;
    }
};

DP39 字母收集

DP39 字母收集

cpp 复制代码
#include<iostream>

using namespace std;

const int N=505;
int m,n;
char g[N][N];
int dp[N][N];

int main()
{
    cin>>m>>n;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>g[i][j];
        }
    }

    for(int i=0;i<=m;i++)
    {
        for(int j=0;j<=n;j++)
        {
            int t=0;
            if(g[i][j]=='l') t=4;
            else if(g[i][j]=='o') t=3;
            else if(g[i][j]=='v') t=2;
            else if(g[i][j]=='e') t=1;

            dp[i][j]=max(dp[i][j-1],dp[i-1][j])+t;
        }
    }
    cout<<dp[m][n]<<endl;
    return 0;
}
相关推荐
ValhallaCoder17 小时前
hot100-栈
数据结构·python·算法·
WW_千谷山4_sch21 小时前
洛谷B3688:[语言月赛202212]旋转排列(新解法:deque双端队列)
数据结构·c++·算法
Zachery Pole21 小时前
【代码随想录】二叉树
算法
漂流瓶jz21 小时前
UVA-11214 守卫棋盘 题解答案代码 算法竞赛入门经典第二版
c++·算法·dfs·aoapc·算法竞赛入门经典·迭代加深搜索·八皇后
浮生091921 小时前
DHUOJ 基础 88 89 90
算法
fpcc1 天前
并行编程实战——CUDA编程的Enhancing Memory Allocation
c++·cuda
v_for_van1 天前
力扣刷题记录7(无算法背景,纯C语言)
c语言·算法·leetcode
先做个垃圾出来………1 天前
3640. 三段式数组 II
数据结构·算法
白太岁1 天前
通信:(3) 高并发网络通信:epoll + 边沿触发 + 非阻塞 IO + tcp
c语言·网络·c++·网络协议·tcp/ip
楼田莉子1 天前
C++项目:日志&&线程池
linux·c++·学习·visual studio code