ac,40%求教咋弄,暴力 83% 求较好的方法
题1.ac
import java.util.Scanner;public class Main1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n+1];
for (int i = 0; i < n; i++) {
arr[sc.nextInt()] = 1;
}
sc.close();
for (int i = 0; i < n; i++) {
if (arr[i]==0) {
System.out.println(i);
}
}
}
}
题2.40%求教
import java.util.Scanner;
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
if (n == 0) {
System.out.println(0);
}
else if (n > 0) {
int steps = 1;
int pos = 1;
while (pos!=n) {
pos = pos*2;
if (pos>n) {
if ((n -pos/2) <= (pos-n)) {
steps += n -pos/2;
}else {
steps += pos-n+1;
}
break;
}
else {
steps++;
}
}
System.out.println(steps);
}
else {
int steps = 1;
int pos = -1;
while (pos!=n) {
pos = pos*2;
if (pos<n) {
if ((pos/2-n) < n-pos) {
steps += pos/2-n;
}else {
steps += n-pos+1;
}
break;
}
else {
steps++;
}
}
System.out.println(steps);
}
}
}
public class Main2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
if (n == 0) {
System.out.println(0);
}
else if (n > 0) {
int steps = 1;
int pos = 1;
while (pos!=n) {
pos = pos*2;
if (pos>n) {
if ((n -pos/2) <= (pos-n)) {
steps += n -pos/2;
}else {
steps += pos-n+1;
}
break;
}
else {
steps++;
}
}
System.out.println(steps);
}
else {
int steps = 1;
int pos = -1;
while (pos!=n) {
pos = pos*2;
if (pos<n) {
if ((pos/2-n) < n-pos) {
steps += pos/2-n;
}else {
steps += n-pos+1;
}
break;
}
else {
steps++;
}
}
System.out.println(steps);
}
}
}
题3.暴力83%
import java.util.Scanner;
public class Main3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
if (n==1) {
System.out.println(1);
}else {
int index = 1;
for (int i = 2; i <= Integer.MAX_VALUE; i++) {
if (zheng(i)) {
++index;
if (index==n) {
System.out.println(i);
break;
}
}
}
}
}
public static boolean zheng(int t) {
while(t%2 == 0) {
t /= 2;
}while(t%3 == 0) {
t /= 3;
}while(t%5 == 0) {
t /= 5;
}
if (t==1) {
return true;
}
return false;
}
}
#招商银行信用卡中心#public class Main3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
if (n==1) {
System.out.println(1);
}else {
int index = 1;
for (int i = 2; i <= Integer.MAX_VALUE; i++) {
if (zheng(i)) {
++index;
if (index==n) {
System.out.println(i);
break;
}
}
}
}
}
public static boolean zheng(int t) {
while(t%2 == 0) {
t /= 2;
}while(t%3 == 0) {
t /= 3;
}while(t%5 == 0) {
t /= 5;
}
if (t==1) {
return true;
}
return false;
}
}