Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求大佬看一下我这个为什么会re,几个测试数据都过了没有出现问题import java.util.Collections; import java.util.Scanner; import java.util.ArrayList; public class smallD { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(true) { int n = sc.nextInt(); sc.nextLine(); ArrayList list = new ArrayList(); for (int i = 0; i < n; i++) { String[] ss = sc.nextLine().split(" "); int l = ss.length; ArrayList li = new ArrayList(); for (int j = 0; j < l; j++) li.add(Integer.parseInt(ss[j])); Collections.sort(li); list.add(sub(li)); } for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } } public static int sub(ArrayList<Integer> ii) { int r=0; int l=ii.size(); int n=l/2; if (l%2==1) { if (ii.get(0)==0) { r += ii.get(1) * Math.pow(10, n);ii.remove(1); } else r+=ii.get(0)*Math.pow(10,n);ii.remove(0); r+=re(ii); } else { int minD=minD(ii); r+=minD*Math.pow(10,n-1); r+=re(ii); } return r; } private static int re(ArrayList<Integer> ii) { int r=0; int l=ii.size();int n=l/2;int m=n; for (int i=0;i<n;i++) { r+=(ii.get(i)-ii.get(l-i-1))*Math.pow(10,m-1); m--; } return r; } public static int minD(ArrayList<Integer> li) { int min=10;int record=-1; for (int i=0;i<li.size()-1;i++) { if (li.get(i)==0)continue; int sub=li.get(i+1)-li.get(i); if (sub<min) { min = sub;record=i; } } li.remove(record);li.remove(record); return min; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator