Pre Acm Ptit Round 1

Embed Size (px)

DESCRIPTION

ACM 2014

Text of Pre Acm Ptit Round 1

  • PRE ACM PTIT 2015 ROUND 1

    Problem A: Cc cp giai tha

    Time limit: 1s

    Axe chi mt tr chi vi Lina.

    H nh ngha hm F(x) vi s x nguyn dng l tch giai tha cc ch s ca x. V d

    F(135) = 1! * 3! * 5! = 720.

    u tin, h chn mt s a c n ch s v c t nht mt ch s ln hn 1, c th c ch s

    khng u. Sau h tm mt s nguyn dng x ln nht tha mn:

    1. X khng cha ch s 0 hoc 1

    2. F(x) = F(a)

    Hy gip Axe v Lina tm ra c s .

    Input:

    Dng u tin cha s b test T ( T < 100 ).

    Mi test gm mt dng cha s n v s a (1

  • PRE ACM PTIT 2015 ROUND 1

    Problem B: Rubik i siu th

    Time limit: 1s

    Rubik i siu th mua n mn v vo trong xe y ri mang ra quy thanh ton. Bit mt

    hng th i c gi l C_i v ngi thu ngn cn thi gian T_i c th xc nhn mt hng ny.

    Nhng Rubik l thnh n trm nn anh ta sp xp th t cc mt hng cho ngi thu ngn

    xc nhn theo ca mnh, khi ngi thu ngn bn lm th tc l Rubik s c th n trm 1

    mn t chnh xe ca mnh v mt 1 giy.

    Bn hy tnh xem s tin ti thiu m Rubik phi tr l bao nhiu?

    Input:

    Dng u tin cha s mt hng n (1

  • PRE ACM PTIT 2015 ROUND 1

    Problem C: Tr chi tr tu

    Time limit: 5s

    Tide v Kunkka thch thc nhau v mt tr chi. H vit tt c cc s nguyn dng t 1 n

    n. Ti lt ca mi ngi, ngi s chn mt s nguyn trong cc s h va vit ra, nu

    chn s x th cc s l ly tha (nguyn dng) ca x s khng c chn cho cc lt tip

    theo.

    Tt c u chi vi chin thut ti u, vy nu Tide chn trc th bn hy cho bit ai s l

    ngi chin thng?

    Ngi thua cuc l ngi m n lt ca mnh khng cn s no chn.

    Input:

    Dng u tin cha s b test T (1

  • PRE ACM PTIT 2015 ROUND 1

    Problem D: Du hnh gia cc v sao

    Time limit: 1s

    Sau chuyn du hnh gia cc v sao nhm Cooper tm c hnh tinh Edmunds ph hp vi

    s sng thin h Blabla, anh gi thng tin v cho con ngi Ngn H qua l su. V di

    chuyn sang thin h Blabla tn kh nhiu ti nguyn nn cn tp hp tt c ngi dn trn

    mt trm bt k.

    C n trm ang trn qu o ca n hnh tinh hay thin th khc nhau ln cn trong h mt

    tri, mi hnh tinh c d_i c dn ang sinh sng, v c n-1 khng gian 5 chiu di chuyn

    trc tip gia hai trm v ch c mt cch duy nht di chuyn gia hai trm bt k. Mi

    khng gian nh vy ni hai trm u v v, di chuyn 1 ngi t trm ny sang trm kia cn

    mt lng ti nguyn l w.

    May thay cc nh khoa hc nghin cu ra mt cch chuyn ng i trn qua mt khng

    gian nhiu chiu hn, vi cch vic di chuyn gia hai trm gn nh khng tn ti

    nguyn, nhng c mt rc ri l s nhiu trong khng gian trn nn ch c th chuyn ti a k

    khng gian c sang khng gian mi.

    Cc nh lnh o ang tm mt cch di chuyn sao cho tn t ti nguyn nht, bn hy gip

    h.

    Input

    Dng u tin cha s b test, mi b test cu trc nh sau:

    Dng u tin cha hai s nguyn n v k (1 n 1000, 0 k n 1).

    Dng th hai cha n s t nhin, di l s dn ang sng trn trm th i (1 d_i

    100000).

    n-1 dng cn li, dng th i cha ba s nguyn dng ui, vi v wi (1 u_i, v_i n, 1

    w_i 100000).

    Output

    In ra kt qu mi test trn mt dng.

    Example

    Input: Output:

    1

    5 3

    8 5 1 8 7

    1 3 8

    2 3 9

    3 5 7

    3 4 8

    45

  • PRE ACM PTIT 2015 ROUND 1

    Problem E: Sn xut kem

    Time limit: 1s

    Nh my Blabla ang sn xut kem Bla. Kem c bm vo mt khay hnh ch nht kch

    thc m x n nh ri a vo my lnh. My phun kem l mt cnh tay c hai u phun kem

    t trn hai khc nhau. V hai u phun trn cng tay r bt nn cc bc di chuyn ca

    chng ng b ha vi nhau, nu my th nht di chuyn theo mt vec t, th tay th hai

    cng c di chuyn theo vect y. Ban u cc trn khay khng cha kem.

    Tay r bt di chuyn theo quy lut sau:

    C 2 my phun u t trn 2 khc nhau v u hot ng.

    My phun di chuyn qua no th y c phun kem.

    Tay r bt di chuyn song song vi cc cnh ca khay.

    Cc my phun khng c di chuyn ra bn ngoi khay.

    Blab l nhn vin k thut ca nh my Blabla, anh c giao nhim v vit chng trnh

    tnh s khng c phun kem, cc bn hy gip anh y.

    Input

    Dng u tin cha s b test T (khng qu 150 test), T dng sau mi dng cha 1 b test

    cha 6 s nguyn dng ln lt m, n, x1, y1, x2, y2.

    Trong m, n ln lt l s ct v s hng ca khay, (x1, y1) l ta ca my phun th

    nht (x1, y1 l v tr ct, hng), (x2, y2) l ta ca my phun th hai (x2, y2 l v tr ct,

    hng). Cc ct c nh du t tri sang phi, cc hng c nh du t trn xung di.

    Gii hn: 2 n, m 10^9, 1 x1, x2 m, 1 y1, y2 n.

    Output

    Vi mi b test in ra kt qu trn 1 dng.

    Example

    Input: Output:

    2

    4 4 1 1 3 3

    4 3 1 1 2 2

    8

    2

  • PRE ACM PTIT 2015 ROUND 1

    Problem F: Cipher

    Time limit: 1s

    0xb0b0 team l 1 i ca PTIT ang tham gia cuc thi CTF(Capture The Flag). tm

    c Flag ca mt cu hi, bn phi tri qua rt nhiu th thch. i ang tin hnh gii

    quyt 1 bi Cipher. Sau 1 hi thi c rt quyt lit, 0xb0b0 team i n kt lun:

    Secret key (kha b mt) c th ly c bng cch ct kha Public key (cng khai)

    thnh 2 phn. Kha cng khai l 1 s t nhin rt ln, c th c ti 1 triu ch s.

    0xb0b0 team mun tm mt cch sao cho c th ct publickey thnh 2 s nguyn dng

    x v y sao cho x chia ht cho a v y chia ht cho b (vi a v b l 2 s cho trc). C x v y

    u khng c c ch s 0 u.

    Hy gip 0xb0b0 team tm cch ct public key.

    Input

    Dng th nht cha public key 1 s nguyn dng (khng cha ch s 0 u) c

    di t 1 n 10^6 ch s.

    Dng tip theo bao gm 2 s nguyn dng cch nhau bi 1 du cch a, b

    (1a,b10^8).

    Output

    Dng u tin in "YES" nu c cch ct c public key. Trong trng hp ny, in 2 dng

    tip theo l 2 s x, y sao cho x b nht c th.

    Trng hp cn li, tc l khng tn ti cch ct, in "NO" v khng in g thm.

    Example

    Test 1 Test 2 Test 3

    Input:

    116401024

    97 1024

    Output:

    YES

    11640

    1024

    Input:

    284254589153928171911281811000

    1009 1000

    Output:

    YES

    2842545891539

    28171911281811000

    Input:

    120

    12 1

    Output:

    NO

  • PRE ACM PTIT 2015 ROUND 1

    Problem G: Xp hng

    Time limit: 1s

    Trong gi n tra ti Hc vin Cng ngh Bu chnh Vin thng, c n sinh vin ang xp

    hang ly .

    Cm thy chn v phi ng i mt mnh, v vy mi sinh vin vit ra m sinh vin ca

    mnh ng ngay trc v ngay sau ca mnh. Nu khng c ai ng trc hoc khng c

    ai ng sau th vit ra 0.

    t nhin, xe ch nc si i qua, tt c sinh vin phi trnh. Khi h tr li, h khng

    nh v tr ca mnh m ch nh m sinh vin ca ngi n trc v ngi ng sau.

    Hy gip cc sinh vin PTIT tm li v tr ca mnh!!!!

    Input

    Dng u tin gm s t nhin n (2n210^5) s lng sinh vin.

    n dng tip theo, dng th i gm cp s t nhin ai, bi (0ai,bi10^6), vi ai l m sinh

    vin ca ngi ng trc, bi l m sinh vin ca ngi ng sau 1 sinh vin no .

    Nu khng c ai ng trc hoc khng c ai ng sau nhp 0.

    M sinh vin ca mi sinh vin l khc nhau.

    Output

    Trn 1 dng, in ra n s x1,x2,...,xn, danh sch ca cc sinh vin theo th t ban u.

    Example

    Input: Output: 4

    92 31

    0 7

    31 0

    7 141

    92 7 31 141

    Gii thch test bi:

  • PRE ACM PTIT 2015 ROUND 1

    Problem H: S ma thut

    Time limit: 1s

    Mt s ma thut l s m c ghp bi cc s 1, 14, 144. S ma thut khng nht thit

    phi c ghp bi c 3 s trn. Cc bn gip kim tra gip xem mt s c l s ma

    thut khng nh!

    Input

    Mt dng duy nht cha s n (1

  • PRE ACM PTIT 2015 ROUND 1

    Problem I: Ch s cui cng

    Time limit: 1s

    Thy T rt thch th vi nhng con s, c gio giao cho T mt bi tp v rt gn cc

    con s. Php rt gn c thc hin nh sau: t mt s ban u, s mi c to thnh

    bng cch cng cc ch s ca s ban u vi nhau. Sau T phi thc hin tip tc vi

    con s va mi thu c.

    Qu trnh rt gn kt thc khi s thu c ch c duy nht 1 ch s.

    Cc bn hy cng T i tm ch s cui cng ca php rt gn!

    Input

    Dng u tin gm s lng test T (T

  • PRE ACM PTIT 2015 ROUND 1

    Problem J: m s ng i

    Cho mt ma trn N x M, trong c K b chn khng c php i qua. Bn ch c php

    i sang phi hoc i xung di.

    Nhim v ca bn l tm cc ng i t (1, 1) ti (N, M).

    Input:

    Dng u tin gm s test T (T