2023/9/3 微众银行笔试


第一题

import java.io.*;
import java.util.*;

//微众第一题 100%
public class Main4 {
    public static void main(String args[]) throws Exception {
        Scanner cin=new Scanner(System.in);
        int n = cin.nextInt();
        int[] res=new int[n];
        for(int i=0;i<n;i++){
            res[i]=cin.nextInt();
        }
        int a=help(res);
        System.out.println(a);
    }
    public  static int help(int[] res){
        Set<Integer> set=new HashSet<>();
        int n=res.length;
        for (int i = 0; i < n; i++) {
            if(set.contains(res[i]))break;
            set.add(res[i]);
        }
        return set.size();
        }


}

第二题

import java.io.*;
import java.util.*;
//微众银行第二题 45%

public class Main5 {
    public static void main(String args[]) throws Exception {
        Scanner cin=new Scanner(System.in);
        int n = cin.nextInt();
        int[] res=new int[n];
        Set<Integer> set=new HashSet<>();
       // Set<Integer> set1=new HashSet<>();
        long sum=0;
        int count=0;
        for(int i=0;i<n;i++) res[i]=cin.nextInt();
        Arrays.sort(res);
        for (int i = 0; i <n ; i++) {
            if(set.contains(res[i])){
                sum+=res[i];
               //set1.add(res[i]);
               count++;
            }
            set.add(res[i]);
        }
        long ans=0;
        for (int i = res[0]; i <=100000&&count>=1; i++) {
            if(set.contains(i))continue;
            ans+=i;
            count--;
        }
        System.out.println(ans-sum);
    }
}

第三题

import java.io.*;
import java.util.*;

//直接输出n,通过18%
public class Main6{
    public static void main(String args[]) throws Exception {
        Scanner cin=new Scanner(System.in);
        int n = cin.nextInt();
        int u = cin.nextInt();
        int v = cin.nextInt();
        int[] res=new int[n];
        for(int i=0;i<n;i++) res[i]=cin.nextInt();
        long[] presum=new long[n+1];
        for (int i = 1 ;i <=n ; i++) {
            presum[i]=presum[i-1]+res[i-1];
        }
        int count=0;
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                long sun=pre[j]-pre[i];
                if(1L*(i-j+1)*u==1L*v*sum)count++;
            }
        }
        System.out.println(count);
    }
}

  目录