GCJ2011 Round 1B A "RPI"
問題:https://code.google.com/codejam/contest/dashboard?c=1150485#s=p0
Google Code Jam nise..nabeで参加.
ある総当たりの勝敗結果が与えられる.各参加者に対してRPIという評価方法がある.これは,自分の勝率WP,対戦相手の自分との対戦を除いた勝率OWP,対戦相手のOWPの平均OOWPという評価項目が計算できるとして, RPI=0.25*WP+0.50*OWP+0.25*OOWPという風に計算する.このRPIを各参加者について求める.
単に式をコードにするだけ.自作Scannerが文字列に弱かったらしく,めちゃくちゃ時間かかってヒヤヒヤしてたから同時にjava.util.Scannerの実装を走らせたら一瞬で終わってなんか悲しい.
コード
import java.io.*; import java.util.*; public class A { public static void main(String[] args) { Scanner s = new Scanner(System.in); for (int t = 1, T = s.nextInt(); t <= T; ++t) { n = s.nextInt(); cs = new char[n][]; for (int i = 0; i < n; ++i) { cs[i] = s.next().toCharArray(); } double[] r = new double[n]; for (int i = 0; i < n; ++i) { r[i] = rpi(i); } System.out.println("Case #" + t + ":"); for (double x : r) { System.out.println(x); } } } static int n; static char[][] cs; static double rpi(int i) { return (wp(i, -1) + 2 * owp(i) + oowp(i)) / 4; } static double wp(int i, int b) { int c = 0, r = 0; for (int j = 0; j < n; ++j) { if (cs[i][j] != '.' && (b < 0 || j != b)) { ++c; r += cs[i][j] - '0'; } } return c > 0 ? (double) r / c : 0; } static double owp(int i) { double c = 0, r = 0; for (int j = 0; j < n; ++j) { if (cs[i][j] != '.') { ++c; r += wp(j, i); } } return c > 0 ? r / c : 0; } static double oowp(int i) { double c = 0, r = 0; for (int j = 0; j < n; ++j) { if (cs[i][j] != '.') { ++c; r += owp(j); } } return c > 0 ? r / c : 0; } }