A.The Table回到顶部
题意
n行m列,问哪一列乘积最大,相同输出m大的,n<=1000,m<=20
题解
曾经做过(07G),大数相乘处理一下就行了,复杂度O(nm)
代码
1 import java.math.BigInteger; 2 import java.util.*; 3 4 public class Main { 5 6 public static void main(String[] args) { 7 8 BigInteger[] big = new BigInteger[25]; 9 10 Scanner sc = new Scanner(System.in); 11 while(sc.hasNext()) { 12 int m = sc.nextInt(); 13 int n = sc.nextInt(); 14 BigInteger b; 15 for (int i = 1; i <= m; i++) 16 big[i] = BigInteger.ONE; 17 for (int i = 1; i <= n; i++) { 18 for (int j = 1; j <= m; j++) { 19 b = sc.nextBigInteger(); 20 big[j] = big[j].multiply(b); 21 } 22 } 23 int id = 1; 24 BigInteger maxx = big[1]; 25 for (int i = 2; i <= m; i++) { 26 //System.out.println(maxx.compareTo(big[i])); 27 if (maxx.compareTo(big[i]) <= 0) { 28 maxx = big[i]; 29 id = i; 30 } 31 } 32 System.out.println(id); 33 } 34 } 35 }