笔试强训day08



求最小公倍数

#include <iostream>
using namespace std;

int gcd(int a,int b)
{
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b)
{
    return a/gcd(a,b)*b;
}
int main() {
    int a,b;
    cin>>a>>b;
    cout<<lcm(a,b)<<'\n';
}
// 64 位输出请用 printf("%lld")


数组中的最长连续子序列

class Solution {
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * max increasing subsequence
     * @param arr int整型vector the array
     * @return int整型
     */
    int MLS(vector<int>& arr) {
        // write code here
        sort(arr.begin(), arr.end());
        int ans = 1;
        int n = arr.size();
        for (int i = 0; i < n; ++i) {
            int cnt = 1;
            for (int j = i + 1; j < n;) {
                if (arr[j] == arr[j - 1] + 1)
                    ++j, ++cnt;
                else if (arr[j] == arr[j - 1])
                    ++j;
                else
                    break;
            }
            ans = max(ans, cnt);
        }
        return ans;
    }
};


字母收集

#include <iostream>
using namespace std;
const int N = 510;
char g[N][N];
int dp[N][N];
int m, n;
int main() {
    cin >> m >> n;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> g[i][j];
        }
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 1; 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 - 1][j], dp[i][j - 1]) + t;
        }
    }
    cout << dp[m][n] << endl;
    return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值