1)输入
3
3 6 2 4 5 2
输出2
package sort;
import java.util.Scanner;
public class merge {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m = Integer.valueOf(in.nextLine());
String str = in.nextLine();
String[] strs = str.split(" ");
int array[] = new int[strs.length];
for (int i = 0; i < strs.length; i++) {
array[i] = Integer.valueOf(strs[i]);
}
System.out.println(getPiPei(array, array.length, m));
}
public static int getPiPei(int array[], int n, int m) {
if (n != 2 * m)
return -1;
int i = 0, j = n - 1;
int leftSum = array[0];
int rightSum = array[n - 1];
int result = 0;
while (i < n && j >= 0) {
if (leftSum == rightSum) {
result++;
i++;
j--;
if (i < n && j >= 0) {
leftSum += array[i];
rightSum += array[j];
}
} else if (leftSum < rightSum) {
i++;
if (i < n) {
leftSum += array[i];
}
} else {
j--;
if (j >= 0) {
rightSum += array[j];
}
}
}
return result;
}
}
********************************************************************************************************************************************************************************************************
package sort;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class Main2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int size1 = sc.nextInt();
Set<Integer> arr1 = new TreeSet<Integer>();
for (int i = 0; i < size1; i++) {
arr1.add(sc.nextInt());
}
int size2 = sc.nextInt();
Set<Integer> arr2 = new TreeSet<Integer>();
for (int i = 0; i < size2; i++) {
arr2.add(sc.nextInt());
}
int size3 = sc.nextInt();
Set<Integer> arr3 = new TreeSet<Integer>();
for (int i = 0; i < size3; i++) {
arr3.add(sc.nextInt());
}
arr1.retainAll(arr2);
arr1.retainAll(arr3);
for (int i : arr1) {
System.out.print(i + " ");
}
}
}
*********************************************************************************************************************************************************************
package sort;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
public class ShuiXianHuaNumber {
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
Scanner cin = new Scanner(System.in);
int m = cin.nextInt();
int n = cin.nextInt();
List<Integer> resultList = getShuiXianHuaNumber(m, n);
for (int i = 0; i < resultList.size(); i++) {
if (i != 0)
System.out.print(" ");
System.out.print(resultList.get(i));
}
}
public static List<Integer> getShuiXianHuaNumber(int m, int n) {
List<Integer> result = new ArrayList<>();
for (int i = m; i <= n; i++) {
if (verify(i)) {
result.add(i);
}
}
return result;
}
public static boolean verify(int i) {
int sum = 0, j, tmp = i;
while (i != 0) {
j = i % 10;
sum += (int) Math.pow(j, 3);
i = i / 10;
}
if (sum == tmp)
return true;
return false;
}
}