Created
November 25, 2013 10:12
-
-
Save PRotondo/7639206 to your computer and use it in GitHub Desktop.
My solutions to the problems from Facebook Hackercup 2014 Qualification Round.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gets.to_i.times do |i| | |
n, m, ps = gets.split.map(&:to_i) | |
players = (1..n).map do | |
name, sp, h = gets.split | |
sp, h = sp.to_i, h.to_i | |
[sp,h,name] | |
end | |
players.sort! | |
players.reverse! | |
team1, team2 = [], [] | |
players.each_with_index do |pl,i| | |
name = pl.last | |
if (i % 2) == 0 | |
team1.push([0,i,name]) | |
else | |
team2.push([0,i,name]) | |
end | |
end | |
playing1 = team1.take(ps) | |
playing2 = team2.take(ps) | |
notplaying1 = team1.drop(ps) | |
notplaying2 = team2.drop(ps) | |
n1 = team1.length | |
n2 = team2.length | |
m.times do | |
playing1.map!{ |x,y,z| [x+1,y,z]} | |
playing2.map!{ |x,y,z| [x+1,y,z]} | |
playing1.sort! | |
playing2.sort! | |
if n1 > ps | |
p1 = playing1.pop | |
notplaying1.sort! | |
r1 = notplaying1.shift | |
playing1.push(r1) | |
notplaying1.push(p1) | |
end | |
if n2 > ps | |
p2 = playing2.pop | |
notplaying2.sort! | |
r2 = notplaying2.shift | |
playing2.push(r2) | |
notplaying2.push(p2) | |
end | |
end | |
puts "Case \##{i+1}: #{(playing1.map(&:last)+playing2.map(&:last)).sort.join(" ")}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Data.List | |
solve c = do | |
n <- fmap read getLine :: IO Int | |
m <- replicateM n getLine | |
let res = filter (not . null) [ [(i,j) | j <- [0..n-1], ((m!!i)!!j) == '#'] | |
| i <- [0..n-1] ] -- look at the rows that have blocks | |
let cons = map (fst . head) res -- row numbers | |
let cons2 = map snd $ head res -- column numbers of first non-filtered row | |
let size = length cons2 == length cons -- dimensions = good | |
let range = isRange cons && isRange cons2 -- check that we have full ranges | |
let equal = equals $ map (map snd) res -- taking first row -> unimportant | |
case size && equal && range of | |
True -> putStrLn $ "Case #" ++ show c ++ ": YES" | |
_ -> putStrLn $ "Case #" ++ show c ++ ": NO" | |
where | |
equals [] = True | |
equals (x:xs) = all (==x) xs | |
isRange a@(x:_) = and $ zipWith (==) a [x..] | |
main = do | |
t <- fmap read getLine :: IO Int | |
mapM_ solve [1..t] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <cstdio> | |
#include <string> | |
#include <map> | |
#include <iostream> | |
#include <algorithm> | |
#include <cstring> | |
#include <queue> | |
#include <cassert> | |
using namespace std; | |
#define PII pair<int,int> | |
#define EPS 0.0 | |
double dp[101][101][1001]; | |
double solve(int K, double ps, double pr, int pi, int pu, double pw, int pd, double pl) | |
{ | |
double ans = 0.0; | |
for (int i = 0; i <= K; i++) | |
for (int j = 0; j <= K; j++) | |
for (int r = 0; r <= 1000; r++) | |
dp[i][j][r] = 0.0; | |
dp[0][0][pi] = 1.0; | |
for (int s = 0; s < 2*K - 1; s++) | |
{ | |
int a = max(0,s + 1 - K); | |
int b = min(K,s+1); | |
for (int i = a; i < b; i++) | |
for (int j = 0; j <= 1000; j++) | |
if (dp[i][s-i][j] > EPS) | |
{ | |
double p = dp[i][s-i][j]; | |
double PW = (j / 1000.0) * ps + ((1000-j)/1000.0) * pr; | |
dp[i+1][s-i][min(1000,j+pu)] += p*PW * pw; | |
dp[i+1][s-i][j] += p*PW * (1-pw); | |
double PL = 1 - PW; | |
dp[i][s-i+1][max(0,j-pd)] += p*PL * pl; | |
dp[i][s-i+1][j] += p* PL * (1-pl); | |
} | |
} | |
for (int j = 0; j < K; j++) | |
for (int r = 0; r <= 1000; r++) | |
ans += dp[K][j][r]; | |
return ans; | |
} | |
int main(void) | |
{ | |
int T; | |
scanf("%i",&T); | |
for (int i = 1; i <= T; i++) | |
{ | |
int K; | |
double ps, pr, pi, pu, pw, pd, pl; | |
cin >> K; | |
cin >> ps >> pr >> pi >> pu >> pw >> pd >> pl; | |
double ans = solve(K, ps, pr,(int)(pi * 1000), (int)(pu * 1000), pw, | |
(int)(pd*1000), pl); | |
fprintf(stderr,"Case #%i: %.6f\n",i,ans); | |
printf("Case #%i: %.6f\n",i,ans); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment