0
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

第19回オフラインリアルタイムどう書くの問題をPythonで

問題はこちら
http://nabetani.sakura.ne.jp/hena/ord19nebasec/

他の解答例はこちら
http://qiita.com/Nabetani/items/9810b301648099028bf0

from math import floor

def solve(data):
    bad = map(int, data.split(','))
    hdd = [[0]*n for n in (0, 8, 16, 24, 32)]
    def mark(t,s): hdd[t%len(hdd)][s%len(hdd[t])] += 1
    def side(t,s): return int(floor((s - 0.5) / track * t + 0.5))
    for track, sector in ((b/100, b%100) for b in bad):
        mark(track, sector-1)
        mark(track, sector+1)
        if track > 1:
            for s in range(side(track-1, sector), side(track-1, sector+1)+1):
                mark(track-1, s)
        if track < 4:
            for s in range(side(track+1, sector), side(track+1, sector+1)+1):
                mark(track+1, s)
    return ','.join(map(str, (t*100+s for t in (1,2,3,4) for s in range(8*t)
                              if hdd[t][s]>1 and t*100+s not in bad))) or "none"

def test(data, correct):
    answer = solve(data)
    print 'xo'[answer == correct], data, correct, answer

0, test( "400,401,302", "300,301,402" );
1, test( "105,100,306,414", "none" );
2, test( "100", "none" );
3, test( "211", "none" );
4, test( "317", "none" );
5, test( "414", "none" );
6, test( "100,106", "107" );
7, test( "205,203", "102,204" );
8, test( "303,305", "304" );
9, test( "407,409", "306,408" );
10, test( "104,103", "207" );
11, test( "204,203", "102,305" );
12, test( "313,314", "209,418" );
13, test( "419,418", "314" );
14, test( "100,102,101", "201,203" );
15, test( "103,206,309", "205,207,308,310" );
16, test( "414,310,309", "206,311,413" );
17, test( "104,102,206,307,102,202", "101,103,203,204,205,207,308" );
18, test( "104,206,308,409,407", "103,205,207,306,307,309,408,410" );
19, test( "313,406,213,301,409,422,412,102,428", "none" );
20, test( "101,300,210,308,423,321,403,408,415", "none" );
21, test( "304,316,307,207,427,402,107,431,412,418,424", "none" );
22, test( "205,408,210,215,425,302,311,400,428,412", "none" );
23, test( "200,311,306,412,403,318,427,105,420", "none" );
24, test( "105,305,407,408,309,208,427", "104,209,306,406" );
25, test( "311,304,322,404,429,305,316", "203,303,321,405,406,430" );
26, test( "210,401,316,425,101", "211,315" );
27, test( "414,403,404,416,428,421", "303,415" );
28, test( "207,300,103,211,428", "104,206" );
29, test( "322,314,310", "none" );
30, test( "427,200,215", "100,323" );
31, test( "311,402,424,307,318,430,323,305,201", "200,204,301,302,306,322,423,425,431" );
32, test( "425,430,408", "none" );
33, test( "202,320,209,426", "319,427" );
34, test( "430,209,302,310,304,431,320", "202,303,323" );
35, test( "208,206,406,424,213,312", "207,311,313" );
36, test( "420,302,313,413,317,402", "301,403" );
37, test( "319,306,309,418,204,411", "305,307,308,412" );
38, test( "400,308,105,430,203,428,209", "104,210,429,431" );
39, test( "200,305,214", "215" );
40, test( "214,408,410,407,317,422", "306,316,409,423" );
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
0
Help us understand the problem. What are the problem?