吐槽贴+刷题贴
赛码是真的反人类的刷题平台呀,它能让你抓狂让你无奈,要的就是一个心理爆炸。

赛码

007Manager

Manager
时间限制:1S内存限制:64MB
描述
小明是一个互联网公司的老板,需要招聘员工。现在有k个学校的学生前来应聘。
由于特殊原因,要求最后入职的员工学校的人数应该都不一样。
比如我们可以A大学录取5人,B大学录取4人。但是不允许A大学和B大学都录取5人。
请问后最多录取多少人呢?
输入描述
第一行一个整数k,表示学校的数量。
第二行k个整数ai,表示这个学校有ai个人前来应聘。
满足 1<=k<=100000,1<=ai<=100000
输出描述
输出最多录取人数
示例
输   入:
3
3 3 2
返回值:
6

关键解题思路
重新定义一个Set集合,存放能招生学校(可能存在不招生的学校)的录取人数,然后求和。

我的通过率66.7%,找不到原因。气死了,就是浪费时间

Solution

import java.util.*;
class Main{
   
  public static void main(String[] args){
   
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    ArrayList<Integer> arrline = new ArrayList<Integer>();
    for(int i = 0; i<n; i++){
   
        arrline.add(in.nextInt());
    }
    // System.out.print(arrline);
    int count =0;
    Set<Integer> newcount = new HashSet<Integer>();//用普通的list会报超时。没有get方法,后面要转成数组
    newcount.add(arrline.get(0));
    for(int i = 1; i<n; i++){
   
        count = arrline.get(i);
        while(count>=0 &!newcount.add(count)){
   
            --count;
        }
    }
    System.out.println(newcount);
    Integer[] newcountarr = newcount.toArray(new Integer[0]);
    long sum =0;
    for (int j = 0; j < newcountarr.length; j++){
   
        sum+=newcountarr[j];}
    try{
   
      System.out.println(sum);
    }
    catch(Exception e){
   
      System.out.println(newcountarr);
    }
  }
}

008大整数截取

描述
花花有一个很珍贵的数字串,但是它太长了,没有办法保留下来,所以她想截取其中一段保存下来,但是她希望截取下来的这一段数对1000000007取模之后等于Ai,她想知道有多少种截取方案。数字串S中截取一段是指S[L], S[L+1],, S[R]连起来所形成的十进制数,其中LR满足1LR|S|。例如S=1023456789”,S(1,2)=10S(2,4)=23S(2,10)=23456789。

输入描述
第一行一个数字串,长度不超过30000。

第二行一个数T,表示询问的数量。(T100)

接下来T行,每行一个非负整数Ai,表示询问有多少种截取方案使得其值模1000000007后等于Ai。(0Ai<1000000007)

输出描述
共T行,每行一个非负整数,表示方案数。

示例
输   入:
1000000008001
4
8
0
1
10
返回值:
9
39
5
2

关键解题思路
这题只通过36.3%;
先把所有有可能的截取情况保存,就是这一步骤可能会导致OOM,String没有内存限制,但是jvm有啊
//将每个数据拿出来判断
BigInteger的用法还比较特殊
Solution

//截取字符串subString(i,j)
//BigInteger的用法
import java.util.*;
import java.math.BigInteger;
public class Main{
   
  public static void main(String[] arg){
   
    Scanner in = new Scanner(System.in);
      String s = in.nextLine();
      int n =in.nextInt();
      int[] ai = new int[n];
      for(int i=0;i<n;i++){
   
          ai[i]=in.nextInt();

      }
      //先把所有截取情况都保存,就是这一部可能会导致OOM,String没有内存限制,但是jvm有啊
      List<String> result = new ArrayList<>();
      for(int j=0;j<s.length(); j++){
   
          for(int k = j+1;k<s.length()+1; k++){
   
              result.add(s.substring(j,k));
              }
      }
      //将result每个数据拿出来判断
      for(int j =0; j<n; j++) {
   
          List<BigInteger> arr = new ArrayList<>();
          BigInteger a =new BigInteger(String.valueOf(ai[j])) ;
// System.out.println(a);
          for (int i = 0; i < result.size(); i++) {
   
               BigInteger x=  new BigInteger(result.get(i));
               BigInteger y = new BigInteger("1000000007");
              if(x.mod(y).equals(a)){
   
                  arr.add(x);
          }
      }
          System.out.println(arr.size());
      }
  }
}