HO
ffi
Ho Si DAM (Ch0 bi6n)
DO DUC DONG - LE MINH HOANG
. NGUYEN THANH HUNG
TAI IIEU CHUYTN TIN HOC
.rl
I
H
BAt TAPa
OUYEN
1
(Tdi bdn tdn th* nhiit)
runA
xuAr
eAN
ctAo ouc vtEt
ruRnt
Lor NoI uAu
lieu chuyAn Tin hoc - Bdi tQp Quydn 1,2, 3 duoc viet kdm vdi bO
C6c t6c gih
Tdi liQu chuyAn Tin ioc - Quydn 1,2,3 tuong tnrg dd du-o.c xuAt ban'
BQ sdch Tdi
chuyOn'
tham gia biOn soan bO s6ch ld nhtrng thdy gi6o dd vh dang d4y o c6c trudng
gi6b vi6n
ldp chon hoac tham gra c6c kh6-a bdi dudng thi tin hoc qudc tq bdi dudng
mudn
tin cho cilc trUong chuy0n theo cfruong trinh ctra BO Gi6o duc vh Dho tao, mong
vuc
linh
thu6c
tuong
xAy dtpg duo. c c6c tai tieu c6 tinh h0 thong phqc vU t6t c^c ddi
chuy€n tin hoc.
nhau' gdm hai
C6c cu6n Tdi lidu chuyAn Tin hoc ' Bdi tQp ddu c6 cau tnic nhu
phAn:
!
Phdn I - Bii t4p bao gdm tat chc6c bdi mp trong nhfrng chuyen dd ciia sSchTdi
d€ ddn
hAu chuyAn Tin hoc firon' rmg vd cr4c bdi mp bd sung, duoc s6p xep tir
kh6,.til don gi6n ddn Phfc taP.
gifp ban
Phdn II - Hu6ng dan giii bii tap c6 thd ld nhfrng huong d6n chi tidt dd
hidu v)r tim
doc tim duo. c ldi gi6i hoac chi li doan chuong trinh chfnh girip ban doc
Ddi v6i m6t sd bdi tAp
duo. c ldi giii hoac chuong trinh ho)rn chinh dd tham kh6o.
thi c6 thd chi ld ddp 6n hay huong dAn ngan ggn'
Hai bQ s6ch Tdi tiQu chuyan Tin hoc vit Tdi liau chuyan Tin hoc - Bdi ttfrp t'ao
chuy6n
rhinh h0 th6ng tdi liOu kh6 hodn chinh theo dinh huong Chuong trinh c6c
vdi b6
dd chuyen rin hoc da duo. c 86 Gi6o duc vh Ddo tao ban hdnh' Do vay cung
'sdch Tdi liQu chuyAn Tin hoc,b6 s6ch Tdi liAu chuyAn Tin hoc ' Bdi tqp sE ld tdi
ca
li€u thidt thuc phuc vu cho gi6o viOn, hoc sinh cdc trudng chuy0n, l6p chon
tham
Trung hoc phdlhong vb Trung hoc co s&. Ngodi ra, b0 s6ch cdn lh thi lieu
gia
kh6o bd ich cho viec t4p huan sinh vien c6c trudng Dai hoc, Cao ding tham
vi€n Qudc td'
c6c ki thi olympic Tin hoc Sinh vion Todn qudc vd Ki thi lap trinh
Luu y khi srt dqng bQ sdch: C6c bdi tap trong b6 siich ndy du-o.c d6nh so nhu trong
theo'
s6ch li thuydt; c6c bdi tap bd sung drro. c dd 6 muc riOng vd dr4nh sd tidp
b0
Mac dD c6c t6c gia vd Ban biOn tap da cd gang hohn thien nhmg chdLc chan
dd
g6p
d6ng
s6ch cbn nhidu thieu s6t, cdc tdc giA mong nhAn duoc nhidu f kiea
g6p f 'xin gui vri:
s6ch sO hohn thiOn hon, phuc vu ban doc du-o.c hiOu qui hon. C6c
BanTodn-Tin, COng ry cd phdn Dich vu xud't bdn Gido duc Hd NOiNhd xudt bdnGido ducVi€t Nam, l87B,Giringv6, Hd Noi'
CAc tilc giir
P]
1.
t.
a
,rs
t.:
1.,
Bai t?p
cHuytN DE 1. THU4T roAN
va, pnAN ricn THUAT roAn
Phdn t{ch thdi gian thttc hi€n cita d6qn chucng trinh 6 cdc bdi't* 1.1 d€n 1.9.
1.1.
for i::1 to n do
if i mod 2:0 then c:=c+l;
for 1:=1 to n do
if, i nrod 2:0 then c1::c1+1
else c2:=c2+I;
for i::1 9o n do
if i mod 2:0 then
for ir=1 to n do ci=c-f1
a.
1.5.
while 1>0 do
begin _
i . =i .l .=.1 + i.
end;
1
l:6.
ri r. -v,
-n .
repeat,
i
.
=i +T
L
'
lf
.
if i- mod 3:0 then d:=d + i;
until i>n;
,for i-::1 to n-1 do
for j:=i+l- to n do d:=d+1;
1.8.
d: :0;.
l
.
for i::1 to n-2 do
for j:=i+1 to n-1 do
for k': j +1 to n do d::d+1;
1.9.
while n>0
do
begin
n::n div 2;
.l . =.1+1
.
J
end,.
1.10. cho mQt ddy s6 g6m r sr5 nguy€n duong, xdc dfnh xem c6 t6n t4i mQt d6y
con li€n titip c6 t6ng bing k hay kh6ng?
a) Dua ra thuat to6n c6 thoi gian thgc hiQn O(nt).
b) Dua ra thuet to6n c6 thcri gian thpb hiQn O(n').
c) Dua ra thuet to6n c6 thcrigian thqc hiQn O(n).
cnuvtx on 2. clcrrnx rHUc co BAN
2.1.
nguyen kh6ng
cho s li mot x6u chi g6m hai ki tu'0' hopc'1' m6 tA mQt s6
a- O ftQ co s6 Z, hay chuy0nrsO d6 sang hQ co sO t0 (d0 ddi xiu s kh6ng
vuqt qu6 200).
Vi
dg:
101011002: ACro
1010 101 1 I 10000010010001
2.2.
Cho
sO
rz:
ABCL23
rc
nguy6n ducrng N (N < 10).
a) Ph0n tich N thdnh thira s6 nguy6n t6'
b) DOm sti u6c cria N.
c) Tinh t6ng c6c udc cira N'
tra tinh nguY6n to
2.3. Dua ra nhirng sd nho hon ho{c bing 106 md c6ch'ki,5m
cfra Fermat bi sai.
t6 trong doan [t, R].
2.4. Sir dung sdng s6 nguyen t6 liet k6 c6c s6 nguyen
gqi ld sO 'Agp n6u N thoi
2.5. \guoi ta dinh nghTa m6t s6 nguyQn ducrng N dugc
ian *Ot trong hai dt€ukiQn sau:
N bing 9;
Gqi (1g h ti5ng c6c chfi s6 ctra Nthi (M) cflng ld sO dqp'.
N co phii ld s6 dqp
Cho s6 nguy6n duong N (N < 10'oo), hay kigm tri xem
-
kh6ng?
Dtng
(sign: I
sO
l6n bing xdu ki tU vd th6rn th6ng tin i16u
d€ xu li
s6 lcrn le s6 thOng dm, sign: -l ni5u sO l6n ld sO am)
cSch biOu di6n s6 nguy€n
ni5u
nguy€n lon c6 dAu nhu sau:
tlpe bigNum = record
sign: longint;
num: string;
end;
*ay dgng c6c him xir U s6 nguy€n 16n c6 ddu'
phan
Dirng c6ch bi6u di6n s6 nguyen lon bing ming (m6i
iay
2.7.
mQt nhom c6c chfi s6).
a) Hdy,xdy dgng c6c hirm xu
li
s6 nguy€n l6n'
tt
cria ming ld
2.8.
b) st'dung hdm nhan s6 nguy€n ldn vdi s6 nh6 dii tintr
M v6i
TirnKchfi's6 cu6i cung ciaArf (0
Vi du, K
:
2,
cta 2to ld 24.
2.9.
M: 2, y'y': 10, ta c6 2t0 :
r/<
2000.
1024, nhu v6y hai cht s6 cu6i cung
Cho N(l/< t0),nguy€n ducrng clt, a2, ..., aN (a, < loe;.
Tim u6c s6 chung
t?n,.n16,' boi s6 chung ntro ntr6t
,o oen (chri y, BSCNN c6 th6
"t^
rat lon).
i
2.t0. cho hai s6 nguy€n kh6ng dmA,B (0 < A < B..l0too),
tinh s6 lugng
s6
Fibonacci trong dopn [A, B].
2.11. Cho s6 nguyOn duong N(l/< 10'oo), hdy ttchNlhdnh
t6ng crlc s6 Fibonacci
d6i m6t kh6c nhau.
Vidp,N:16:l+5+13.
)'
)'
)'
2.12. cho 1/ ld mQt s6 nguy€n duong kh6ng wgr qu6
r0e. Hay tim s6 chir s6 0 t6n
cirng cua N!
2.13. cho s ld mQt xau m6 t6 s6 nguydn kh6ng dm
o h0 co s6 a, hdy chuytin s6 d6
sang h6 co s6 b (l < o, b < l6rdQ ddi xdu s kh6ng
vuqr qua SO;.
2.14. xdy dung hdm,ki6m tra s6 nguyOn duong i/
c6 phii rd s6 chinh phuong
kh6ng? (N< l0'oo)
2.15. Tinh cn* (0 < k < n< 2000).
i
,,
2.16. Tinh sO Catalann (n < 2000).
2.17. Hdy ddm s6 crich dpt t qudn xe l€n bdn
Sndugc nhau (l
ccr
nx
2.18. Gia thiet N h s6 nguyCn duong. 56 nguy€n'
cua n6. N dugc ggi ld nguon ci,r' M.
n
sao cho kh6ng c6 qudn ndo
M lit t6ngcua // v6i c6c chfr s6
Vf du, N:245, khi d6 M:245 + 2 + 4 + 5:256. Nhu v6y,
ngu6n cua256
\d245. c6 nhfrng so t hong c6 ngu6n vd c6 s6 lai c6
nhi€u
vi ju.so
"g.fn.
216 co 2 ngu6n ld l9g vir 207 .,
cho s6 nguy€n M (M cd kh6ng qu6 100 chir s6) hdy rim ngu6n
nho nh6t cria
n6. N€u Mkh6ngc6 ngu6n tfriOua ra s6 0.
2.19. Tinh sd c6c u6c vd t6ng cric u6c cta
M (N <
100).
2'20' cho m6t chi6c cdn hai dia vd c6c qu6 c6n c6 kh6i
luqng
30, 3t
Hdy chgn c6c qud cdn d€ c6 th6 c6n dugc v4t c6
kh6i luqng
8
, 32,. .
.
// (N < l0'oo).
1
Vi dg,
cAn cdn v4t c6
ly': I I ta cAn sri dr,rng c6c qu6L cdn sau:
kh6i lu.qng
- DIa cdn b€n tr5i: qud cdn 3r vd
- Dia cdn b6n phdi: qu6 c6n
32.
30 vd
vflt
N: I l
.
2.21. D,€m s6 luong dAy nhl ph6n kh6c nhau d0 ddi n md kh6ng c6 hai sO
I ndo
dfng canh nhau.
Vf dg, n:3;tac65ddy000,001,010, 100, 101
2.22. Cho xdu s chi gdm ki tg tir'a' d}n'z'(dg dei xdu s kh6ng vugt qu6 100), hdy
A I
1A
d€m sO hoan vl kh6c nhau cira xdu d6.
Vi
s:'abe' , ta c6 3 hoin vl 'eeb' ,'aba' ,'baa' .
2.23. Nam quytit dinh d6nh s6 trang cho quy6n s6ch cria anh ta tir I d6n N. Hdy
tinh to6n sO luqng chir sO 0 cAn dirng, sd lugng chfr s6 I cdn dung,..., 56
luqng chf sO 9 cdn dirng.
f
dU,
nput: TQp digits.inp gdm mQt dong duy nhAt chria mQt sO .ntr 1l'r< 10'oo).
Output: TQp digits.out co dangg6m 10 ddng,
. Ddng thri nhbt h s6 lugng chir sd 0 cAn dirng,
. Dong thir hai ld si5 lugng chir sd I cAn dirng,...,
. Dong thrf l0 ld s6 luqng chfr s6 9 cAn dirng.
2.24,TANI GIAC SO (EA thi'hoc sinh gi6i Hd Tdy, ndm 2006)
Hinh
bOn mO
^,.
N:
ti
a-
mQt tam gi6c sd c6
1
5. Di tu dinh (sd 7) d€n
d6y tam gi6c bing mQt tlucrng gAp
. khric, m6i bu6c chi dugc di tri s6 o
hdng tr€n xu6ng mQt trong hai s6
s6 hdng
3
r;
I
8
'
dung k€ b6n phii hay b6n trdi 6
hdng dupi vd tinh tich c6c s6 trCn
'
r
4
2
7
5
8
0
4
_Z 6
4
5
ducrng
Vi dg, duong di 7 8 | 4 6 c6tich ld S :
ducrng di7 3
I 7 5 c6 tich ld S :
1344,
735.
YOu cAu: Cho tam gi6c s6, tim tich cua duong tli c6 tich l6n nh6t
lnput: TQp v6n b6n TGS-INP:
. Ddng dAu ti€h chria s6 nguy€n n, (0 < n < l0l);
9
'.tr.dlng. ti6p theo, tu dong thir 2 d€ndong thri N I l: dong thri i c6 (, - 1)
s6 c6ch nhau bcri dAu c6ch (c6c s6 c6 gi6 tri tuyQt ool ttrong wcrr quii 100).
output: Eua ra tQp ian brin TGS.OUT c6 mQt s6 nguy€n ld tich lon nhAt tim du-o. c.
Vi dq:
5
1
3B
810
2144
45-265
2.25.HArNAM (Di thi olympic sinh vi€n, ndm 2009, khtii chuv€n)
Mdt ch6u gdi hing ngdy duoc me giao nhiQm vu d6n tham bd noi. Tir
nhd
minh d6n nhd bd'n6i, cd be phrii dj qua mQt khu rtmg c6 rAt nhi6u loai nAm.
Trong s6 c6c loai n6m, c6 ba loai c6 th6 dn duoc. c6 bd drinh s6 ba loai n6m
6n duoc lAn lugt ld,1,2 vd 3. Ld m6t ngucri ch6u hi€u thrio n6n c6 b6 quy6t
dinh m6i lAn dt5n thdm bd, c6 s€ hrii it nhAt hai loai n6m dn du-o. c d€ nau ,.ip
cho bd. Khu nmg md cd b6 di qua duoc chia thdnh luoi 6 vu6ng gdm m
hdng vd n c6t. c6c hdng ctra lu6i duoc ddnh s6 tu trcn xu6ng du6i bat dAu tir
l, cdn c6c cOt dugc d6nh s6 tu tr6i sang ph6i, bat dau il l. 0 nim giao cira
hdng i vd cQtT c6 roa d0 (t,i). Tr0n m5i 6 w6ng, tru 6 (1, l) vd 6 (m, n) c6c
6 cdn l4i ho{c c6 n6m dOc vd c6 bd kh6ng d6m di vdo (d6nh d6u h
-t), holc
ld c6 dring mot loai nAm c6 thtl [n dugc (ddnh dAu bing so hicu ctra lo4i n6m
d6). Khi c6 b6 di vdo mQt 6 vu6ng c6 n6m [n duoc thi c6 bd s€ h6i loai n6m
moc tr6n 6 d6. Xu6t ph6t tu 6 (1, l), tl6 een duoc nhd bd nQi o 6 (m, n) mQt
c6ch nhanh nhAt co bd lu6n di theo huong sang ph6i hoac xu6ng du6i,
viQc di thdm bd vd h6i n6m trong'nmg s6u gap nguy hi€m boi c6 m6t.con
cho s6i lu6n theo ddi vd mu6n [n thit c6 bd. D6 phong tr6nh ch6 s6i theo d6i
vd 6n thit, co bd quy6t dinh m6i ngdy s€ di theo m6t con ducrng kh6c nhau
(hai con ducrng kh6c nhau n6u chirng kh6c nhau o ft nh6t mQt 6).
YGu cAu: cho b:ing mxn d vu6ng m6 td khu nmg. Hdy tinh s6 con ducrng
kh6c nhau cd bd c6 ttrti aen thdm bd n6i theo c6ch dd n6u o tr6n.
Input: TQp vdn bdn MUSHROOM.INp:
. Ddng dAu chira hai s6 m, n (l 1m, r
' .m ddng ti6p titlp theo, m6i dong chria r's6 nguydn cho bi€t th6ng tin v€
c6c 6 cira khu rtmg (ri€ng gid tri o hai 6 (l,l) vd 6 (m, n) lu6n lu6n bing 0
c6c 6 cdn lai c6 gi6 tri bing -1, hodc l, ho{c 2, hodc 3).
10
)'
Hai s6 li€n ti6p trOn mQt dong c6ch nhau mQt dAu cdch.
outpirt: TQp vdn bdn MUSHROOM.OUT chria rhqt dong ghi mQt s6 nguy€n
,.,l.
la Ket qua Dal toan.
Vi du:
l
34
3
03-L2
3333
3130
2.26.H8 THONG DEN MAU (Di thi Tin hec ftd bdng B, ndm 2009)
D6 trang tri cho 16 ti niem 15 ndm hQi thi Tin hoc ffe toAn qu6c, ban ti5 chric
dd dirng mQt hp th6ng ddn mdu gdm , ddn d6nh sO tu 1 d€n n. tvtSi ddn c6
kh6 n[ng s6ng mdu xanh hoflc miu do. C6c ddn duqc di6u khi€n theo quy
tic sau:
- Ban dAu tdt cd chc ddn d€u sdng mdu xanh.
.
- Sau khi k6t ttrirc chuong trinh thir nh6t cta l5 ti niem; tht ch c6c ddn c6 s.5
thf tu chia h6t cho 2 se d6i miu...Sau khi t6t ttrtc chucrng trinh thu i, tdt ctr
c6c ddn c6 s6 thri tg chia h6t cho i + I se d6i mdu (ddn xanh d6i thirnh mdu
d6 con ddn d6 d6i thdnh mdu xanh).
Minh, mQt thi sinh dU 16 ki nigm dd ph6t hiqn dugc quy lupt tti€u khi€n ddn
vi r6t thich thf v6i hQ th6ng ddn trang tri ndy. Vdo luc chucrng trinh thri ft
'cua bu6i 16 vua krit thirc, Minh tl6 nhAm tinh dugc t4i thoi iti€m d6 c6 bao
nhi6u den xanh vd bao nhi6u ddn do. Tuy nhi€n vi kh6ng c6 m6y tinh n6n
Minh kh6ng chic chin k€t qui cira minh ld ttirng. Cho bi6t hai s6 n vd k
(n, k < 106), em hdy tinh lpi girip Minh xem khi chucrng trinh thri ft cira bu6i
16 vua k6t thirc. c6 bao nhi6u ddn mdu do.
Vi dg:
vtin: l0;k:3.
'
Trgng thdi cdc ildn
Thdi diiim
gat CAu
Xanh:
I
2
3 4 5 67 8 910
Do:
Sau chuong
trinh
I
3'
Xanh: I
Do:
2
4
9
7
5
6
8
l0
ll
Sau chucrng trinh 2
Xanh:
Do:
Sau chucrng trinh 3
5 37
I
2
3
2
J
Xanh: I
Eo:
t
1 5 aT t
,rl
9
t0
910
VAy c6 4 ddn d6 sau chucrng trinh thri 3.
Bii t?p b6 sung
2.27.56 dep
MQt so^^
nguydn duoqg dugc gqi ld dgp rrrr
n6 (trong dpng bi6u di6n thAp phdn) li nrqt
Vf du, 12 ld mQt sO dgp vi
12
+ 22 :
ldq3t-pLurg
c6c cho s6 cria
ri qryer rO5 ta sO ngr{a ri-
,,
F q bir diu tu L
YOu cfru.' cho s6 nguy€n n (t
c6c sd dgp dugc rl6nh sd theo thri tu ting cEu cte
Input: TQp vdn bdn BEAUTY.INP g6m
ki6m thri chria m6t s6 nguydn n.
nhiir
output: T€p vdn bdn BEAUTY.OUT ghi
bQ"ducr. c ghi tr6n mQt dong.
kit qui oa -or
ddng-
mii
oong ld mQt
b,6
uq ki6m thtr, m6i
Vi dq:
2.28.
Eiu
gi6
I
Thdnh ptr6 Ha NQi c6 mQt s5 linh v4t duqc dinh s6 rtu qu u
d€n B (A, B
ld hai s6 nguyOn ducrng A < B). Ldnh d4o thanh ph6 qu1€t dinh b6n ddu gi6
nhirng linh vOt c6 s6 thri tq de.p dc ny ti€n ung lrq dor€ t6o t[ lut mi6n Trung.
Mgt
sO
thri tg dugc ggi ld dgq n6u n6 thod mdn eic til6u kiin sau:
. Ld inQt s6 nguydn ducrng.Zm
.I
d
A 1T S B;
lir mdt s6 nguy€n t6;
' T ld mQt s5 doi xfng (dqc z tu tr6i qua phii gi6ng nhu doc z tu phdi qua
tr6i). Vi dt;1232t li mQt sO AOi xring.
t2
YOu cAu: Cho hai s6 nguy€n duong
A
vit B (A.<
B),hdy tim
sO
lith vdt co s6 tfrir
t.u tlEp.
Input: Tgp vdn bin AUCTION.INP gdm mQt dong chria hai s6 nguy€n
duong A vd B (0 S AS B < l0e).
Output: Dua ra tgp vdn bin AUCTION.OUT !6m mQt sd nguydn
?
vdt c6 sO ttli tW
dgp.
h
sO
linh
Vi dg:
AUCTION. INP
AUCTION. OUT
11111 22222
23
2.29. PAIRS
Cho s6 nguy€n duong n, d6msti c6ch chia c6e sO tu I d6n2n thdnh n nh6m,
;.
I
'
m6i nh6m g6m hai s6 md gi6 tri tuyQt d6i cira hiQu hai sd trong mQt nh6m
bing gi6 tri tuyQt d6i ctra hiQu hai s6 trong nh6m kh6c.
Input: TQp van bdn PAIRS.INP gdm nhidu ddng, m6i dong g6m mQt sd
(n < 106), c6 kh6ng qu6 106 dong.
Output: TQp vdn bin PAIRS.OUT g6m nhi€u do'ng, mdi dong
. tuong img vdidft liqu vdo.
li
r
k6t qud
Vi dq:
PAIRS. INP
PAIRS
1
1
2
2
. O'UT
Gidi thich
C6 hai cdch chia c6c s6
C6ch l- : {I,2L { 3, 4 }
Cach 2: {1,3}l {2,41
tt 1 d6n
4
2.30. FDP
Cho n vd
k(n < 108; k <
l}t\.
Tlm ml6n nh6t sao cho n! chian}t ctro
t{.
lnput: TQp vdn bin FDP.INP:
. Ddng dAu ghi sO f U SO UO f.iein thir (Z< 100);
X. r.
r\
. /- oong
sau, mol oong co nat so nva
A
K.
Output: TQp vdn bdn FDP.OUT g6m Z dong, m6i ddng ld k6t qu6 tim
tuong ung v6i dt liQu vdo.
duo. c
Vf du:.
FDP. INP
2.31. T6ng hiQu
t0'olHedq -it - B ra hiQu A - B.
YOu ciu: Cho t6ng vd hiQu cia hai s6. riln hi 16 d6_
Tim hai s6 nguydn A vit B (lAl,lB,<
,
Input: TQp vdn bdn AB.INP
. Ddng l: chria t6ng A + B;
. Ddng 2: chuahiQu A B .
-
Output: T€p vin b6n AB.OUT
. Ddng l: ghi A;
. Dong 2: ghi B (A < B).
Vi du:
AB. INP
2.32.8|is6 chung nh6 nh6t
rA^
ff c- G- 5 l, 2, -.., ,.
lnpirt: T6p vdn b6n BSCNN.INP ggn qrdr3ch jr(n < 1000).
output: Tgp vdn bdn BSCNN.OLT eh bfr r6qt
ilit cua 1,2, .., n.
Cho so nguydn n, tim bQi sd chung nho
Vi du:
BSCNN.TN? i 3sfgl-3Gt
J:
2.33. Thd thdng minh
uong vi€c quin li
hB t E
vii h lTk
- cnp rnOt the th6ng
diyriU*firrriaguy€n
duong
Tpp dodn Smart IT quy6t dinh rrng
an ninh o noi ldm viQc. M6i nhnn
minh ri6ng, trong ihe chria mqt
kz, ..., kr\.
t4
{ft1,
Trong nhd di€u hinh c{ra Smart IT c6 n sdn,,
phong dugc d6nh sO ttr t d6n n.6 cria vdo
ctra cdn phong thri , (l < i < n) c6 mQt dAu
dqc th6. Khi cAn md cira phong, nguoi nh6n
vi6n s€ dua th6 vdo dAu dgc th6. N6u. thd
phu hqp vdi phong thi ctra sE ryo.
Trong ddu dqc th6 o phdng thu I c6 luu mQt
ddy s6 nguy6n ductng {xt, xiz, ..., xi^\. Thd
phi hqp v6i phong thri i n6u tich h x k2 x
... x k*h b0i s6 cua tich x;1 x x;2x ... x xim.
y6u cflu: Cho ddy s6 bi mat cria mQt thd th6ng minh vd ddy s6 tiong ddu
dQc th6 citr- n c6n phdng. Hay cho uict tne th6ng minh ndy c6 th6' dnng d€
mo dugc bao nhi6u phong.
Input: TQp vdn b6n SCARD.INP:
. Dong dAu ti€n chira hai s,5 nguy6n duong m vd n (l < m, n < 100).
. Ddng thir hai chfia m s6 nguy€n ducrng kr, kz, ..', k^ ld ddy s6 bi,n4t tten
the. M6i s6 c6 gi6 tri kh6ng qu6 10r5.
. Ddng thri i trong s6 n dong titip theo (l < t < n), m6i dong gOm z s6
nguy€n duong xit, xie,..., xi* h day s6 trong d0u ttqc the tai phong thri t. M6i
s6 c6 gi6 tri kh6ng quf 1015. C6c s6 tren cirng mQt ddng dugc c6ch ohau boi
mOt d6u c6ch.
output: TQp vdn.bin,SCARD.OUT:
. Ddng dAu ti6n chira sti nguy€n C ld
sO
lugng nhirng phong c6'th6 md cua
dugc.
. Dong thri hai chfta C s6 nguy6n ld sO thri tu (theo thri tg tdng dAn) ctra c6c
phong md b4n c6 th6 md cira dugc.c6c s6 tren cing mQt dong dugc c6ch
nhau boi mQt d6u c6ch.
Vidg:
.'
SCARD. INP
SCARD. OUT
34
2
'7 1,0 20Lr
34
-LJD
22'7
"725
1.4 L 20rr
t5
2.34.MAy tfnh sinh h1c (Di thi Otynpic sinh vi€n, ndm 20t
I)
Gi6o su Alex waston dang nghiCn criu mQt loai m6y tinh
mdi c6 t6n goi
"mdy tinh axit amin", dua trOn nguy€n li hopt d6ng cta
cdc chu6i axit amin
trong co th€ s6ng cua circ sinh vai. HiQn tpi Alex waston
dd hi6u du
tfnh ctra K loai axit amin kh6c nhau, cho n€n tdt cir cons6
vd phdp to6n trong
. mhy tfnh axit amin s6 dugc bitlu di6n vd thuc hiQn rrong h6 ." ,A r. xdt s6
nguycn ducrng n trongm6y tinh axit amin, ta dinh nghia:
n! : I x 2 x ... x n.
ciu: cho s6 n vi6to hQ co so lr, tim s6 chfr so 0 cu6i cung cria
mdy tinh axit amin.
YGu
n! trong
Input: Tdp vdn ban BIOCOMp.INp:
. Ddng
'
dAu chira mQt s6 nguydn ducrng /<
Ddng thri hai chria s6 n vi6t
output: r€p v[n bdn
cht
(KS l0).
cr hQ ccr s6 ,<
BlocoMp.our
c6 kh6ng qu6 1000 chir s6.
g6m mQt s5 nguydn (hQ co so
s6 0 cuOi cirng cua n! trong.bi6r, dGn hQ co
sO
4
u
so
rKl
Vi dg:
B]OCOMP. INP
B]OCOMP. OUT
8
1
7
2.35. XAu
nhiphin
gAn diii xring
MOt xdu dugc ggi ld d6i xring n6u dgc x6u d6 tu tr6i qua phrii gi6ng
nhu doc
tu phdi qua tr6i. MQt x6u nhi ph6n duoc goi ld gAn d6i xring neu ,uu
khi sip
x6p lqi chc ki tu cira n6 ta thu duoc mQt *au AOi*ring.
vf dg: c6c x6u nhi ph6n'110.',
'1010', '10000' ld cdc x6u nhi phdn gan d6i
xring vi sau khi sip x6p lai c6c ki tu cta chring, ta thu dugc
c6c xdu tuong
fng'101', '1001,, ,00100'ld c6c xdu d6i xring.
YOu cAu: cho hai s6 nguyen n, t virxdu nhi ph6n gAn d6i
xring s c6 d0 ddi n.
Tim xdu nh! ph6n gAn d0i xring c6 d0 dai n co thu tU tu di6n rhf
I vA tim
,
thri tU tu di6n cta x6u
s.
Input: TQp vdn bin NBS.INp:
. Dong l: chria sO nguydn ducrng n (n < 106);
. Ddng 2: chua s6 nguy€n ducrng I (l < l0'00);
. Ddng 3: chria xdu s
.
I6
iQl
Output: TQp v[n bdn NBS.OUT:
rin
. Ddng l: xdu nhi phdn gAn eOi xring d9 ddi n thir t;
. Ddng 2: s6 thri ty cua xdu nhi phOn gAn dOi xring s mod I11539786.
pc
ng
SO
Vi dr;:
NBS. INP
NBS . OUT
2
t1
2
1
00
(D€ thi hqc'sinh gi6i Qudc gia, ndm 201l):
MOt trang tr4i l6n c6 n cdy c6nh voi dQ cao kh6c nhau tirng d6i. C6c cdy ndy
!A
ougc xep rneo mQt hAng dgc. Ong chtr trangtr4ili ngucri c6 dAu 6c thAm mi
n6n b6 tri hdng c0y c6 tinh chAt kh6ng don diQu nhu sau: "Di til dAu hdng
dtin cuOi hdng kh6ng c6 3 cdy ndo (kh6ng nnat thi0t phii li6n ti6p) c6 chiOu
?36. Hnng
cAry
cao gi6m ddn".
MQt h6m, 6ng chri mua th6m mQt cdy cinh m6i co chi€u cao l6n hon chiiiu
cao cira tfut cir cilc c|ty dd c6. Ong ta mu6n x6p cdy cinh m6i vdo m6t trong
n +l vitri c6 th6 cira hdng cdy (vdo vl tri dAu hing, vi tri sau ciy thf nhAt
cria hdng, vi tri sau cdy thri hai cria hdng, ..., vi tri sau cdy thri n oia hdng) sao
cho ducv. c hdng cdy vdn tho'6 mdn ydu cAu vC tffi kh6ng tlon digu n6u tr€n.
YOu cAu:
. Hdy cho bi6t c6 bao nhi€u c6ch x6p cdy canh cao nh6t m6i mua vio hdng
.cdy sao cho v5n drim bao di6u kien viitinh kh6ng dcrn diQu.
. Gia su mdi ngdy 6ng chri mu6n x6p n+l c6y dd c6 thinh hdng cdy dim bao
I
).,
^ cdu
y€u
v€ tinh kh6ng dcrn diQu vd hai hdng cay cria hai ngdy kh6c nhau ld
kh6ng trung nhau. HAy giirp 6ng chir tinh xem viEc d6 c6 th6 di6n ra nhi6u nhAt
ld bao nhi6u ngdy.
Input: TQp vdn bdn TREELINE INP:
. Ddng thu nh6t chria hai s6 nguy6n duong n vit htucrng tmg ln s6 lugng cdy
vd chiOu cao ctra cdy cao nhat. giast rdng
r.
10s, h
<
106.
. Ddng thri hai
chfta n sO nguy6n duong 1m6i sO ddu nho hon ft) tucrng ung
ld ddy chi6u cao cta r c6y dugc x€p ban d6u.
I
')'
C6c s6 tr€n ctrng m6t dong itugc ghi c6ch nhau it nh6t mQt d6u c6ch.
Output: TQp vdn bin TREELINE.OUT:
2. TLCTHBTQl -A
t7
I
t
. Ddng thri nh6t ghi mQt s6 nguydn ln s6 cich xqp
cry o nlrir vdo hdng.
' Ddng thri hai ghi mQt s6 nguy€n ld phin e qg ptcp chia s6 ngdy l6n
nh6t tim duoc cho l0e.
I
i
;3.
Vi du:
CHUYEN EE 3. SAPruF
3.:
3.1. cho m6t danh s6ch n hoc sinh
. Ho vd t6n: x6u ki tu
. Di6m: s6 thuc.
(l < n < 2mL nii lc ta
dQ ddi kh6ng qu6 30
a) Dua ra danh s6ch ho
vi
tOn tld
sip xep
((*|i($frr
rb
15
co tb6ng tin sau:
mQt d6u c6ch);
l^ft (fti ru m ti6n t€n,
hg, dQm).
ci.l, rF
Ec* len d6.
c) chqn nhirng hgc sinh c6 thri hang I, e 3 fiL o tir rrong danh s6ch
d6 trao hoc b6ng, hdy cho bitlt t6n nheng hgc flai.
b) c6 bao nhiOu t€n kh6c nhau trong danh
3.!
Vi du:
6
Vu Anh Quan
8.9
Nguyen Van Chung
B.'7
Hoang Trong Quynh
'J: Anh Quan
Nguyen Van Chung
Cong Hoang
Dlnh Quang Hoang
Dinh Quang Huy
Vu Anh Quan
Hoang Trong Quynh
Dinh Quang
E€,q
]::l-
Euy
llgr:pn Van
-..
Huy
Quang Hoang
Chung
::.:a!.
3.6
8.5
Dinh Quang Hoang
8.1
Dinh Quang Huy
8.8
Cong Hoang
.8.0
t8
3.7
2. TLCTHBTQl.B
3.2. Cho ddy sO gdm N s5 nguy0n ar < a) < ...< aN
a) Eua ra thu4t ro6n c6 dQ phirc
md ai* aj:0.
b) Dua ra thuflt to6n c6
ctQ
.
qp o(Mog/f) d6 tim hai chi s5 i,7 md i < j
phric tap O(MloglD d6 tim ba chi s6 i, i, k mit
i
c) Dua ra thuflt to6n c6 dQ phirc tap O(N) dC tim hai chi s6 i,7 md i <7 vd
ai -f aj:0.
d) Du4 ra thu6t to6n c6 dQ phuc tap O(ll) dC tim ba chi s6 i,i, k mit i
vd a;
33.
* ai * a*:0.
Cho mot xdu s (dQ ddi kh6ng qu6 200) chi g6m clckitq'a' d6n'z', d6m
lucr,ng xdu con li6n ti6p kh6c nhau nhQn dugc tir xiu s.
sO
Vi du, .r = 'abab', ta co chcxdu con li6n ti6p kh6c nhau lir:
''a'
r'b' r'ab' r.'ba' r'aba' r'bab' r'abab',
sO tuqilg xdu con li0n ti6p kh6c nhau ld 7.
3.4. Vii5t ten ti6p c6c sti tu nhi€n tu I d6n N ta dugc mot s6 nguyen M. Yi dv
N: 15 ta co M:123456789101I 12131415. FI6y tim c6ch xo6 di K cho s6
ctra s6 u d6 nhAndugc s,5 M' le l6n nh6t.
3.5. X6t tap F(D tat cit cfrc so triru ti trong doan [0,1] v6i mau s6 kh6ng vugt
qu6N(l
vi ds, t0'p r(5):
01112132341
15435253451
Sap xep c6c phdn s6 trong tap F(N) theo thri tp tdng ddn, dua ra phdn
sO
thu k.
3.6.
Cho x0u s (d0 ddi kh6ng vuqt qu6 t06; chi g6m c6c ki
tu'a' d€n'z',
a) C6 bao nhi€u lo4i ki tg xu6t dign trong s?
b) Dua ia mQt ki tq xu6t hiQn nhi€u nhAt trong xdu s vd sO tAn xu6t hi€n cia
ki ts d6.
3.7.
Cho hai ddy
a,.or1...3o,ve 4 < br3...3b*,hdyduarathuptto6nc6 d0
phric'tAp O(n + @
d,6
c6 ddY c,3 c,
19
3.8.
Cho ddy sd g6m n (n < 10000) s6 ngu1,6n o..o_......r. ( a,l
nguydn x bhtki d6s:lar-x+loz-x *...- a----l dat gi6tri nho nhat.
C6 bao nhi6u gi|tri nguy€n khric nhau thod min.
Vi dU 1, ddy g6m 5 sO 3, I ,5,4,5, ta co dul.nhit mor gi6 ti X:+ dtisCat
gi6 tri nho nh6t bing 6.
Vi
dU
Ce S
3.9.
2,
ddy gdm
6 sO 3,
I
,7,2,5,7
tac6 ba gii tri n21-€n cuaX Id,3,4,5
dat giri tri nho nh6t bang 13.
cho N (N < 10000) ditlm tr€n mdt phing o.n'. diim rhu i co toa dQ lit (x;, y;).
Ta dinh nghia kho6ng c6ch giira hai di€m p.r,. _r..,r ta e(xg, yq) bing
lr, - xol + lyo - yol. Hay tim di€m A co toa do ngul in ma tong khoang c6ch
(theo c6ch dinh nghia tr€n) tu A tsi J'di€m da cbo lir nho nh6t
Qx,l, ty,l
nguy€n kh6ng vuot qu6 l0e).
(l/ < 10000) doan thing trdn truc ,o rcri r-dc di€m ddu x; vd d0 ddi
d,(V), di ld nhirng sO nguy€n vd kh6n_e'rm qui lU'r. Tinh t6ng dQ ddi
3.10. cho N
tr6n truc sO Ui ptrtr boi N doan tr€n.
: l0 rz:
d: :6:-r: : -100. d: :
Vi du, c6 ba doan
xt:5,
dg dditr€n truc
Ulptru boi ba doan tr€n la ll.
sO
d1
0.
10
thit6ne
3.11. cho N (N < 300) diem rr€n mdt phing o-n'. ,Ji€m rhu r co roa d6 ld (xi, yi).
Hdy d6m so cdch chon bdn di€m trong -\-di€m rrin ma bon di6m ao ia uon
dinh ctra m6t hinh chfr nh6t (x,1, ly,l ngul€n khong rrrr.rr qud 1000).
Vi du, c6 5 di€m (0,.0), (0, l), (1, 0), (-1. 0). t0.
-l
r co du1.nh6t m6t crich
chgn 4 di€m md 4 di6m d6 ld 4 dinh cua rnor hinh ch& nhit_
3.12. cho N (N < 10000) do4n s6 nguy€n (a,, b,l. rrdl' trm rmt so md sti d6 thuOc
nhiAu do4n s6 nguydn nhdt.
V1 dU, c6 5 dopn [0,10], 12,31,14,7), [3.5].[_r.8]. ta chon s0 5 thu6c 4 doan
[0,10], [4,7], [3,5],
15,81.
3.13. Cho ddy gdm N (N < 10000) s6 a,, e:,....a, . Hd1 rim di1'con liOn ti6p ddi
nhAt c6 t6ng
bing o ( 1", | < l0n ).
Vi du, ddy gdm 5 sO 2, l, -2,3, -2 thi ddr-con
bing 0 ld: l, -2, 3, -2.
20
hen ri€p
dii
nhAt c6 t6ng
3
3.14.
ESEQ
Cho day s6 nguyOn
tho6mdn:
A
.
g6mNphAn
tt Ar, A2, ...,1n. Tim s6 cflp chi sd i,7
i
z4=i+v6i1<
p=t
s--j
.
tnput: TQp vdn bdn ESEQ.INP c6 d4ng:
. Ddng dAu h s6 nguydn duong N (2
i
S I0\.
=N
uong trep theo chiraNs5 nguy€n At, Az, '.., Au (lAil<17\i, c6c s6
.t
c6ch
nhau m6t d6u c6ch.
output: TQp vin bdn ESEQ.OUT g6m mQt s6 ld sd cap tim dugc.
Vi dg:
ill
ii
g
).
3.15. GHEP SO
Cho n s6 nguy6n duong ar, a2, ;.., an (l < n < 100), m6i sO kh6ng wgt qu6
10e. Tri c6c si5 nhy nguoi ta t4o ra mQt s6 nguy€n mdi bing c6ch gh6p tdt cit
Vi dg, vti n = 4
n
c6c s6 dd cho, tirc ld vi6t h€n ti6p c6c si5 da cho vdi nhau.
h
vd c6c sti 123, 124,56,90 ta c6 th$ tao ra circ s6 m6i sau: 1231245690,
1241235690, 5612312490, 9012312456, 9056124123,... C6 thti d6 Oang
thAy ring, vbi n : 4, ta c6 th6 tao ra 24 s6 mdi. Trong trucrng hqp ndy, s6
'!
a
n
lon nhAt co th6 t4o ra ld 9056124123.
You
ciq:
Cho n vd c6c s6 a7, ct2, ...,
ra khi ghdp c6c
sO
a,.Hdy x6c dinh s6 l6n nh6t c6 th6 tao
da cho thinh mQt s6 m6i.
Input: TQp vdn b6n NUMJOIN.INP:
ri
t
. Dong thri nh6t chua s6 nguy6n r;
. Ddng thf hai chta n s6 nguy€n at az . . . Qn .
output: TQp v6n bin NUMJOIN.OUT g6m mot dong ld s6 lon nh6t c6 thc
tpo ra khi gh6p c6c s6 dd cho thdnh mQt s6 m6i.
2l
3.I6. GIA TRI NHO NHAT
cho bing s6,a g6m MxN 6, m6i 6 chh* j-ry€n klrdng am1,.lr) co
gi6 tri kh6ng vuot qud t0e. xdt hang r ri rijci-ri.,
*a" iini x,,
"ii'
nguy6n d6:
(N
'Sij
Tinh W
\
=l Yt 4' -.yI/rl'l
\;i
M_I
\
\- _1.-x,-lf:;"rnonhjt.
/r
'-)
\ii
M
=IIsu.
i=l j=i+l
lnput: T€p v6n bin WMT.INp:
. Dong dAu h hai s6 nguy€n duong
. M ddngsau, m6i dong N s6.
t{ .l-(l <|(Jf,< lml).
Output: TQp vdn bdn WMT.OUT gim
Vidu:
rir j Z
.
,
23
231
234
\\RrTtrrc@tur
c6ng viQc girii md chfi vitit cria ngrroi rlrF rrEh
hon nguoi ta tuong
nhiOu. Tr6i qua hon 200 ndm md
n €rr*i
i .* ca.lnt vi6t navl
Chi trong ba thap ni€n gAn ddy do"g,-i
cory +lf tllr=- 69. gidi m6 nay mOi
3.17. DECTPHERING THE MAYAN
c6 nhi€u ti6n b0.
chfr vi€t Maya dua trdn c6c ki hi€u nb gi E €t
n6i net v6 tucrng irng
v6i mQt dm giong n6i. M6i tir trong ch, vE lh c ho g6m mQt tap rrqp
cdc n6! vE nhu vdy k€t hqp lai voi nhiir tiirt
tE nhau. uai"qi .,lc .o
ttr6 hiCu ld mQt ki ts .
M6t trong nhirng v6n d€ ion ttri giii mr cr rqtr E ti r.u dpc c6c n6t v6.
Do ngucri Maya trinh bdy cdc ndt vd ri;- kri= rb rli qu ph6t dm, md theo
c6ch th6 hiQn cria chir.nq. Do v4y nhcukr c-tii ri c* net v6 crra m6t
tu
r6i nhung v6n kh6ng th6 tim .u iow chirr *citil
ri dgc cria tir ndy.
c6c nhi kh6o cd dang di tim ki6m mor n dF rF r llo da bi6t ro t6t ca
c6c ndt vE cria tu ndy nhung vin ch'a ticr cft cil rii ra iua tir niv.
vl ho
22
.
biet c6 c6c thi sinh 10I'06 sE dtin n€n mu6n su tro Sirip cua c6c thi sinh niry.
Hg sE dua ra todn b0 g n6t v€ cria tir W vit ddy ,S tat ca c6c net vE c6 trong
hang d6 c6. B4n hay girip c6c nhi khio c6 tinh xem c6 bao nhi€u kh6 ndng
Wtronghang d6.
*u6t hiQn
W vit ddy S c6c
YOu cflu: Hly vi€t chuong trinh, cho tru6c c6c ki tu cira
n6t v6 trong hang d6, tinh t6ng s6 kh6 n6ng xuat hiQn cua tri w trong day s,
nghia li s6 hn xu6t hiQn mdt hodn vi c6c ki ty c0a ddy S ki ty trong S.
c6
X,,
ti
ti
Cac rdng bu6c
. | 1g
< 3 000, s6 n6t vE trong W'
S lsl S 3 000 000, lsl ld s6 cfc n6t vE cira ddy S'
Input: TQp c6 dang
. Ddng thri nhAt: chria hai s6 g vd lSl c6ch nhau boi ddu c6ch.
'g
. Ddng thir hai: chria g ki tu licn nhau ld c6c ndt v€ ctra ti w. c6c ki tu hqp
lQ ld a'-'z' vd' A' -' Z . C6c chf in hoa vir in thulng ld kh6c nhau.
. Ddng thir ba: chria lsl ki tu ld ddy c6c n6t vE tim thay trong hang. c6c ki tu
hcr-p lp ld a'-'z' vd' A' r Z . C6c chir in hoa vd in thudng li kh6c nhau.
output: TQp chira dirng mQt so ta qa n6ng xu6t hiQn ctra ti w trong d6y s.
'
'
Vi dg:
4IT
2
cAda
AbrAcadAbRa
3.18. TRO CHoI
'
c.
)o
lfr
VoI DAY
SO (Da
thi
hpc sinh gi6i qu6c gia, 2007-2008)
Hai b?n hgc sinh trong lirc nhdn r6i nghi ra trd choi sbu day. M6i ban chqn
tru6c mQt ddy s6 g6rnn st5 nguy6n. Gi6 sri ddy s6 md b4n thri nhAt chqn ld:
bt,b2,...,b;, con ddy s6 md bpn thri hai chon ld: c,,cr,...,c,'
luqt choi, m6i b4n dua ra mQt s6 h4ng trong d6y s6 ctra minh. Ntiu b4n
thri nhdt dua ra sO hpng bt(l < i < n), cdn ban thir hai dua ra s6 h4ng
N,l6i
c,(13
j (r)
thigi6cualugtchoid6s€ld 1b,+c,1.
Vi dg, gii su day s6 b4n thf nh6t chgn ld l, -2; con ddy s6 md b4n thu hai
chon ld 2, 3. Khi d6 c6c khi ndng c6 th6 cira mQt lugt choi la (1, 2), (1, 3),
(-2, /), (-2,3). Nhu vfy, giii nh6 nh6t cua
-6t hrgt'"hoi trong s6 c6c lugt
choi c6 ttr6 n 0 tucrng img v6i gid cta luqt cM(_2,2).
YGu cau:,Hdy x6c dinh gi6 nh6 nh6t cria mO.t
hrqt choi trong s6 c6c rugt
choi c6 th6.
lnput: TQp c6 d4ng
. Ddng
dAu tidn chria sti nguydn duong n
(z < 105)
' Dgng thu hai chira ddy sti nguyOn br, bz, .--,'b.(Jhl < tge, i : t,2, ..., n).
' Dong thri ba chira ddy sd nguy€n c t, c2, ..., c, (kls ld, i : l, 2, ..., n),
Hai s6 hdn ti6p tr6n mQt dong dugc ghi c6ch ntrnu
b&i d6u c6ch.
Output: Tgp ghi ra gi|nho nh6t tim
dugc.
.
Vi dB:
.)
r-z
23
3.19. DAY SO @A thi hpc sinh gi6i
Cho ddy s6 nguyOn
Hd
N1li, 2005_2(X)g)
. 36 ao(l < p < z) duw goi ld mQt s6 trung
binh cQng trong ddy n6u t6n t4i ba chi rO ,,,1, k(i,j,k
mQt khiic nhau,
ctt +a,+a,.
,
Sao CnO ao
YOu
ciu.'
=#.
a1, ct2,...,ctn
3.2
J
Cho n vd ddy
s6 a,,.or,...,a,.Hdythn s6 hrqng c6c
cQng trong d6y.
Input: TQp c6 dang
. Ddng itAu ghi sri nguyOn
ducrng n
. Ddng thri hai chfa n s6.nguy€
e < n< l0m).
n a; (a;. l0t).
outpqt: TQp ghi s6 luqng cdc s6 trung binh cQng trong
d6y.
Vf dg:
5
43535
,Bi
)
si5
trung binh
rrgt
3.20.
"rCIt
DEM SO TAM GIAC (DA thi Tin hpc trd, bang B, ndm 2009)
Cho ba s6 nguyOn ducrng a, b, m vir r do4n thing ddnh s6 tu 1 tdi n
(m,n110000). Do4nthing thu i c6 dO dai di 0
(d1,d2,...,d,) dugc cho nhu sau:
lb
d,=1
'
l(oxd,_,
nOu
+b)modm+l
l=
ndul
I
(*)
HEy cho bi0t c6 bao nhi6u tam giitc kh6c nhau c6 th6 dugc t4o ra bing c6ch
ldy dung ba doqn trong s5 n doqn tbing dd cho ldm ba c1nh (hai,tam giSc
bing nhau n6u chirng co ba cflp c4nh tucrng ring bdng nhau, n6u kh6ng
chring dugc coi ld kh6c nhau).
a:6; b:3: m:4; n:5.
Ta c6 5 dopn thdng v6i d0 ddi cua
chring tinh theo c6ng thuc (*) ld (3,2. 4,4,4). Vsi 5 doan thing ndy c6 th6
tao ra dugc 4 tam gi6c voi d0 dii c6c c4nh dugc chi ra nhu sau:
Vi dg voi
Tam gi6c
l: (2,3, 4)
(2,4,4)
Tam gi6c 3: (3,4.4)
Tam gi6c 4: (4,4,4).
Tam gi6c 2:
o
Jo
Bii tqp b6 sung
3.21. Bdn vanxo Fibonacci (Di thi hoc sinh gi6i Quiic gia, ndm 2012)
BAn vanxo Fibonacci ld mQt b6n nh4c md giai diqu cua no
bit ngudn tu
mQt
trong nhirn g ddy sO nOi ti6ng nhdt trong li thuy6t sO - aay s6 Fibonacci. Hai
sO eau ti6n cira ddy ld sO I ud s6 2, ct c s6 titlp theo dugc x6c dinh bing t6ng
cua hai sO lien titip ngay tru6c n6 trong
diy.
Bin vanxo Fibonacci thu dugc bing viQc chuy6n day sd Fibonacci
,
A,
thdnh
ddy c6c n6t nh4c theo quy tdc chuy6n mQt s6 nguy6n duong thinh n6t nh4c
sau ddy: