爱奇艺GG了
看到好多人2.6以上,0.7的表示GG。题确实简单,就是半天都优化不动。。。Java岗的,有大佬帮忙看一下怎么优化吗?
第一题:循环数比较大小,永远只有0.3的通过率
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long x1 = sc.nextLong(); long k1 = sc.nextLong(); long x2 = sc.nextLong(); long k2 = sc.nextLong(); if(x1 >= 1 && x1 <= 1000000000 && x2 >= 1 && x2 <= 1000000000 && k1 >= 1 && k1 <= 50 && k2 >= 1 && k2 <= 50) { if(repeat(x1, k1) < repeat(x2, k2)) { System.out.println("Less"); } else if(repeat(x1, k1) > repeat(x2, k2)) { System.out.println("Greater"); } else if(repeat(x1, k1) == repeat(x2, k2)){ System.out.println("Equal"); } } } public static long repeat(long x, long k) { String str = String.valueOf(x); StringBuffer sb = new StringBuffer(); for(int i = 0; i < k; i++) { sb.append(str); } str = sb.toString(); long result = Integer.parseInt(str); return result; } }第三题:计算有序对数量
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long m = sc.nextLong(); if(n >= 1 && n <= 100000 && m >= 1 && m <= 100000) { System.out.println(SSR(n, m)); } } public static long SSR(long n, long m) { long count = 0; for(long A = 1; A <= n; A++) { for(long B = 1; B <= m; B++) { if((Math.sqrt(A) + Math.sqrt(B)) * (Math.sqrt(A) + Math.sqrt(B)) % 1 == 0) { count++; } } } return count; } }应该都不是超时,牛客的系统超时好像要提示。