Advertisement
Guest User

Untitled

a guest
May 29th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import Data.List
  2. import Data.Function
  3. import Control.Monad
  4.  
  5. groupOn f = groupBy ((==) `on` f) . sortBy (compare `on` f)
  6. uniq = map (!! 0) . groupOn id
  7.  
  8. -- 场景:假设a得到了数字x,b得到了数字y
  9. -- 可看做二分图,其中possibleX,possibleY是顶点,possible是边,(aGuessY x)和(bGuessX y)分别表达x点和y点的邻接点集
  10. possible = [(5, 15), (5, 16), (5, 19), (6, 17), (6, 18), (7, 14), (7, 16), (8, 14), (8, 15), (8, 17)]
  11.  
  12. possibleX = uniq $ [i | (i, j) <- possible]
  13. possibleY = uniq $ [j | (i, j) <- possible]
  14.  
  15. aGuess x = [(i, j) | (i, j) <- possible, i == x]
  16. bGuess y = [(i, j) | (i, j) <- possible, j == y]
  17.  
  18. aGuessY x = map (\(i, j) -> j) $ aGuess x
  19. bGuessX x = map (\(i, j) -> i) $ bGuess x
  20.  
  21. -- A说“我不知道,并且我确定你也不知道”
  22. xs = [x | x <- possibleX, (length $ aGuessY x) > 1, (all ((>1) . length) [bGuessX y | y <- aGuessY x])]
  23.  
  24. -- B说“我现在知道了!”
  25. ys = [y | y <- (uniq $ join $ map aGuessY $ xs), (length $ intersect (bGuessX y) xs) == 1]
  26.  
  27. -- A说“我现在也知道了!”
  28. xs2 = [x | x <- intersect xs (uniq $ join $ map bGuessX $ ys), (length $ intersect (aGuessY x) ys) == 1]
  29.  
  30. -- 结论
  31. rst = [(x, y) | x <- xs2, y <- intersect (aGuessY x) ys]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement