解题思路: 注意事项: 参考代码: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 人评分
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:552 |
大神老白 (C语言代码)浏览:713 |
多输入输出练习1 (C语言代码)浏览:1179 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:583 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:603 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:517 |
WU-蓝桥杯算法提高VIP-勾股数 (C++代码)浏览:1593 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:691 |
WU-陶陶摘苹果2 (C++代码)浏览:970 |
Hello, world! (C++代码)浏览:1744 |