xu


私信TA

用户名:dotcpp0705180

访问量:153

签 名:

等  级
排  名 16169
经  验 767
参赛次数 0
文章发表 4
年  龄 0
在职情况 学生
学  校 郑州大学
专  业

  自我简介:

解题思路:
注意事项:
参考代码:import java.util.*;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
  public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        long num[][]=new long[n+1][10];
        long[] std=new long[10];
        long count=0;
        for(int i=1;i<=n;i++){
            int top=0;
            long h=scan.nextLong();
            std[top]=h;
            while(h>1){
                top++;
                h=sqrt(h/2+1);
                std[top]=h;
            }
            for(int j=0,k=top-1;k>=0;k--,j++){
                num[i][j]=std[k];
            }
            count+=top;
        }
        for(int i=0;i<10;i++){
            for(int j=2;j<=n;j++){
                if(num[j][i]>0&&num[j][i]==num[j-1][i])count--;
            }
        }
        System.out.println(count);
    }
    public static long sqrt(long h){
        long x=0;
        long start=1l,end=(long)1e9,mid=0;
        while(start<=end){
            mid=(start+end)/2;
            if(mid*mid<=h){
                x=mid;
                start=mid+1;
            }
            else end=mid-1;
        }
        return x;
    }
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区