PTIT Summer Round 4

Embed Size (px)

DESCRIPTION

ACM 2014

Text of PTIT Summer Round 4

  • PTIT Summer 2014 Round 4

    Problem A: Nam chm Time limit: 1s

    T ang hc v t tnh ca nam chm. Cu bit rng nam chm c 2 cc m v dng, cng cc

    th y nhau, khc cc th ht nhau.

    Mt ln cu sp ln lt cc nam chm theo chiu dc, nhim v ca bn l xem c bao nhiu

    khi nam chm nm ri nhau.

    Nam chm c biu din biu 2 k t 0 v 1. 0 l cc m, 1 l cc dng.

    Input

    Dng u tin l s nguyn n (1

  • PTIT Summer 2014 Round 4

    Problem B: Cp s cng Time limit: 1s

    Bn c cho mt dy s c n phn t. Nhim v ca bn l tm tt c cc s x tha mn: x xut

    hin trong dy s cho v cc v tr ca x trong dy to thnh mt cp s cng.

    Input

    Dng u tin l s nguyn n (1

  • PTIT Summer 2014 Round 4

    Problem C: S tuyt p Time limit: 1s

    To c mt s thch c bit khi rt thch cc s c to bi 2 ch s a, b, cu gi cc s nh

    vy l s p. c bit hn na, cc s p c tng cc ch s l mt s p, cu gi l s tuyt

    p.

    V d: To thch cc s 1 v 3, s 11, 311 l s p cn 12 th khng.

    S 111 l s tuyt p, 11 th khng phi.

    Gi To mun bit c bao nhiu s tuyt p c n ch s, tt nhin ch s 0 khng ng u.

    Kt qu c ly d cho (10 ^ 9 + 7).

    Input

    Dng duy nht c 3 s nguyn a, b, n ( 1

  • PTIT Summer 2014 Round 4

    Problem D: Chui c bit Time limit: 1s

    T rt thch chi vi cc chui s. Mt chui s a[] c T gi l c bit nu:

    + a[1] = q vi q l 1 s nguyn no .

    + a[i] = a[i-1] + ((-1) ^ (i +1) )* p, vi p l 1 s nguyn no .

    Gi T ang c mt chui b, cu cn tm chui con di nht ca b l chui c bit.

    Mt chui con ca b l chui c to bi b khi gi nguyn th t v xa i mt s phn t no

    hoc khng xa mt phn t no c.

    Cc bn gip T nh!

    Input

    Dng u tin l s nguyn n( 1

  • PTIT Summer 2014 Round 4

    Problem E: Truy vn Time limit: 2s

    T thch vic tm chui s c bit, To th li thch x l vi cc truy vn trn mng. Cu ang

    c mt dy s v phi tr li cc cu hi, trn mt on ca con gm cc phn t lin tip c

    bao nhiu s m s ln xut hin ca n bng chnh n.

    Cc bn cng chi vi To cho vui nh!

    Input

    Dng u tin gm 2 s nguyn n, m (1

  • PTIT Summer 2014 Round 4

    Problem F: Xp hng. Time limit: 1s

    Bob c ng ch giao nhim v lm bo v qun bar. Qun bar mi khai trng v m ca

    min ph, v vy rt ng khch ti. Do , mi ngi phi xp hng ln lt vo trong qun

    bar, v nhim v ca Bob l duy tr trt t ng li.

    duy tr cn bng gii tnh trong qun bar, ng ch mong mun s chnh lch gia nam v

    n khng vt qu X (X

  • PTIT Summer 2014 Round 4

    Gii thch test 2:

    Ti v tr ngi th 5, nu ngi ny vo, s lm mt cn bng gii tnh, v vy ngi ng

    th 2 (W) s c vo trc. Hng i lc ny cn li MWMMMWWMW, trong qun bar hin ti c 3

    nam v 2 n.

    Lt th 6 v th 7, hai ngi tip vo bnh thng, hng i cn li MMMWWMW, trong qun bar

    hin ti c 4 nam v 3 n.

    Lt th 8, ngi tip (M) vo bnh thng, trong qun bar c 5 nam v 3 n. Sau lc ny

    khng th cho ai vo c na, Bob s ng ca qun bar li.

  • PTIT Summer 2014 Round 4

    Problem G: Vn chuyn bnh piza Time limit: 2s.

    T v To c nhn vo lm thm ti mt ca hng bnh piza. Nhim v ca T l ng gi,

    xp bnh vo hp cn thn, cn nhim v ca To l vn chuyn bnh theo a ch yu cu ca

    khch hng.

    Nh bp lm bnh lin tc, mi ln lm mt chic bnh c kch thc khc nhau. T phi qun l

    mt hng i nhng chic bnh piza. T lun sp xp danh sch nhng chic bnh ch c

    mang i ny theo th t ng knh tng dn. Mi ln c yu cu ca khch hng, T s mang ra

    chic bnh c kch thc bng phn t trung v trong tp hp tt c nhng chic bnh m T hin

    ti ang qun l. C ngha l nu hin ti T qun l c ci bnh, nu c l, T s mang i chic

    bnh c kch thc ln th (c+1)/2; trong trng hp c chn, T s ly i chic bnh c kch

    thc ln th c/2+1.

    Ca hng lun ghi li nhng hot ng ca mnh, gm mc thi gian mt chic bnh c ra l

    v mc thi gian c mt chic bnh c chuyn i. Vi cch lm k d ca T, ca hng ny kh

    au u trong vic lit k nhng chic bnh no c xut xng. Cho bit cc mc s kin

    xy ra theo thi gian, cc bn hy hy gip ca hng ny lp ra danh sch nhng chic bnh

    c bn i.

    Input:

    C 1 b test, gm nhiu dng, c th hin theo trnh t thi gian.

    Mi dng c th l mt s nguyn n, hoc mt k t #. S nguyn dng n th hin ti thi

    im , mt chic bnh piza c ng knh l n c lm xong v chuyn sang khu ng gi.

    K t # th hin ti thi im c yu cu ca khch hng, T s mang cho To mt chic

    bnh piza To vn chuyn ti a ch yu cu ca khch hng.

    Output:

    In ra kch thc cc chic bnh piza m To vn chuyn theo ng th t.

  • PTIT Summer 2014 Round 4

    Sample test:

    Test 1 Test 2

    Input:

    1

    2

    3

    4

    #

    #

    #

    #

    Output: 3

    2

    4

    1

    Input:

    1

    #

    2

    #

    3

    #

    4

    #

    Output: 1

    2

    3

    4

  • PTIT Summer 2014 Round 4

    Problem H: Hnh trnh du lch Time limit: 2s

    Bob ang trong k ngh h ti b bin. Tht khng may, cc khch sn gn b bin ht phng

    v anh phi trong trung tm thnh ph. Anh thu hn mt chic xe my c th vi vu khp

    thnh ph bin ny. m nay, a im m anh mun ti khng phi l bi bin nh thng

    ngy, m l thp truyn hnh cao nht ca thnh ph.

    H thng giao thng trong thnh ph kh phc tp. C N nt giao thng v M con ng mt

    chiu ni gia cc im giao thng. Khch sn ca Bob nm gn nt giao thng th nht, cn

    thp truyn hnh ngay gn nt giao thng th N. i ng bui ti nn Bob rt mun trnh cc

    khc cua, anh ch mun gi ga v phng u trn ng. V vy, Bob mun chn cho mnh mt

    hnh trnh sao cho gc cua ln nht trong hnh trnh l nh nht. Tuy nhin, anh cng khng

    mun qung ng i qu di, v xe ca anh ch xng i c ti a khong cch bng D.

    Cc bn hy gip Bob chn ra hnh trnh ti u, v tnh gc cua ln nht trong hnh trnh ti u

    ny.

    Input :

    Dng u tin gm 3 s nguyn N, M, D ln lt l s nt giao thng, s ng mt chiu v

    khong cch ln nht m Bob mong mun. (N

  • PTIT Summer 2014 Round 4

    Sample test

    Test 1 Test 2 Test 3

    Input:

    5 6 500

    -100 0

    -100 100

    0 200

    100 100

    100 0

    1 2

    1 3

    2 3

    3 4

    3 5

    4 5

    Output: 90.00000000

    Input:

    5 6 450

    -100 0

    -100 100

    0 200

    100 100

    100 0

    1 2

    1 3

    2 3

    3 4

    3 5

    4 5

    Output: 126.86989765

    Input: 5 12 440

    -100 0

    -100 100

    0 200

    100 100

    100 0

    1 2

    1 3

    3 1

    2 3

    3 2

    3 4

    4 3

    3 5

    5 3

    4 5

    5 4

    5 1

    Output: Impossible

    Gii thch test 1: Hnh trnh ti u l 1-2-3-4-5. Gc cua ln nht l ti nt 3 bng 180-90 = 90

    .

    Gii thch test 2: Hnh trnh ti u l 1-3-5. Gc cua ln nht ti nt 3.

  • PTIT Summer 2014 Round 4

    Problem I: Chia phn Time limit: 1s.

    Sau gi hc, T cng cc bn r nhau i n xc xch. Mi ngi cng nhau gp tin. C tt c M

    ngi nhng s tin m T cng cc bn c ch mua c N ci xc xch.

    cho cng bng th T s chia u N chic xc xch cho tt c mi ngi. Vi mt con dao

    trong tay, cc bn hy gip T tnh xem T cn ct t nht bao nhiu pht?

    Input

    Gm 2 s nguyn n v m (n, m

  • PTIT Summer 2014 Round 4

    Problem J: Nui cy vi khun Time litmit: 2s

    Phng th nghim XYZ thc hin nui cy mt loi vi khun trn mt bng vung kch thc

    vi cc dng v cc ct nh s t 1 ti . S c th vi khun trong mt vung ban u

    l 0 v ngi ta c th tin hnh cy thm mt s c th vi khun trong mi .

    C hai loi yu cu:

    S : Cy thm c th vi khun vo ( ) ( );

    Ch th Q : Yu cu cho bit tng s c th vi khun trong cc ( ) nm

    trong phm vi , .

    Cho bit mt dy m yu cu thc hin tun t, hy tr li tt c cc yu cu loi Q.

    Input

    Dng 1 cha hai s nguyn dng ;

    dng tip theo, mi dng cha mt yu cu theo th t thc hin.

    Output:

    ng vi mi ch th Q, hy in ra s lng c th vi khun tng ng tnh c.

    Sample test:

    Input:

    4 7

    S 2 2 2

    S 4 3 3

    Q 2 2 4 4

    S 1 2 5

    S 4 3 6

    Q 1 1 4 4

    Q 1 1 2 2

    Output:

    5

    16

    7