【Leetcode】【2022秋招笔试题总结】

这篇博客总结了2022年秋季招聘的笔试题目,包括阿里和美团的笔试经历。在阿里笔试中,讨论了如何通过反转01字符串的操作来使两个字符串相等的最小次数问题,以及解决三元组(a, b, c)条件下的组合计数问题。在美团实习笔试中,涉及到了softmax函数的计算。" 17632443,1425852,Spring定时器cron配置问题解决,"['Spring框架', '定时任务', 'Cron', 'Quartz库']

阿里笔试(9月3号)

有两个长度为n的只由01组成的字符串A,B。每次可以选择一个区间([1,n])将A进行反转,最少经过多少次这样的操作才能将A变成B?

//看两个串是否相等,相等就不用变,不想等就要看要变的区间有几个
#include<iostream>
#include<string>
using namespace std;
int main(){
   
   
    int n;
    string a, b;
    cin>>n>>a>>b;
    int count = 0;
    bool tmp = false;
    for(int i=0; i<n; ++i){
   
   
        if(a[i] != b[i]){
   
   
            if(tmp == false){
   
    //字符不等并且和上一个区间断开
                tmp = true;
                count += 1;
            }
        }
        else if(tmp == true){
   
    //字符相等,若区间没断开说明得断了
            tmp = false;
        }
    }
    cout<<count<<endl;
    return 0;
}

三个数a,b,c(好像是正整数),找到满足条件的组数
a ≤ x 2 ≤ b a\le x^2\le b ax2b a ≤ y 3 ≤ b a\le y^3\le b ay3b ∣ x 2 − y 3 ∣ ≤ c |x^2-y^3|\le c x2y3c

//首先算出y的上下界,枚举y,带回去求x,看是否满足条件
//27开立方本来是3,万一变成3.000000001,那么ceil就是4
#include<iostream>
#include<cmath>
using namespace std;
const double eps = 1e-9;
int main(){
   
   
    long long a, b, c;
    cin >> a >> b >> c;
    long long start_y = ceil(pow(a, 1.0/3)-eps);
    long long end_y = floor(pow(b, 1.0/3)+eps);
    long long ans = 0;
    for(long long y=start_y; y<=end_y; ++y){
   
   
        long long y_3 = y*y*y;
        long long start_x = ceil(pow(y_3-c<=1?1:y_3-c
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值