题目描述
思路分析
dfs
代码实现
package lanqiao;import java.util.Arrays;
import java.util.Scanner;public class Main {public static int []n;public static void main(String[] args) {Scanner scanner = new Scanner(System.in);n=new int[3];for (int i = 0; i < 3; i++) {n[i]=scanner.nextInt();}Arrays.sort(n);for (int i = 0; i < 5; i++) {int num=scanner.nextInt();char res=f(num,0,0);System.out.print(res+" ");}System.out.println();}/***参数代表着当前取球人面临的局面* @param num 球的总数* @param me 我方持有的数目* @param you 对手持有的数目* @return*/public static char f(int num, int me, int you) {//出口if(num<n[0]){//不够取if((me&1)==1&&(you&1)==0) return '+';else if((me&1)==0&&(you&1)==1) return '-';else return '0';}boolean ping=false;for (int i = 0; i < 3; i++) {if(num>=n[i]){char res=f(num-n[i],you,me+n[i]);//对手进行互换if(res=='-'){return '+';}if(res=='0'){ping=true;}}}//如果能走到第这行,说明不存在对手输的情况,那么是否存在平的情况if(ping){return '0';}else {return '-';}}
}