蓝桥杯知识点3

1.字典树

1.编写一个insert函数,用于将一个字符串s加入到字典树中去

public static void insert(String word){
       TreeNode node = root;

       for(int i = 0;i < word.length();++i){
               char index = word.charAt(i);

              if(!node.map.containsKey(index)){
                   node.map.put(index,new TreeNode());

                 }
             node.cnt++;

             node = node.map.get(index));

     }
  node.cnt++;

 }
 

2.编写一个query函数,用于判断某个字符串在trie中的出现次数是否大于0

public static boolean query(String word){
         TreeNode node = root;

         for(int i = 0;i < word.length;++i){
               char index = word.charAt(i);

               if(!node.map.containsKey(index){
                    return  false;

           }
          node = node.map.get(index);

   }
  return node.cnt > 0;

 }

2.GCD:最大公约数

3.唯一分解定理:

1.public class Main{
             static List<int [] >list = new ArrayList<>();

             public static void main(String[] args){
   Scanner scan =new Scanner(System.in)

   int n = scan.nextInt();

   //枚举所有的质因子

  for(int i = 2;i <= n;i++){
       if(n % i == 0){
         int ans = 0;

         while(n % i == 0) {ans++; n/=i;}
        list.add(new int[] {i ,ans)};

      }
    }
      if(n > 1){

           list.add(new int [] {n,1});

     for(int []x : list)

           System.out.println(x[0]+" "+x[1]);

      }
  }

4.快速幂原理

1.public static long qmi(long a,long b,long p){
        long res = 1;

        while(b > 0){
             if((b & 1) == 1){
                    res = res * a % p;

             a = a * a % p;

             b >>= 1;

        }
      return res;

}
 

5.排列组合

1.public static long c(long n , long m){
         long res = 1;

         for(long i = n;i >= n-m+1;i--){
                  res = res * i % mod;

              }
          for(long i = 1;i <= m; i++){
                  res = res * qmi(i , mod - 2) % mod;

            }
         return res;

       }
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值