import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Solution s = new Solution(); s.doBefore(); Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 0; i < t; i++) { int n = sc.nextInt(); s.getResult(n); } sc.close(); } } class Solution { public ArrayList<int[]> curResult = new ArrayList<int[]>(); // public boolean mark = false; public void doBefore() { int last = 0; for(int i = 1; i <= 100000; i++) { if(f(i) == g(i)) { int[] arr = {i, ++last}; curResult.add(arr); } } } public void getResult(int n) { int result = 1; for(int i = 0; i < curResult.size(); i++) { if(curResult.get(i)[0] <= n) { result = curResult.get(i)[1]; } else break; } System.out.println(result); } // int curMostClosed = 1; // int result = 1; //当前结果是0; // // if (mark) { // for (int k : curResult.keySet()) { // if (k > curMostClosed && k <= n) { // curMostClosed = k; // } // } // result = curResult.get(curMostClosed); // } // mark = true; // // for(int i = curMostClosed + 1; i <= n; i++) { // if(f(i) == g(i)) // result++; // } // curResult.put(n, result); // // System.out.println(result); // } private int f(int n ) { int result = 0; while(n != 0) { result += n % 10; n /= 10; } return result; } private int g(int n ) { int result = 0; while(n != 0) { result += (n & 1) == 1 ? 1 : 0; n >>>= 1; } return result; } }
点赞 评论

相关推荐

找工作勤劳小蜜蜂:自我描述部分太差,完全看不出想从事什么行业什么岗位,也看不出想在哪个地区发展,这样 会让HR很犹豫,从而把你简历否决掉。现在企业都很注重员工稳定性和专注性,特别对于热爱本行业的员工。 你实习的工作又太传统的it开发(老旧),这部分公司已经趋于被淘汰,新兴的互联网服务业,比如物流,电商,新传媒,游戏开发和传统的It开发有天然区别。不是说传统It开发不行,而是就业岗位太少,基本趋于饱和,很多老骨头还能坚持,不需要新血液。 工作区域(比如长三角,珠三角,成渝)等也是HR考虑的因素之一,也是要你有个坚定的决心。否则去几天,人跑了,HR会被用人单位骂死。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务