| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
纪念60题,没用位运算,算层数水过。。。import java.util.Scanner;
public class BST {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
while (N-- > 0) {
int input = sc.nextInt();
int allLevel = (int) (Math.log(input) / Math.log(2.0));
int root = (int) Math.pow(2.0, allLevel);
int level = 0;
while (level < allLevel) {
if (root == input) {
break;
}
if (root > input) {
root -= (int) Math.pow(2.0, allLevel - level - 1);
level++;
}
if (root < input) {
root += (int) Math.pow(2.0, allLevel - level - 1);
level++;
}
}
int min = input - (int) Math.pow(2.0, allLevel - level) + 1;
int max = input + (int) Math.pow(2.0, allLevel - level) - 1;
System.out.printf("%d %d%n", min, max);
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator