20240825蚂蚁后端笔试前两题ac
- (a==b)&&(d==0 || a>0)为YES
- dfs预处理一份全部的好数列表,对每次询问二分答案
static int[] goodNums = new int[5680000]; static int p = 0; static { for (int i = 1; i <= 9; i++) { dfs(0, i, 0, 0); } goodNums[p++] = 1023456789; } static void dfs(int pos, int n, int mask, int curNum) { if (pos == n) { goodNums[p++] = curNum; return; } for (int i = 0; i <= 9; i++) { if (i == 0 && pos == 0) { continue; } if (((mask >> i) & 1) == 0) { dfs(pos + 1, n, mask | (1 << i), curNum * 10 + i); } } }