I am reading a book of algorithms in my time. Here is a question to which I have my own answer, but I'm not entirely sure. What do you think? Thanks!
Question: There are 2 television network companies, even if it is assumed that A and B, each of them plans a schedule of television programs in n time slots per day. Each of them puts its n programs in these slots. While each program has a rate based on last year’s popularity, these figures differ from each other. A company wins a slot when its show is at a higher level than that of its opponent. Is there a correspondence of the schedule that A made the schedule of S and B, made the schedule of T, and (S, T) is stable, so that none of the networks can unilaterally change its own schedule and win more time intervals.
, , (.. , , , ).
Proof
, , - . , . , . .
, , .
( ), ( , ).
.
, , , , . ( )
Haskell:
hasStable :: Ord a => [a] -> [a] -> Bool hasStable x y = score x y + score y x == 0 -- score is number of slots we win minus number of slots they win -- in our best possible response schedule score :: Ord a => [a] -> [a] -> Integer score others mine = scoreSorted (revSort others) (revSort mine) where -- revSort is sort from biggest to smallest revSort = reverse . sort scoreSorted :: Ord a => [a] -> [a] -> Integer scoreSorted (o:os) (m:ms) | m > o = -- our best show is better then theirs -- we use it to beat theirs and move on 1 + score os ms | otherwise = -- their best show is better then ours -- we match it with our worst show -- so we could make use of our big guns -1 + score os (m : ms) scoreSorted _ _ = 0 -- there are no shows left > hasStable [5,3] [4,2] False > hasStable [5,2] [3,4] True
. , 2 . A p1 (5.0) p2 (3.0); B p3 (4.0) p4 (2.0);
: S1: p1, p2 S2: p2, p1 B : T1: p3, p4 T2: p4, p3
, : (S1, T1) (S1, T2) (S2, T1) (S2, T2)
(S1, T1) - (p1, p3) (p2, p4) 2: 0 - , B T2, : (S1, T2) - (p1, p4) (p2, p3) 1: 0
Vise versa, .
-, 2, . TV-1:
Show1 has a rating of 20 points. show2 has a rating of 40 points.
TV-2:
Show1 has a rating of 30 points. Show2 has a rating of 50 points.
Then he clearly shows that the match is unstable.
Source: https://habr.com/ru/post/1715805/More articles:Mysql - Insert queries by inserting funny characters - sqlHow to make create_or_update in sqlobject? - pythonКак удалить файл на основе даты его создания в Perl? - fileDisable or ignore mousedown in select field in firefox - javascriptLooking for an alternative to .NET CryptoStream? - c #Java Stringparsing с Regexp - javaGNU screen: `` quote programmer '' in Readbuf? - gnu-screenData Warehouse Type Bit Data Bit - typesLua десятичный знак? - functionGNU Screen: environment variables - environment-variablesAll Articles