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 |
这道题感觉有点问题吧。对于付出多的人,平均值应该取上界,对于付出少的人,平均值应该取下界吧,这样才能最小阿。 import java.io.*; import java.util.*; import java.math.*; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter( System.out)); //Scanner cin = new Scanner(System.in); while(true){ int n = Integer.parseInt(in.readLine().trim()); if(n == 0) break; long[] data = new long[n]; long total = 0; for(int i = 0; i < n; i++){ String[] s = in.readLine().split("\\."); data[i] = Long.parseLong(s[0]) * 100 + Long.parseLong(s[1]); total += data[i]; } long res1 = 0; long res2 = 0; long price1 = (total + n - 1) / n; long price2 = total / n; for(int i = 0; i < n; i++){ if(data[i] > price1){ res1 += data[i] - price1; } else if(data[i] < price2){ res2 += price2 - data[i]; } } long res = Math.min(res1, res2); if(res % 100 >= 10) out.write("$" + (res / 100) + "." + (res % 100) + "\n"); else out.write("$" + (res / 100) + ".0" + (res % 100) + "\n"); } out.flush(); } } 这是我的程序,没有用浮点数来做,wr死了。 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator