Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
c tuye^n PTIT
main problemset
Editors:
Thch code nhu+ng dt
Preface
This electronic material contains a set of algorithmic problems, forming the archives of the Thi lp trinh tru+.c tuye^n PTIT (http://www.spoj.com/ACMPTIT/), main problemset. The document can be accessed at the following URLs: in PostScript format: http://www.spoj.com/ACMPTIT/problems/main.ps in Portable Document Format: http://www.spoj.com/ACMPTIT/problems/main.pdf These resources are constantly updated to synchronise with the ever-changing hypertext version of the problems, and to include newly added problems. If you have obtained this document from another source, it is strongly recommended that you should download the current version from one of the aforementioned URLs.
Disclaimer from the Editors. Despite our best efforts, it is possible that this document contains errors or that some of the content differs slightly from its original hypertext form. We take no responsibility for any such faults and their consequences. We neither authorise nor approve use of this material for any purpose other than facilitating problem solving at the Sphere Online Judge site; nor do we guarantee its fitness for any purpose whatsoever. The layout of the problems in this document is the copyright of the Editors named on the cover (as determined by the appropriate footers in the problem description). The content is the copyright of the respective Editor unless the copyright holder is otherwise stated in the resource section. The document as a whole is not protected by copyright, and fragments of it are to be regarded independently. No responsibility is taken by the Editors if use or redistribution of this document violates either their or third party copyright laws. When referring to or citing the whole or a fragment of this document, please state clearly the aforementioned URLs at which the document is to be found, as well as the resources from which the problems you are referring to originally came. Remarks concerning this document should be sent to the following e-mail address: contact@spoj.com.
Table of Contents
1. 2. 3. 4. 5. 6. 7. 8. 9. Problem REPSTR (13217. Replacing Digits) Problem FINDCOW (13239. Find the Cow!) Problem STRBALAN (13240. Chui cn bng) Problem GOODFRIE (13265. Good friends) Problem REMOVBIT (13266. Xa bit) Problem SUMSQR1 (13313. Tng binh phu+o+ng) Problem PRISUSTR (13379. Prime Substring) Problem YOUNGCLA (13380. Birthdates) Problem NUMPOLY (13400. Giao ie^?m trong a gic)
(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();
Input
Dong u chu+a s nguyen du+o+ng a c dai N (khng bt u bng chu+~ s 0). Dong 2 chu+a day s c dai M (1<=N,M<=10 5 )
Output
S a lo+n nht c the^? thay the^ u+o+.c.
Example
Input: 1024 010 Output: 1124 Input: 987 1234567 Output: 987
Added by: Thch code nhu+ng dt Date: 2013-01-10 Time limit: 1s Source limit:50000B Cluster: Cube (Intel Pentium G860 3GHz) Languages: C++ 4.3.2 C++ 4.0.0-8 JAVA
(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();
Input
Dong 1: Mt chui ngoc o+n c dai la N (1 <= N <= 50,000).
Output
Dong 1: S vi. tr ma Bessie c the^? u+ng - C nghia la s cp (x,y) khc nhau vo+i x < y sao cho (( u+o+.c tim thy o+? x va )) u+o+.c tim thy o+? y.
Example
Input: )((()())()) Output: 4
C 4 vi. tr c the^? cu?a Bessie u+o+.c the^? hie^.n o+? du+o+i1. )((()())())^^ ^^2. )((()())()^^^^3. )((()())()^^ ^^4. )((()()) ())^^^^
C 4 vi. tr c the^? cu?a Bessie u+o+.c the^? hie^.n o+? du+o+i 1. )((()())()) ^^^^ 2. )((()())()) ^^^^ 3. )((()())()) ^^^^ 4. )((()())()) ^^^ ^
Added by: Thch code nhu+ng dt Date: 2013-01-11 Time limit: 1s Source limit:50000B Cluster: Cube (Intel Pentium G860 3GHz) Languages: C++ 4.3.2 C++ 4.0.0-8 JAVA
(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();
Bessie vu+a mo+i mua mt my tnh xch tay mo+i, nhu+ng c ta la.i khng go ban phm u+o+.c cho tt lm vi mng chn lo+n cu?a c ta so vo+i kch thu+o+c nho? cu?a ban phm. Bessie vu+a nhp vao ban phm mt day k tu+. u+a thch cu?a c ta - mt chui ngoc cn bng. Tuy nhien, c ta nhn ra rng c ta c le~ a go nhm mt k tu+. mt cch v tinh, tu+ du mo+? ngoc o+n thanh du ng ngoc o+n, hoc ngu+o+.c la.i. Hay gip Bessie e^m s vi. tr trong chui e^? ne^u ta i ngu+o+.c du o+? vi. tr thi chui ban u se~ thanh chui cn bng. C nhie^u cch e^? i.nh nghia mt chui ngoc la "cn bng." Cch de^~ nht la s lu+o+.ng du mo+? ngoc ( bng s lu+o+.ng du ng ngoc ), va vo+i bt ki chui tie^n t nao, s lu+o+.ng du mo+? ngoc o+n ( pha?i lo+n ho+n hoc bng s lu+o+.ng du ng ngoc o+n ). Trong nhu+~ng v du. sau y, nhu+~ng chui o+? ben du+o+i la chui cn bng: () (())
Input
Dong 1: Mt chui ngoc o+n c dai la N (1 <= N <= 100,000).
Output
Dong 1: S vi. tr trong chui ban u ma ne^u ta i ngu+o+.c du o+? vi. tr thi chui se~ thanh chui cn bng.
Example
Input: ()(()))) Output: 4
Ne^u ta nhin cu. the^? vao chui ban u: 12345678 ()(()))) Ne^u ta i ngu+o+.c du cu?a k tu+. thu+ 2 thi chui se~ thanh chui cn bng: 12345678 (((()))) Tu+o+ng tu+. ne^u ta i o+? vi. tr thu+ 5,6, va 7, ta e^u c ke^t qua? la chui cn bng.
Added by: Thch code nhu+ng dt Date: 2013-01-11 Time limit: 1s Source limit:50000B Cluster: Cube (Intel Pentium G860 3GHz) Languages: C++ 4.3.2 C++ 4.0.0-8 JAVA
(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();
Input
Dong u chu+ N (3<=N<=300 000) va K (1<= K <=N). N dong tie^p theo, mi dong chu+a ten mt ho.c sinh theo danh sch xe^p ha.ng (tu+ 2 e^n 20 chu+~ ci tie^ng Anh in hoa).
Output
S cp ba.n tt.
Example
Input: 4 2IVAIVOATOM4 2 IVA IVO ANA TOM Output: 5 Input: 6 3 CYNTHIA LLOYD STEVIE KEVIN MALCOLM DABNEY Output: 2
Added by: Thch code nhu+ng dt Date: 2013-01-12 Time limit: 1s Source limit:50000B Cluster: Cube (Intel Pentium G860 3GHz) Languages: C++ 4.3.2 C++ 4.0.0-8 JAVA
(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();
13266. Xa bit
Problem code: REMOVBIT
Cho s a vie^t o+? he^. co+ s 2. Nhie^.m vu. cu?a ba.n la pha?i xa mt chu+~ s e^? s con la.i xa khi xa la lo+n nht !!!
Input
Mt dong chu+a s a vie^t o+? he^. nhi. phn.
Output
S lo+n nht sau khi xa 1 chu+~ s tu+ a.
Example
Input: 101 Output: 11
Added by: Thch code nhu+ng dt Date: 2013-01-12 Time limit: 1s Source limit:50000B Cluster: Cube (Intel Pentium G860 3GHz) Languages: C++ 4.3.2 C++ 4.0.0-8 JAVA
(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();
Input
Gm mt s N duy nht (1<=N<=10 9 )
Output
Tng binh phu+o+ng cc s trong day a.
Example
Input: 2 Output: 5
Added by: Thch code nhu+ng dt Date: 2013-01-14 Time limit: 1s Source limit:50000B Cluster: Cube (Intel Pentium G860 3GHz) Languages: C++ 4.3.2 C++ 4.0.0-8 JAVA
(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();
Input
Mi dong chu+a 1 xu (ti a 255 s). Ke^t thc bo+?i dong chu+a s 0 (khng cn xu+? l)
Output
Vo+i mi xu, in ra tren 1 dong ke^t qua?
Example
Input: 112491321150441226406011245 91321150448 1226406 0 Output: 11 1321 2
Added by: Thch code nhu+ng dt Date: 2013-01-17 Time limit: 1s Source limit:50000B Cluster: Cube (Intel Pentium G860 3GHz) Languages: C++ 4.3.2 C++ 4.0.0-8 JAVA
(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();
13380. Birthdates
Problem code: YOUNGCLA
Vie^t chu+o+ng trinh tim ngu+o+i tre? nht va gia nht trong lo+p.
Input
Dong 1 chu+a s n (1<=n<=100), s ngu+o+i trong lo+p. N dong sau, mi dong la thng tin 1 ngu+o+i c da.ng: personName dd mm yyyy Trong : personName la ten khng qu 15 chu+~ ci, dd,mm,yyyy ln lu+o+.t la ngay, thng, va nm sinh.
Output
Dong 1: ten ngu+o+i tre? nht Dong 2: ten ngu+o+i gia nht
Example
Input: Garfield Mickey 1 Alice 30 Tom 15 8 Jerry 18 Garfield Output: Tom Jerry 20 9 19905 10 1991 12 1990 1993 9 1990 20 9 1990
Added by: Thch code nhu+ng dt Date: 2013-01-17 Time limit: 1s Source limit:50000B Cluster: Cube (Intel Pentium G860 3GHz) Languages: C++ 4.3.2 C++ 4.0.0-8 JAVA
(function() { var po = document.createElement(script); po.type = text/javascript; po.async = true; po.src = https://apis.google.com/js/plusone.js; var s = document.getElementsByTagName(script)[0]; s.parentNode.insertBefore(po, s); })();
Input
Chu+a 1 s nguyen N (3 <= N <=100) duy nht la s i?nh cu?a a gic.
Output
S giao ie^?m ta.o bo+?i cc u+o+ng cho nm trong a gic.
Example
Input13outputInput24outputInput36output15
Added by: Thch code nhu+ng dt Date: 2013-01-18 Time limit: 1s Source limit:50000B Cluster: Cube (Intel Pentium G860 3GHz) Languages: C++ 4.3.2 C++ 4.0.0-8 JAVA