京东4.2号笔试 开发岗 1(100%)2(73%)
第一题 树的基本知识点考察 java用long过0.91 直接偷懒用python AC(私密马赛)同学用java的 BigInteger 过了但是我不咋会那个操作就没试出来
if __name__ == '__main__': n, x = list(map(int, input().split())) for c in input(): if c == 'U': x >>= 1 if c == 'L': x *= 2 if c == 'R': x = x*2 + 1 print(x)
第二题 思维题 统计ABC出现的次数 设原始粉刷次数是3 有一个大于等于N的粉刷次数就会-1 要特判ABBABBABB这种没有连续三个B可以涂抹的情况(但是这个情况当时离最后五分钟的时候想到的,没敲上去呜呜呜
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int T = scanner.nextInt(); for (int i = 0; i < T; i++) { int N = scanner.nextInt(); int[] cnt = new int[3]; String s = scanner.next(); for (int j = 0; j < N * 3; j++) { cnt[s.charAt(j) - 'A']++; } int ans = 3; for (int j = 0; j < 3; j++) { if (cnt[j] >= N) { ans--; } } //只写到这里可以过百分之73的样例 //特判ABBABBABB if(ans == 1) { if ((cnt[0] == N || cnt[1] == N || cnt[2] == N) && (cnt[0] == 0 || cnt[1] == 0 || cnt[2] == 0)) { char pre = s.charAt(0); int count = 0; for(int j=0;j<s.length();j++){ if(s.charAt(j) == pre){ count += 1; }else{ count = 1; pre = s.charAt(j); } if(count == N)break; } if(count < N) ans = 2; } } System.out.println(ans); } } }