njuoj 递归查询字符串
思路:每次将pos映射到对称区间的相应位置。直到达到[1,5]区间
其中需要注意的是,需要找到$的分布规律。单独处理
package com.company.dp; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class 递归查询子字符串 { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int case_num=Integer.parseInt(scanner.nextLine()); for (int i = 0; i < case_num; i++) { long pos=Long.parseLong(scanner.nextLine()); char res=getNum(pos); System.out.println(res); } scanner.close(); } private static char getNum(long pos) { long[] s=new long[50]; s[0]=5; for (int i = 1; i < s.length; i++) { s[i]=s[i-1]*2+i; } for (int i = 0; i < s.length; i++) { System.out.println(s[i]); } String str0="12345"; while(pos>5){ for (int i = 1; i < s.length; i++) { if(pos>=s[i-1]&&pos<=s[i]){ if(2*pos-s[i]>=0&&2*pos-s[i]<=i)return '$'; pos=s[i]-pos+1; break; } } } return str0.charAt(((int) pos)-1); } }