├── .gitattributes ├── .gitignore ├── Algoritmhs └── .gitkeep ├── IOI ├── [1994]triangolo │ ├── Il triangolo (triangolo).pdf │ └── triangolo.cpp ├── [2006]writing │ ├── Deciphering the Mayan writing (writing).pdf │ ├── writing.cpp │ ├── writing2.cpp │ ├── writing3.cpp │ ├── writing4.cpp │ ├── writing5.cpp │ └── writing6.cpp ├── [2007]pairs~ │ ├── Pairs (pairs).pdf │ └── pairs.cpp ├── [2008]teleporters~~ │ ├── Teleporters (teleporters).pdf │ └── teleporters.cpp ├── [2009]garage │ ├── Garage (garage).pdf │ └── garage2.cpp ├── [2009]poi │ ├── POI (poi).pdf │ └── poi.cpp ├── [2009]raisins~~ │ ├── Raisins (raisins).pdf │ └── raisins.cpp ├── [2010]ricehub~~ │ ├── Ricehub (rice).pdf │ └── ricehub.cpp ├── [2012]pizza │ ├── Olympic pizza (pizza).pdf │ ├── pizza.cpp │ ├── pizza2.cpp │ ├── pizza3.cpp │ └── pizza4.cpp ├── [2012]queue │ ├── Italian queue (queue).pdf │ ├── [IOI 12]queue.rar │ ├── queue.cpp │ └── queue2.cpp ├── shelton.c └── shelton.cpp ├── OII ├── [2002][nat]borse │ ├── Borse di studio (borse).pdf │ └── borse.cpp ├── [2003][nat]alberi │ ├── Alberi (alberi).pdf │ ├── alberi.cpp │ ├── alberi2.cpp │ ├── alberi3.cpp │ └── alberi4.cpp ├── [2003][reg]giostre │ ├── Giostre (giostre).pdf │ └── giostre.cpp ├── [2004][nat]collage │ ├── Arcobaleno e Collage (collage).htm │ ├── collage.cpp │ └── collage_2.cpp ├── [2004][reg]poldo │ ├── La dieta di Poldo (poldo).pdf │ └── poldo.cpp ├── [2005][nat]camelot │ ├── La tavola rotonda di Camelot (camelot).htm │ └── camelot.cpp ├── [2005][reg]chimico │ ├── Il nobile chimico (chimico).htm │ └── chimico.cpp ├── [2005][reg]codice │ ├── Codice segreto (codice).htm │ └── codice.cpp ├── [2005][reg]korrot │ ├── La poltrona di Korrot (korrot).pdf │ └── korrot.cpp ├── [2005][reg]sunny │ ├── Sunnydale (sunny).pdf │ └── sunny.cpp ├── [2006][reg]bilancino │ ├── Le pesate di Bilancino (bilancino).htm │ └── bilancino.cpp ├── [2006][reg]brambillia │ ├── Ritrovo a Brambillia (brambillia).htm │ └── brambillia.cpp ├── [2006][reg]serie │ ├── Teste di serie (serie).htm │ └── serie.cpp ├── [2007][reg]lino │ ├── Lino il giornalaio (lino).htm │ └── lino.cpp ├── [2007][reg]nimbus │ ├── Giri sulla Scopa Nimbus3000 (nimbus).htm │ └── nimbus.cpp ├── [2007][reg]torero │ ├── Torero Escamillo (torero).htm │ └── torero.cpp ├── [2008][nat]triade~ │ ├── Giornalismo d’inchiesta (triade).pdf │ ├── triade.cpp │ └── triade2.cpp ├── [2008][reg]mappa │ ├── Mappa antica (mappa).pdf │ └── mappa.cpp ├── [2008][reg]missioni │ ├── Missioni segrete (missioni).pdf │ └── missioni.cpp ├── [2008][reg]pizzini │ ├── Codici e pizzini (pizzini).pdf │ ├── pizzini.cpp │ └── pizzini2.cpp ├── [2009][reg]depura │ ├── Depurazione dell’acqua (depura).pdf │ └── depura.cpp ├── [2009][reg]essenza │ ├── Essenza per profumi (essenza).pdf │ └── essenza.cpp ├── [2009][reg]treno │ ├── Treno di container (treno).pdf │ └── treno.cpp ├── [2010][nat]amici │ ├── Tè con gli amici (amici).pdf │ ├── amici.cpp │ └── amici2.cpp ├── [2010][nat]numeri~ │ ├── Numeri antipatici (numeri).pdf │ └── numeri.cpp ├── [2010][nat]pesca~ │ ├── Pesca bizzarra (pesca).pdf │ ├── pesca.cpp │ ├── pesca2.cpp │ └── pesca3.cpp ├── [2010][reg]quasipal │ ├── Quasi-palindromi (quasipal).htm │ ├── Quasi-palindromi (quasipal).pdf │ └── quasipal.cpp ├── [2010][reg]sbarramento │ ├── Sbarramento tattico (sbarramento).pdf │ └── sbarramento.cpp ├── [2010][reg]tamburello │ ├── Sequenza per tamburello (tamburello).pdf │ ├── tamburello.cpp │ └── tamburello2.cpp ├── [2011][nat]bath │ ├── Per un pugno di baht (baht).pdf │ └── bath.cpp ├── [2011][nat]fuga │ ├── Fuga dagli inseguitori (fuga).pdf │ ├── fuga.cpp │ └── fuga2.cpp ├── [2011][nat]salti │ ├── Salti spettacolari (salti).pdf │ └── salti.cpp ├── [2011][nat]scuola │ ├── Scuola di supereroi (scuola).pdf │ └── scuola.cpp ├── [2011][reg]domino │ ├── Domino massimale (dominio).pdf │ └── domino.cpp ├── [2011][reg]galattici │ ├── Eserciti Galattici (galattici).pdf │ ├── galattici.cpp │ └── galattici2.cpp ├── [2011][reg]nanga │ ├── Nanga Parbat (nanga).pdf │ ├── nanga.cpp │ └── nanga2.cpp ├── [2012][nat]eso~ │ ├── Espressioni senza operatori (eso).pdf │ └── eso.cpp ├── [2012][nat]fermata │ ├── Entscheidungsproblem, o problema della fermata (fermata).pdf │ ├── fermata.cpp │ └── fermata2.cpp ├── [2012][nat]fibstr │ ├── Stringhe di Fibonacci (fibstr).pdf │ └── fibstr.cpp ├── [2012][nat]fontane~ │ ├── Allenamento per la maratona (fontane).pdf │ ├── fontane.cpp │ └── fontane2.cpp ├── [2012][nat]matita │ ├── Disegna senza sollevare la matita (matita).pdf │ ├── matita.cpp │ ├── matita2.cpp │ ├── matita3.cpp │ └── matita4.cpp ├── [2012][nat]salta │ ├── Salta il Coniglietto (salta).pdf │ └── salta.cpp ├── [2012][reg]barbablu │ ├── Il tesoro del Pirata Barbablù (barbablu).pdf │ └── barbablu.cpp ├── [2012][reg]grandprix │ ├── Grand Prix (grandprix).pdf │ ├── grandprix.cpp │ └── grandprix2.cpp ├── [2012][reg]turni │ ├── Turni di guardia (turni).pdf │ ├── turni.cpp │ └── turni2.cpp ├── [2013][nat]bufale │ ├── Mozzarelle di bufala (bufale).pdf │ └── bufale.cpp ├── [2013][nat]maree │ ├── Maree a Venezia (maree).pdf │ ├── maree.cpp │ ├── maree2.cpp │ ├── maree3.cpp │ └── maree4.cpp ├── [2013][nat]spiedini │ ├── Spiedini di frutta (spiedini).pdf │ └── spiedini.cpp ├── [2013][reg]brisbane │ ├── A spasso per Brisbane (brisbane).pdf │ └── brisbane.cpp ├── [2013][reg]gardaland │ ├── Gita a Gardaland (gardaland).pdf │ └── gardaland.cpp ├── [2013][reg]trovaparola │ ├── Trova la parola (trovaparola).pdf │ ├── trovaparola.cpp │ └── trovaparola2.cpp ├── [2014][abc]messaggi │ ├── Messaggi (messaggi).pdf │ └── messaggi.cpp ├── [2014][gator]cannoniere │ ├── Cannoniere (cannoniere).pdf │ └── cannoniere.cpp ├── [2014][gator]fulcrodelgioco │ ├── Fulcro del gioco (fulcro).pdf │ ├── fulcrodelgioco.cpp │ └── fulcrodelgioco2.cpp ├── [2014][gator]fuorigioco │ ├── Fuorigioco (fuorigioco).pdf │ ├── fuorigioco.cpp │ ├── fuorigioco2.cpp │ └── fuorigioco3.cpp ├── [2014][gator]sorteggio │ ├── Pilota il sorteggio (sorteggio).pdf │ ├── sorteggio.cpp │ └── sorteggio2.cpp ├── [2014][nat]bottleneck │ ├── Collo di bottiglia (bottleneck).pdf │ └── bottleneck.cpp ├── [2014][reg]collaz │ ├── La Congettura di Collatz (collatz).pdf │ └── collatz.cpp ├── [2014][reg]mojito │ ├── Giochiamo con Mojito (mojito).pdf │ ├── mojito.cpp │ └── mojito2.cpp ├── [2014][reg]sommelier │ ├── Corso per Sommelier (sommelier).pdf │ └── sommelier.cpp ├── [2015][gator]canoa │ ├── Canottaggio (canoa).pdf │ └── canoa.cpp ├── [2015][gator]cercalesomme │ ├── Cerca le somme (cercalesomme).pdf │ └── cercalesomme.cpp ├── [2015][gator]classifica │ ├── Classifica (classifica).pdf │ └── classifica.cpp ├── [2015][gator]tedoforo │ ├── Tedoforo (tedoforo).pdf │ ├── tedoforo.cpp │ └── tedoforo1.cpp ├── [2015][reg]semiprimi │ ├── Numero semiprimo (semiprimo).pdf │ └── semiprimi.cpp ├── shelton.c └── shelton.cpp ├── README.md ├── UNIPI ├── biglietti │ ├── Biglietti a Milano (biglietti).pdf │ └── biglietti.cpp ├── capslock │ ├── cAPS lOCK (capslock).pdf │ ├── capslock.cpp │ └── capslock2.cpp ├── cotte~ │ ├── Cottarelle in classe (cotte).pdf │ └── cotte.cpp ├── crittografia │ ├── Crittografia (crittografia).pdf │ └── crittografia.cpp ├── cubetti │ ├── Cubetti colorati (cubetti).pdf │ ├── Cubetti colorati (cubetti_n).pdf │ ├── cubetti.cpp │ ├── cubetti2.cpp │ └── cubetti_n.cpp ├── distributori │ ├── Rifornimenti ai distributori (distributori).pdf │ └── distributori.cpp ├── easy1 │ ├── Trova il massimo (easy1).pdf │ └── easy1.cpp ├── easy2 │ ├── Trova la somma pari massima (easy2).pdf │ └── easy2.cpp ├── easy3 │ ├── Trova la somma pari massima v2.0 (easy3).pdf │ └── easy3.cpp ├── figonacci │ ├── Numeri di Figonacci (figonacci).pdf │ └── figonacci.cpp ├── giardino │ ├── Giardino imperiale (giardino).pdf │ └── giardino.cpp ├── interrogazioni │ ├── Interrogazioni equilibrate (interrogazioni).pdf │ ├── interrogazioni.cpp │ └── interrogazioni2.cpp ├── kfree │ ├── Insieme k-free (kfree).pdf │ ├── Insieme k-free (kfree_n).pdf │ ├── kfree.cpp │ ├── kfree2.cpp │ └── kfree_n.cpp ├── licenziamenti │ ├── Tagli al personale (licenziamenti).pdf │ └── licenziamenti.cpp ├── minato │ ├── Campo minato (minato).pdf │ ├── minato.cpp │ └── minato2.cpp ├── ois_bilancio │ ├── Finanza creativa (bilancio).pdf │ ├── ois_bilancio.cpp │ └── ois_bilancio2.cpp ├── ois_medaglie~ │ ├── Oro, argento e bronzo (medaglie).pdf │ └── ois_medaglie.cpp ├── ois_ponti │ ├── Ponti e isole (ponti).pdf │ └── ois_ponti.cpp ├── padrun │ ├── Controllare l’accampamento (padrun).pdf │ └── padrun.cpp ├── papa~ │ ├── Papà (papa).pdf │ ├── papa.cpp │ └── papa2.cpp ├── pazzo │ ├── Tecnico pazzo (pazzo).pdf │ └── pazzo.cpp ├── piastrelle │ ├── Piastrellature (piastrelle).pdf │ └── piastrelle.cpp ├── ponti │ ├── Ponti (ponti).pdf │ ├── ponti.cpp │ └── ponti2.cpp ├── race │ ├── Box Car Race (race).pdf │ └── race.cpp ├── rangetree1 │ ├── Flipping Coins (rangetree1).pdf │ ├── rangetree1_1.cpp │ ├── rangetree1_2.cpp │ └── rangetree1_3.cpp ├── rangetree2 │ ├── Multiples of 3 (rangetree2).pdf │ └── rangetree2.cpp ├── rangetree3~ │ ├── Can you answer these queries III (rangetree3).pdf │ ├── rangetree3 - Copia (2).cpp │ ├── rangetree3 - Copia (3).cpp │ ├── rangetree3 - Copia.cpp │ └── rangetree3.cpp ├── regions~ │ ├── Regions (regions).pdf │ └── regions.cpp ├── ristorante │ ├── Ristorante (ristorante).pdf │ ├── ristorante.cpp │ └── ristorante2.cpp ├── shelton.c ├── shelton.cpp ├── subs │ ├── Massima sottostringa (subs).pdf │ └── subs.cpp ├── suffarr~ │ ├── Suffix Array (suffarr).pdf │ ├── suffarr.cpp │ ├── suffarr2.cpp │ ├── suffarr3.cpp │ └── suffarr4.cpp ├── talmart │ ├── Tal Mart (talmart).pdf │ ├── telmart.cpp │ └── telmart2.cpp ├── topologia │ ├── Topologia di rete (topologia).pdf │ ├── Topologia di rete (topologia_n).pdf │ ├── topologia.cpp │ └── topologia_n.cpp ├── torri │ ├── Torri (torri).pdf │ ├── torri.cpp │ └── torri2.cpp ├── training~ │ ├── Training (training).pdf │ ├── training.cpp │ └── training_1.cpp ├── triangoli │ ├── Triangoli pienotti (triangoli).pdf │ ├── triangoli.cpp │ ├── triangoli2.cpp │ ├── triangoli3.cpp │ ├── triangoli4.cpp │ └── triangoli5.cpp ├── vasi │ ├── Mattia e i suoi vasi (vasi).pdf │ └── vasi.cpp ├── vasi2~ │ ├── Mattia e i suoi vasi 2.0 (vasi2).pdf │ └── vasi2.cpp └── zigzag │ ├── ZigZag (zigzag).pdf │ ├── zigzag.cpp │ └── zigzag2.cpp ├── UVA ├── 119 │ ├── 119.cpp │ └── Greedy Gift Givers (119).pdf ├── 130 │ ├── 130.cpp │ └── Roman Roulette (130).pdf ├── 156 │ ├── 156.cpp │ └── Ananagrams (156).pdf ├── 161 │ ├── 161.cpp │ └── Traffic Lights (161).pdf ├── 183 │ ├── 183.cpp │ └── Bit Maps (183).pdf ├── 193 │ ├── 193.cpp │ └── Graph Coloring (193).pdf ├── 195 │ ├── 195.cpp │ └── Anagram (195).pdf ├── 272 │ ├── 272.cpp │ └── TEX Quotes (272).pdf ├── 278 │ ├── 278.cpp │ └── Chess (278).pdf ├── 401 │ ├── 401.cpp │ └── Palindromes (401).pdf ├── 454 │ ├── 454.cpp │ └── Anagrams (454).pdf ├── 462 │ ├── 462.cpp │ └── Bridge Hand Evaluator (462).pdf ├── 489 │ ├── 489.cpp │ └── Hangman Judge (489).pdf ├── 573 │ ├── 573.cpp │ └── The Snail (573).pdf ├── 574 │ ├── 574.cpp │ └── Sum It Up (574).pdf ├── 579 │ ├── 579.cpp │ └── Clock Hands (579).pdf ├── 584 │ ├── 584.cpp │ └── Bowling (584).pdf ├── 608 │ ├── 608.cpp │ └── Counterfeit Dollar (608).pdf ├── 621 │ ├── 621.cpp │ └── Secret Research (621).pdf ├── 637 │ ├── 637.cpp │ └── Booklet Printing (637).pdf ├── 661 │ ├── 661.cpp │ └── Blowing Fuses (661).pdf ├── 696 │ ├── 696.cpp │ └── How Many Knights (696).pdf ├── 846 │ ├── 846.cpp │ └── Steps (846).pdf ├── 872 │ ├── 872.cpp │ └── Ordering (872).pdf ├── 927 │ ├── 927.cpp │ └── Integer Sequences from Addition of Terms (927).pdf ├── 948 │ ├── 948.cpp │ └── Fibonaccimal Base (948).pdf ├── 1061 │ ├── 1061.cpp │ └── Consanguine Calculations (1061).pdf ├── 1124 │ ├── 1124.cpp │ └── Celebrity joepardy (1124).pdf ├── 10004 │ ├── 10004.cpp │ └── Bicoloring (10004).pdf ├── 10017 │ ├── 10017.cpp │ └── The Never Ending Towers of Hanoi (10017).pdf ├── 10038 │ ├── 10038.cpp │ └── Jolly Jumpers (10038).pdf ├── 10102 │ ├── 10102.cpp │ └── The path in the colored field (10102).pdf ├── 10114 │ ├── 10114.cpp │ └── Loansome Car Buyer (10114).pdf ├── 10130 │ ├── 10130.cpp │ └── SuperSale (10130).pdf ├── 10141 │ ├── 10141.cpp │ └── Request for Proposal (10141).pdf ├── 10189 │ ├── 10189.cpp │ └── Minesweeper (10189).pdf ├── 10284 │ ├── 10284.cpp │ └── Chessboard in FEN (10284).pdf ├── 10300 │ ├── 10300.cpp │ └── Ecological Premium (10300).pdf ├── 10324 │ ├── 10324.cpp │ └── Zeros and Ones (10324).pdf ├── 10341 │ ├── 10341.cpp │ └── Solve It (10341).pdf ├── 10424 │ ├── 10424.cpp │ └── Love Calculator (10424).pdf ├── 10443 │ ├── 10443.cpp │ └── Rock, Scissors, Paper (10443).pdf ├── 10487 │ ├── 10487.cpp │ └── Closest Sums (10487).pdf ├── 10550 │ ├── 10550.cpp │ └── Combination Lock (10550).pdf ├── 10576 │ ├── 10576.cpp │ └── Y2K Accounting Bug (10576).pdf ├── 10646 │ ├── 10646.cpp │ └── What is the Card? (10646).pdf ├── 10706 │ ├── 10706.cpp │ └── Number Sequence (10706).pdf ├── 10812 │ ├── 10812.cpp │ └── Beat the Spread! (10812).pdf ├── 10813 │ ├── 10813.cpp │ └── Traditional BINGO (10813).pdf ├── 10855 │ ├── 10855.cpp │ └── Rotated square (10855).pdf ├── 10919 │ ├── 10919.c │ ├── 10919.cpp │ └── Prerequisites? (10919).pdf ├── 10920 │ ├── 10920.cpp │ └── Spiral Tap (10920).pdf ├── 10945 │ ├── 10945.cpp │ └── Mother bear (10945).pdf ├── 10963 │ ├── 10963.cpp │ └── The swallowing Ground (10963).pdf ├── 11044 │ ├── 11044.cpp │ └── Searching for Nessy (11044).pdf ├── 11057 │ ├── 11057.cpp │ └── Exact Sum (11057).pdf ├── 11172 │ ├── 11172.cpp │ └── Relational Operator (11172).pdf ├── 11221 │ ├── 11221.cpp │ └── Magic square palindromes. (11221).pdf ├── 11332 │ ├── 11332.cpp │ └── Summing Digits (11332).pdf ├── 11340 │ ├── 11340.cpp │ └── Newspaper (11340).pdf ├── 11364 │ ├── 11364.cpp │ └── Parking (11364).pdf ├── 11459 │ ├── 11459.cpp │ └── Snakes and Ladders (11459).pdf ├── 11498 │ ├── 11498.cpp │ └── Division of Nlogonia (11498).pdf ├── 11507 │ ├── 11507.cpp │ └── Bender B. Rodríguez Problem (11507).pdf ├── 11547 │ ├── 11547.cpp │ └── Automatic Answer (11547).pdf ├── 11553 │ ├── 11553.cpp │ └── Grid Game (11553).pdf ├── 11559 │ ├── 11559.cpp │ └── Event Planning (11559).pdf ├── 11565 │ ├── 11565.cpp │ └── Simple Equations (11565).pdf ├── 11581 │ ├── 11581.cpp │ └── Grid Successors (11581).pdf ├── 11586 │ ├── 11586.cpp │ └── Train Tracks (11586).pdf ├── 11661 │ ├── 11661.cpp │ └── Burger Time? (11661).pdf ├── 11679 │ ├── 11679.cpp │ └── Sub-prime (11679).pdf ├── 11683 │ ├── 11683.cpp │ └── Laser Sculpture (11683).pdf ├── 11687 │ ├── 11687.cpp │ └── Digits (11687).pdf ├── 11727 │ ├── 11727.cpp │ └── Cost Cutting (11727).pdf ├── 11764 │ ├── 11764.cpp │ └── Jumping Mario (11764).pdf ├── 11799 │ ├── 11799.cpp │ └── Horror Dash (11799).pdf ├── 11831 │ ├── 11831.cpp │ └── Sticker Collector Robot (11831).pdf ├── 11906 │ ├── 11906.cpp │ └── Knight in a War Grid (11906).pdf ├── 11942 │ ├── 11942.cpp │ └── Lumberjack Sequencing (11942).pdf ├── 11946 │ ├── 11946.cpp │ └── Code Number (11946).pdf ├── 11953 │ ├── 11953.cpp │ └── Battleships (11953).pdf ├── 11956 │ ├── 11956.cpp │ └── Brainfuck (11956).pdf ├── 12015 │ ├── 12015.cpp │ └── Google is Feeling Lucky (12015).pdf ├── 12157 │ ├── 12157.cpp │ └── Tariff Plan (12157).pdf ├── 12247 │ ├── 12247.cpp │ └── Jollo (12247).pdf ├── 12250 │ ├── 12250.cpp │ └── Language Detection (12250).pdf ├── 12279 │ ├── 12279.cpp │ └── Emoogle Balance (12279).pdf ├── 12289 │ ├── 12289.cpp │ └── One-Two-Three (12289).pdf ├── 12356 │ ├── 12356.cpp │ └── Army Buddies (12356).pdf ├── 12372 │ ├── 12372.cpp │ └── Packing for Holiday (12372).pdf ├── 12403 │ ├── 12403.cpp │ └── Save Setu (12403).pdf ├── 12442 │ ├── 12442.cpp │ └── Forwarding Emails (12442).pdf ├── 12467 │ ├── 12467.cpp │ └── Secret Word (12467).pdf ├── 12468 │ ├── 12468.cpp │ └── Zapping (12468).pdf ├── 12478 │ ├── 12478.cpp │ └── Hardest Problem Ever (12478).pdf ├── 12503 │ ├── 12503.cpp │ └── Robot Instructions (12503).pdf ├── 12554 │ ├── 12554.cpp │ └── A Special "Happy Birthday" Song!!! (12554).pdf ├── 12577 │ ├── 12577.cpp │ └── Hajj-e-Akbar (12577).pdf ├── 12694 │ ├── 12694.cpp │ └── Meeting Room Arrangement (12694).pdf ├── 12696 │ ├── 12696.cpp │ └── Cabin Baggage (12696).pdf ├── 12854 │ ├── 12854.cpp │ └── Automated Checking Machine (12854).pdf ├── 12861 │ ├── 12861.cpp │ └── Help cupid (12861).pdf ├── 12862 │ ├── 12862.cpp │ └── Intrepid climber (12862).pdf ├── 100141 │ ├── 100141.cpp │ └── Vito’s family (10041).pdf ├── shelton.c └── shelton.cpp ├── pre-commit.bat ├── pre-commit.command └── pre-commit.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | # ========================= 31 | # Operating System Files 32 | # ========================= 33 | 34 | # OSX 35 | # ========================= 36 | 37 | .DS_Store 38 | .AppleDouble 39 | .LSOverride 40 | 41 | # Thumbnails 42 | ._* 43 | 44 | # Files that might appear in the root of a volume 45 | .DocumentRevisions-V100 46 | .fseventsd 47 | .Spotlight-V100 48 | .TemporaryItems 49 | .Trashes 50 | .VolumeIcon.icns 51 | 52 | # Directories potentially created on remote AFP share 53 | .AppleDB 54 | .AppleDesktop 55 | Network Trash Folder 56 | Temporary Items 57 | .apdisk 58 | 59 | # Windows 60 | # ========================= 61 | 62 | # Windows image file caches 63 | Thumbs.db 64 | ehthumbs.db 65 | 66 | # Folder config file 67 | Desktop.ini 68 | 69 | # Recycle Bin used on file shares 70 | $RECYCLE.BIN/ 71 | 72 | # Windows Installer files 73 | *.cab 74 | *.msi 75 | *.msm 76 | *.msp 77 | 78 | # Windows shortcuts 79 | *.lnk 80 | 81 | # In/Out file 82 | input.txt 83 | output.txt 84 | in.txt 85 | out.txt 86 | -------------------------------------------------------------------------------- /Algoritmhs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/Algoritmhs/.gitkeep -------------------------------------------------------------------------------- /IOI/[1994]triangolo/Il triangolo (triangolo).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/IOI/[1994]triangolo/Il triangolo (triangolo).pdf -------------------------------------------------------------------------------- /IOI/[2006]writing/Deciphering the Mayan writing (writing).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/IOI/[2006]writing/Deciphering the Mayan writing (writing).pdf -------------------------------------------------------------------------------- /IOI/[2006]writing/writing.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | #define FILE_INPUT "input.txt" 16 | #define FILE_OUTPUT "output.txt" 17 | 18 | int main() 19 | { 20 | ifstream in(FILE_INPUT); 21 | ofstream out(FILE_OUTPUT); 22 | 23 | if(!in || !out) return 1; 24 | 25 | int W,S,count = 0; 26 | string glyph,sequences; 27 | 28 | in>>W>>S; 29 | in>>glyph>>sequences; 30 | 31 | sort(glyph.begin(),glyph.end()); 32 | 33 | do { 34 | int temp = 0; 35 | while(true) { 36 | temp = sequences.find(glyph, temp); 37 | if(temp != -1) { 38 | temp++; 39 | count++; 40 | } 41 | else break; 42 | } 43 | } 44 | while(next_permutation(glyph.begin(),glyph.end())); 45 | 46 | out< 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | #define FILE_INPUT "input.txt" 16 | #define FILE_OUTPUT "output.txt" 17 | 18 | int abs(int x) { 19 | return x >= 0 ? x : -x; 20 | } 21 | 22 | int d(int B, vector &c1, vector &c2) { 23 | int dist = 0; 24 | for(int i = 0; i < B; i++) dist += abs(c2[i] - c1[i]); 25 | return dist; 26 | } 27 | 28 | int main() 29 | { 30 | ifstream in(FILE_INPUT); 31 | ofstream out(FILE_OUTPUT); 32 | 33 | if(!in || !out) return 1; 34 | 35 | int B, N, D, M; 36 | in>>B>>N>>D>>M; 37 | 38 | vector< vector > Point(N); 39 | 40 | for(int i = 0; i < N; i++) { 41 | Point[i].resize(B); 42 | for(int j = 0; j < B; j++) { 43 | in>>Point[i][j]; 44 | } 45 | } 46 | 47 | int count = 0; 48 | for(int i = 0; i < N-1; i++) { 49 | for(int j = i+1; j < N; j++) { 50 | if(d(B, Point[i], Point[j]) <= D) count++; 51 | } 52 | } 53 | 54 | out< 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | #define FILE_INPUT "input.txt" 19 | #define FILE_OUTPUT "output.txt" 20 | 21 | #define MAX_N 22 | 23 | int main() 24 | { 25 | ifstream in(FILE_INPUT); 26 | ofstream out(FILE_OUTPUT); 27 | 28 | if(!in || !out) return 1; 29 | 30 | int N, M; 31 | in>>N>>M; 32 | 33 | for(int i = 0; i < N; i++) { 34 | 35 | } 36 | in.close(); 37 | out.close(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /IOI/[2009]garage/Garage (garage).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/IOI/[2009]garage/Garage (garage).pdf -------------------------------------------------------------------------------- /IOI/[2009]poi/POI (poi).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/IOI/[2009]poi/POI (poi).pdf -------------------------------------------------------------------------------- /IOI/[2009]raisins~~/Raisins (raisins).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/IOI/[2009]raisins~~/Raisins (raisins).pdf -------------------------------------------------------------------------------- /IOI/[2009]raisins~~/raisins.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | #define FILE_INPUT "input.txt" 19 | #define FILE_OUTPUT "output.txt" 20 | 21 | #define MAX_N 22 | 23 | int main() 24 | { 25 | ifstream in(FILE_INPUT); 26 | ofstream out(FILE_OUTPUT); 27 | 28 | if(!in || !out) return 1; 29 | 30 | in.close(); 31 | out.close(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /IOI/[2010]ricehub~~/Ricehub (rice).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/IOI/[2010]ricehub~~/Ricehub (rice).pdf -------------------------------------------------------------------------------- /IOI/[2010]ricehub~~/ricehub.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define FILE_INPUT "input.txt" 17 | #define FILE_OUTPUT "output.txt" 18 | 19 | int main() 20 | { 21 | ifstream in(FILE_INPUT); 22 | ofstream out(FILE_OUTPUT); 23 | 24 | if(!in || !out) return 1; 25 | int N; 26 | long long B; 27 | in>>N>>B 28 | vector rice(N); 29 | 30 | for(int i = 0; i < N: i++) { 31 | in>>rice[i]; 32 | } 33 | 34 | in.close(); 35 | out.close(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /IOI/[2012]pizza/Olympic pizza (pizza).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/IOI/[2012]pizza/Olympic pizza (pizza).pdf -------------------------------------------------------------------------------- /IOI/[2012]queue/Italian queue (queue).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/IOI/[2012]queue/Italian queue (queue).pdf -------------------------------------------------------------------------------- /IOI/[2012]queue/[IOI 12]queue.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/IOI/[2012]queue/[IOI 12]queue.rar -------------------------------------------------------------------------------- /IOI/shelton.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #define FILE_INPUT "input.txt" 12 | #define FILE_OUTPUT "output.txt" 13 | 14 | int main() { 15 | FILE *in, *out; 16 | in = fopen(FILE_INPUT,"r"); 17 | out = fopen(FILE_OUTPUT,"w"); 18 | if(!in || !out) return 1; 19 | 20 | //fscanf(in,"%d", &N); 21 | //fprintf(out,"%d", N); 22 | 23 | fclose(in); 24 | fclose(out); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /IOI/shelton.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | //#include 13 | //#include 14 | //#include 15 | //#include 16 | //#include 17 | //#include 18 | //#include 19 | //#include 20 | 21 | //#include 22 | //#include 23 | 24 | using namespace std; 25 | 26 | #define FILE_INPUT "input.txt" 27 | #define FILE_OUTPUT "output.txt" 28 | 29 | int main() { 30 | ios_base::sync_with_stdio(false); // faster I/O 31 | ifstream in(FILE_INPUT); 32 | ofstream out(FILE_OUTPUT); 33 | if(!in || !out) return 1; 34 | 35 | //in >> N; 36 | //out << N; 37 | 38 | in.close(); 39 | out.close(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /OII/[2002][nat]borse/Borse di studio (borse).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2002][nat]borse/Borse di studio (borse).pdf -------------------------------------------------------------------------------- /OII/[2002][nat]borse/borse.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define FILE_INPUT "input.txt" 17 | #define FILE_OUTPUT "output.txt" 18 | 19 | int N; 20 | ifstream in; 21 | ofstream out; 22 | vector arr; 23 | 24 | void composition(unsigned short n, unsigned short s, unsigned short size = 0) { 25 | 26 | for(int k = 1; k <= s; k++) { 27 | arr[size] = k; 28 | if(n-k > 0) composition(n-k, k, size+1); 29 | else if(n-k == 0) { 30 | for(int j = 0; j < size+1; j++) out<>N; 44 | arr.resize(N); 45 | 46 | composition(N,N); 47 | 48 | in.close(); 49 | out.close(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /OII/[2003][nat]alberi/Alberi (alberi).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2003][nat]alberi/Alberi (alberi).pdf -------------------------------------------------------------------------------- /OII/[2003][reg]giostre/Giostre (giostre).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2003][reg]giostre/Giostre (giostre).pdf -------------------------------------------------------------------------------- /OII/[2003][reg]giostre/giostre.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | #define FILE_INPUT "input.txt" 16 | #define FILE_OUTPUT "output.txt" 17 | 18 | #define MIN_GIOSTRA 21 19 | 20 | int solution_1(unsigned short a, unsigned short b) { 21 | vector V(a); 22 | int inc = 0; 23 | while(!V[inc % a]) { 24 | V[inc % a] = true; 25 | inc += b; 26 | } 27 | return inc/b; 28 | } 29 | 30 | int solution_2(unsigned short a) { 31 | unsigned short start = 20; 32 | while(solution_1(a,start) != a) start++; 33 | return start; 34 | } 35 | 36 | int main() 37 | { 38 | ifstream in(FILE_INPUT); 39 | ofstream out(FILE_OUTPUT); 40 | 41 | if(!in || !out) return 0; 42 | 43 | unsigned short A, B; 44 | in>>A>>B; 45 | out< 10 | #include 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define FILE_INPUT "input.txt" 17 | #define FILE_OUTPUT "output.txt" 18 | 19 | int main() 20 | { 21 | ifstream in(FILE_INPUT); 22 | ofstream out(FILE_OUTPUT); 23 | 24 | if(!in || !out) return 0; 25 | int N, max = 0, smax = 0; 26 | vector panini; 27 | vector soluzione; 28 | 29 | in>>N; 30 | panini.resize(N); 31 | soluzione.resize(N); 32 | 33 | for(int i = 0; i < N; i++) { 34 | in>>panini[i]; 35 | 36 | for(int j = 0; j < i; j++) { 37 | if(panini[j] > panini[i] && soluzione[j] > max) max = soluzione[j]; 38 | } 39 | soluzione[i] = max+1; 40 | if(soluzione[i] > smax) smax = soluzione[i]; 41 | max = 0; 42 | } 43 | 44 | out< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | #define MAX_ROWLEN 80 18 | 19 | char encode(char _row[]) { 20 | char NUM[] = "1234567890"; 21 | char UPCASE[] = "ECDFIGHJOKLMNPUQRSTVYWXZAB"; 22 | char LOWCASE[] = "ecdfighjoklmnpuqrstvywxzab"; 23 | for(int i = 0; i < strlen(_row); i++) { 24 | if(_row[i] >= '0' && _row[i] <= '9') _row[i] = NUM[_row[i]-'0']; 25 | else if(_row[i] >= 'A' && _row[i] <= 'Z') _row[i] = UPCASE[_row[i]-'A']; 26 | else if(_row[i] >= 'a' && _row[i] <= 'z') _row[i] = LOWCASE[_row[i]-'a']; 27 | } 28 | return 0; 29 | } 30 | 31 | int main() 32 | { 33 | FILE *in,*out; 34 | in = fopen(FILE_INPUT,"r"); 35 | out = fopen(FILE_OUTPUT,"w"); 36 | if(!in || !out) return 1; 37 | int N; 38 | char row[MAX_ROWLEN]; 39 | fscanf(in,"%d\n",&N); 40 | for(int i = 0; i < N; i++) { 41 | fgets(row,MAX_ROWLEN,in); 42 | encode(row); 43 | fprintf(out,"%s",row); 44 | } 45 | 46 | fclose(in); 47 | fclose(out); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /OII/[2005][reg]korrot/La poltrona di Korrot (korrot).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2005][reg]korrot/La poltrona di Korrot (korrot).pdf -------------------------------------------------------------------------------- /OII/[2005][reg]sunny/Sunnydale (sunny).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2005][reg]sunny/Sunnydale (sunny).pdf -------------------------------------------------------------------------------- /OII/[2007][reg]lino/lino.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | #define MAX_N 100 //da 2 a 100 17 | #define MAX_R 1000 //da 2 a 1000 18 | 19 | int main() 20 | { 21 | FILE *in,*out; 22 | in = fopen(FILE_INPUT,"r"); 23 | out = fopen(FILE_OUTPUT,"w"); 24 | if(!in || !out) return 1; 25 | int N,R; 26 | int TAGLI[MAX_N] = {0}; 27 | int MAT[MAX_N][MAX_R] = {{0},{0}}; 28 | fscanf(in,"%d\n",&N); 29 | fscanf(in,"%d\n",&R); 30 | for(int i = 0; i < N; i++) { 31 | fscanf(in,"%d\n",&TAGLI[i]); 32 | MAT[i][0] = 1; 33 | } 34 | 35 | for(int j = 1; j < R+1; j++) { 36 | for(int i = 0; i < N; i++) { 37 | if(i-1 >= 0) MAT[i][j] = MAT[i-1][j]; 38 | if(j - TAGLI[i] >= 0) MAT[i][j] += MAT[i][j - TAGLI[i]]; 39 | } 40 | } 41 | 42 | fprintf(out,"%d",MAT[N-1][R]); 43 | 44 | fclose(in); 45 | fclose(out); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /OII/[2008][nat]triade~/Giornalismo d’inchiesta (triade).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2008][nat]triade~/Giornalismo d’inchiesta (triade).pdf -------------------------------------------------------------------------------- /OII/[2008][reg]mappa/Mappa antica (mappa).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2008][reg]mappa/Mappa antica (mappa).pdf -------------------------------------------------------------------------------- /OII/[2008][reg]missioni/Missioni segrete (missioni).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2008][reg]missioni/Missioni segrete (missioni).pdf -------------------------------------------------------------------------------- /OII/[2008][reg]missioni/missioni.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2008][reg]missioni/missioni.cpp -------------------------------------------------------------------------------- /OII/[2008][reg]pizzini/Codici e pizzini (pizzini).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2008][reg]pizzini/Codici e pizzini (pizzini).pdf -------------------------------------------------------------------------------- /OII/[2009][reg]depura/Depurazione dell’acqua (depura).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2009][reg]depura/Depurazione dell’acqua (depura).pdf -------------------------------------------------------------------------------- /OII/[2009][reg]essenza/Essenza per profumi (essenza).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2009][reg]essenza/Essenza per profumi (essenza).pdf -------------------------------------------------------------------------------- /OII/[2009][reg]essenza/essenza.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | using namespace std; 11 | 12 | #define FILE_INPUT "input.txt" 13 | #define FILE_OUTPUT "output.txt" 14 | 15 | #define MAX_N 1001 16 | 17 | int main() 18 | { 19 | FILE *in,*out; 20 | in = fopen(FILE_INPUT,"r"); 21 | out = fopen(FILE_OUTPUT,"w"); 22 | if(!in || !out) return 1; 23 | 24 | int K,N,max = 0,temp; 25 | int Costo[MAX_N]; 26 | fscanf(in,"%d %d\n",&K,&N); 27 | for(int i = 0; i < N; i++) { 28 | fscanf(in,"%d",&Costo[i]); 29 | } 30 | for(int i = 0; i < N; i++) { 31 | for(int j = 1; j <= K; j++) { 32 | if(i+j < N){ 33 | temp = Costo[i+j]-Costo[i]; 34 | if(max < temp) max = temp; 35 | } 36 | } 37 | } 38 | fprintf(out,"%d",max); 39 | 40 | fclose(in); 41 | fclose(out); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /OII/[2009][reg]treno/Treno di container (treno).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2009][reg]treno/Treno di container (treno).pdf -------------------------------------------------------------------------------- /OII/[2009][reg]treno/treno.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | ifstream fin; 18 | ofstream fout; 19 | 20 | void spostamenti(int T) { 21 | fout<<(T-2)/2<<" "<>N; 35 | if(N == 3) { 36 | fout<<"4 3\n2 7\n6 2\n4 6\n7 4"< 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | #define FILE_INPUT "input.txt" 19 | #define FILE_OUTPUT "output.txt" 20 | 21 | #define MAX_N 22 | 23 | int main() 24 | { 25 | ifstream in(FILE_INPUT); 26 | ofstream out(FILE_OUTPUT); 27 | 28 | if(!in || !out) return 1; 29 | 30 | in.close(); 31 | out.close(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /OII/[2010][nat]pesca~/Pesca bizzarra (pesca).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2010][nat]pesca~/Pesca bizzarra (pesca).pdf -------------------------------------------------------------------------------- /OII/[2010][reg]quasipal/Quasi-palindromi (quasipal).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2010][reg]quasipal/Quasi-palindromi (quasipal).pdf -------------------------------------------------------------------------------- /OII/[2010][reg]sbarramento/Sbarramento tattico (sbarramento).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2010][reg]sbarramento/Sbarramento tattico (sbarramento).pdf -------------------------------------------------------------------------------- /OII/[2010][reg]sbarramento/sbarramento.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | #define FILE_INPUT "input.txt" 16 | #define FILE_OUTPUT "output.txt" 17 | 18 | typedef pair pii; 19 | 20 | struct cmp { 21 | bool operator()(const pii a, const pii b) { 22 | return a.first > b.first; 23 | } 24 | }; 25 | 26 | int abs(int a) { 27 | return (a > 0 ? a : -a); 28 | } 29 | 30 | int dist(int x1, int y1, int x2, int y2) { 31 | return abs(x2-x1)+abs(y2-y1); 32 | } 33 | 34 | int main() 35 | { 36 | ifstream in(FILE_INPUT); 37 | ofstream out(FILE_OUTPUT); 38 | 39 | if(!in || !out) return 1; 40 | 41 | int N, X = 1, Y, minm = 0; 42 | pii read; 43 | priority_queue, cmp> Q; 44 | in>>N>>Y; 45 | for(int i = 0; i < N; i++) { 46 | in>>read.second>>read.first; //Y e X 47 | Q.push(read); 48 | } 49 | while(!Q.empty()) { 50 | read = Q.top(); 51 | Q.pop(); 52 | minm += dist(read.first, read.second,X,Y); 53 | X++; 54 | } 55 | out< 10 | using namespace std; 11 | 12 | #define FILE_INPUT "input.txt" 13 | #define FILE_OUTPUT "output.txt" 14 | 15 | #define MAX_N 100000 16 | 17 | int seq[MAX_N],N; 18 | 19 | bool IsFreq(int len) { 20 | if(N % len != 0 || len >= N || len <= 0) return false; 21 | int _j = 0; 22 | for(int _i = len; _i < N; _i++) { 23 | if(seq[_j] != seq[_i]) return false; 24 | _j++; 25 | if(_j == len) _j = 0; 26 | } 27 | return true; 28 | } 29 | 30 | int main() 31 | { 32 | FILE *in,*out; 33 | in = fopen(FILE_INPUT,"r"); 34 | out = fopen(FILE_OUTPUT,"w"); 35 | if(!in || !out) return 1; 36 | 37 | fscanf(in,"%d\n",&N); 38 | for(int i = 0; i < N; i++) { 39 | fscanf(in,"%d",&seq[i]); 40 | } 41 | int flag = 0; 42 | for(int i = 1; i < N; i++) { 43 | if(IsFreq(i)) { 44 | for(int j = 0; j < i; j++) { 45 | fprintf(out,"%d ",seq[j]); 46 | } 47 | flag = 1; 48 | break; 49 | } 50 | } 51 | if(flag == 0) fprintf(out,"%d",2); 52 | fclose(in); 53 | fclose(out); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /OII/[2010][reg]tamburello/tamburello2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | using namespace std; 11 | 12 | #define FILE_INPUT "input.txt" 13 | #define FILE_OUTPUT "output.txt" 14 | 15 | #define MAX_N 100000 16 | 17 | int seq[MAX_N],N; 18 | 19 | bool IsFreq(int len) { 20 | if(N % len != 0) return false; 21 | int _j = 0; 22 | for(int _i = len; _i < N; _i++) { 23 | if(seq[_j] != seq[_i]) return false; 24 | _j++; 25 | if(_j == len) _j = 0; 26 | } 27 | return true; 28 | } 29 | 30 | int main() 31 | { 32 | FILE *in,*out; 33 | in = fopen(FILE_INPUT,"r"); 34 | out = fopen(FILE_OUTPUT,"w"); 35 | if(!in || !out) return 1; 36 | 37 | int flag = 0; 38 | fscanf(in,"%d\n",&N); 39 | for(int i = 0; i < N; i++) { 40 | fscanf(in,"%d",&seq[i]); 41 | } 42 | for(int i = 1; i < N/2+1; i++) { 43 | if(IsFreq(i)) { 44 | for(int j = 0; j < i; j++) { 45 | fprintf(out,"%d ",seq[j]); 46 | } 47 | flag = 1; 48 | break; 49 | } 50 | } 51 | 52 | if(flag == 0) fprintf(out,"%d",2); 53 | fclose(in); 54 | fclose(out); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /OII/[2011][nat]bath/Per un pugno di baht (baht).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2011][nat]bath/Per un pugno di baht (baht).pdf -------------------------------------------------------------------------------- /OII/[2011][nat]bath/bath.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define FILE_INPUT "input.txt" 17 | #define FILE_OUTPUT "output.txt" 18 | 19 | int main() 20 | { 21 | ifstream in(FILE_INPUT); 22 | ofstream out(FILE_OUTPUT); 23 | 24 | if(!in || !out) return 1; 25 | 26 | int P, N; 27 | in>>P; 28 | for(int i = 0; i < P; i++) { 29 | in>>N; 30 | vector money(N); 31 | for(int i = 0; i < N; i++) { 32 | in>>money[i]; 33 | } 34 | sort(money.begin(), money.end()); 35 | 36 | int sol = 0, curr = 1; 37 | for(int i = 0; i < N; i++) { 38 | if(money[i] <= curr) { 39 | sol += money[i]; 40 | curr = sol +1; 41 | } 42 | else break; 43 | } 44 | out< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | 18 | int main() 19 | { 20 | ifstream in(FILE_INPUT); 21 | ofstream out(FILE_OUTPUT); 22 | 23 | if(!in || !out) return 1; 24 | 25 | int N; 26 | char bits, count = 0; 27 | in>>N; 28 | bits = ceil(log2(N)); 29 | for(int i = 0; i <= bits; i++) { 30 | if((N & (1 << i)) != 0) count++; 31 | } 32 | out<<(int)count; 33 | in.close(); 34 | out.close(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /OII/[2011][nat]scuola/Scuola di supereroi (scuola).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2011][nat]scuola/Scuola di supereroi (scuola).pdf -------------------------------------------------------------------------------- /OII/[2011][reg]domino/Domino massimale (dominio).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2011][reg]domino/Domino massimale (dominio).pdf -------------------------------------------------------------------------------- /OII/[2011][reg]domino/domino.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | #define MAX_N 10 17 | 18 | int tes[MAX_N][2]; 19 | int N,lunghezza; 20 | bool usata[MAX_N]; 21 | 22 | void trova_permutazione(int pos,int num_att = -1) 23 | { 24 | if (pos > lunghezza) lunghezza = pos; 25 | for (int i = 0; i < N; i++) 26 | { 27 | for(int j = 0; j < 2; j++) { 28 | if (num_att == -1 || (num_att == tes[i][j] && usata[i] == false)) 29 | { 30 | usata[i] = true; 31 | trova_permutazione(pos + 1,tes[i][1-j]); 32 | usata[i] = false; 33 | } 34 | } 35 | } 36 | } 37 | 38 | int main() 39 | { 40 | FILE *in,*out; 41 | in = fopen(FILE_INPUT,"r"); 42 | out = fopen(FILE_OUTPUT,"w"); 43 | if(!in || !out) return 1; 44 | 45 | fscanf(in,"%d\n",&N); 46 | for(int i = 0; i < N; i++) { 47 | fscanf(in,"%d %d\n",&tes[i][0],&tes[i][1]); 48 | } 49 | trova_permutazione(0); 50 | fprintf(out,"%d",lunghezza); 51 | 52 | fclose(in); 53 | fclose(out); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /OII/[2011][reg]galattici/Eserciti Galattici (galattici).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2011][reg]galattici/Eserciti Galattici (galattici).pdf -------------------------------------------------------------------------------- /OII/[2011][reg]galattici/galattici2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | #define MAX_K 10 18 | #define MAX_N 101 19 | #define MAX_CHAR 256 20 | 21 | int main() 22 | { 23 | FILE *in,*out; 24 | in = fopen(FILE_INPUT,"r"); 25 | out = fopen(FILE_OUTPUT,"w"); 26 | if(!in || !out) return 1; 27 | 28 | int M,N,K, I,J, conf = 1; 29 | char S[MAX_K] = {NULL}, c; 30 | int comb[MAX_N]['z'-'a']; 31 | fscanf(in,"%d %d %d\n",&M, &N, &K); 32 | for(int i = 0; i < K; i++) { 33 | fscanf(in,"%c ",&S[i]); 34 | } 35 | //printf("%s\n",S); 36 | for(int i = 0; i < M; i++) { 37 | fscanf(in,"%d %d %c\n",&I,&J,&c); 38 | comb[I][c-'a'] = J; 39 | } 40 | 41 | for(int i = 0; i < K; i++) { 42 | conf = comb[conf][S[i]-'a']; 43 | } 44 | fprintf(out,"%d",conf); 45 | fclose(in); 46 | fclose(out); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /OII/[2011][reg]nanga/Nanga Parbat (nanga).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2011][reg]nanga/Nanga Parbat (nanga).pdf -------------------------------------------------------------------------------- /OII/[2011][reg]nanga/nanga.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | using namespace std; 11 | 12 | #define FILE_INPUT "input.txt" 13 | #define FILE_OUTPUT "output.txt" 14 | 15 | #define MAX_N 1000 16 | 17 | int main() 18 | { 19 | FILE *in,*out; 20 | in = fopen(FILE_INPUT,"r"); 21 | out = fopen(FILE_OUTPUT,"w"); 22 | if(!in || !out) return 1; 23 | 24 | int N,temp1=0,act=5000; 25 | int count[200+1] = {0}; 26 | int max_c = -1, max_i = -1; 27 | fscanf(in,"%d\n",&N); 28 | for(int i = 0; i < N; i++) { 29 | fscanf(in,"%d\n", &temp1); 30 | act += temp1; 31 | count[act+100-5000]++; 32 | if(max_c == -1 || max_c < count[act+100-5000]) max_c = count[act+100-5000],max_i = act+100-5000; 33 | } 34 | fprintf(out,"%d",5000+max_i-100); 35 | fclose(in); 36 | fclose(out); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /OII/[2011][reg]nanga/nanga2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | using namespace std; 11 | 12 | #define FILE_INPUT "input.txt" 13 | #define FILE_OUTPUT "output.txt" 14 | 15 | #define MAX_N 1000 16 | #define MID_C 100000 17 | #define MAX_C 200000 18 | 19 | int main() 20 | { 21 | FILE *in,*out; 22 | in = fopen(FILE_INPUT,"r"); 23 | out = fopen(FILE_OUTPUT,"w"); 24 | if(!in || !out) return 1; 25 | 26 | int N,read,act = 0, count[MAX_C] = {0}; 27 | int max_c = -1, max_i = -1; 28 | fscanf(in,"%d\n",&N); 29 | count[0] = 1; 30 | for(int i = 0; i < N; i++) { 31 | fscanf(in,"%d\n", &read); 32 | act+=read; 33 | count[act+MID_C]++; 34 | if(count[act+MID_C] > max_c) { 35 | max_c = count[act+MID_C]; 36 | max_i = act; 37 | } 38 | } 39 | fprintf(out,"%d",5000+max_i); 40 | fclose(in); 41 | fclose(out); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /OII/[2012][nat]eso~/Espressioni senza operatori (eso).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2012][nat]eso~/Espressioni senza operatori (eso).pdf -------------------------------------------------------------------------------- /OII/[2012][nat]eso~/eso.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | int main() { 17 | ifstream in(FILE_INPUT); 18 | ofstream out(FILE_OUTPUT); 19 | 20 | if(!in || !out) return 1; 21 | 22 | unsigned int N, M; 23 | in>>N>>M; 24 | 25 | 26 | 27 | out< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | int main() { 18 | ifstream in(FILE_INPUT); 19 | ofstream out(FILE_OUTPUT); 20 | 21 | if(!in || !out) return 1; 22 | 23 | unsigned int len, first = 0, second = 0, max_len = 0, max_start = 0, temp; 24 | string S; 25 | in>>len; 26 | in>>S; 27 | //len = S.length(); 28 | 29 | for(unsigned int start = 0; start < len-2; start++) { 30 | if(max_len > len-start) break; 31 | if(S[start] == S[start+1]) continue; 32 | first = second = 1; 33 | while(!S.compare(start, first, S, start+first+second, first)) { 34 | temp = first; 35 | first = first+second; 36 | second = temp; 37 | } 38 | temp = first+second; 39 | if(temp > max_len) { 40 | max_len = temp; 41 | max_start = start; 42 | } 43 | first = 0; 44 | } 45 | out< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | int main() 18 | { 19 | ifstream in(FILE_INPUT); 20 | ofstream out(FILE_OUTPUT); 21 | 22 | if(!in || !out) return 1; 23 | 24 | int N; 25 | int count = 0; 26 | in>>N; 27 | vector V(N+1); 28 | vector S(N+1); 29 | for(int i = 1; i <= N; i++) in>>V[i]; 30 | int pos = 1; 31 | while(S[pos] == false) { 32 | S[pos] = true; 33 | count++; 34 | pos = ((pos+V[pos])%N)+1; 35 | } 36 | out< 10 | using namespace std; 11 | 12 | #define FILE_INPUT "input.txt" 13 | #define FILE_OUTPUT "output.txt" 14 | 15 | #define MAX_N 31 16 | #define MAX_M 101 17 | 18 | int POS[MAX_N]; 19 | 20 | int swap(int A, int B) { 21 | int _temp = POS[A]; 22 | POS[A] = POS[B]; 23 | POS[B] = _temp; 24 | } 25 | 26 | int main() 27 | { 28 | FILE *in,*out; 29 | in = fopen(FILE_INPUT,"r"); 30 | out = fopen(FILE_OUTPUT,"w"); 31 | if(!in || !out) return 1; 32 | 33 | int N,M,K,A,B; 34 | fscanf(in,"%d %d\n",&N, &M); 35 | for(int i = 1; i < N+1; i++) { 36 | fscanf(in,"%d\n",&K); 37 | POS[K] = i; 38 | } 39 | for(int i = 0; i < M; i++) { 40 | fscanf(in,"%d %d\n",&A,&B); 41 | swap(A,B); 42 | } 43 | for(int i = 1; i < N+1; i++) { 44 | if(POS[i] == 1) { 45 | fprintf(out,"%d",i); 46 | break; 47 | } 48 | } 49 | fclose(in); 50 | fclose(out); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /OII/[2012][reg]grandprix/grandprix2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | using namespace std; 11 | 12 | #define FILE_INPUT "input.txt" 13 | #define FILE_OUTPUT "output.txt" 14 | 15 | #define MAX_N 31 16 | #define MAX_M 101 17 | 18 | int POS[MAX_N]; 19 | 20 | /* 21 | int swap(int A, int B) { 22 | int _temp = POS[A]; 23 | POS[A] = POS[B]; 24 | POS[B] = _temp; 25 | }*/ 26 | #define swap(a, b) ((a)^=(b),(b)^=(a),(a)^=(b)) 27 | 28 | int main() 29 | { 30 | FILE *in,*out; 31 | in = fopen(FILE_INPUT,"r"); 32 | out = fopen(FILE_OUTPUT,"w"); 33 | if(!in || !out) return 1; 34 | 35 | int N,M,K,A,B; 36 | fscanf(in,"%d %d\n",&N, &M); 37 | for(int i = 1; i < N+1; i++) { 38 | fscanf(in,"%d\n",&K); 39 | POS[K] = i; 40 | } 41 | for(int i = 0; i < M; i++) { 42 | fscanf(in,"%d %d\n",&A,&B); 43 | swap(A,B); 44 | } 45 | for(int i = 1; i < N+1; i++) { 46 | if(POS[i] == 1) { 47 | fprintf(out,"%d",i); 48 | break; 49 | } 50 | } 51 | fclose(in); 52 | fclose(out); 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /OII/[2012][reg]turni/Turni di guardia (turni).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2012][reg]turni/Turni di guardia (turni).pdf -------------------------------------------------------------------------------- /OII/[2012][reg]turni/turni.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | using namespace std; 11 | 12 | #define FILE_INPUT "input.txt" 13 | #define FILE_OUTPUT "output.txt" 14 | 15 | #define MAX_N 51 16 | 17 | struct persone { 18 | int start,end; 19 | } 20 | 21 | bool persone_compare(persone a, persone b) 22 | { 23 | if(a.start < b.start) return true; 24 | return false; 25 | } 26 | 27 | int main() 28 | { 29 | FILE *in,*out; 30 | in = fopen(FILE_INPUT,"r"); 31 | out = fopen(FILE_OUTPUT,"w"); 32 | if(!in || !out) return 1; 33 | 34 | int K,N; 35 | persone DISP[MAX_N]; 36 | fscanf(in,"%d\n",&K); 37 | fscanf(in,"%d\n",&N); 38 | 39 | for(int i = 0; i < N; i++) { 40 | fscanf(in,"%d %d\n",DISP[i].start,DISP[i].end); 41 | } 42 | sort(DISP, DISP + N, persone_compare); 43 | 44 | //fprintf(out,"%d",i); 45 | fclose(in); 46 | fclose(out); 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /OII/[2013][nat]bufale/Mozzarelle di bufala (bufale).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2013][nat]bufale/Mozzarelle di bufala (bufale).pdf -------------------------------------------------------------------------------- /OII/[2013][nat]bufale/bufale.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | long long solve(int N, int* M, int* P) { 18 | long long somma = 0; 19 | vector D(N); 20 | for(int i = 0; i < N; i++) { 21 | D[i] = M[i] - P[i]; 22 | somma += M[i] + P[i]; 23 | } 24 | nth_element(D.begin(), D.begin()+N/2, D.end()); 25 | for(int i = 0; i < N/2; i++) somma += -D[i] + D[N/2+i]; 26 | return somma/2; 27 | } 28 | /* 29 | #include 30 | 31 | int main() 32 | { 33 | ifstream in(FILE_INPUT); 34 | ofstream out(FILE_OUTPUT); 35 | 36 | if(!in || !out) return 1; 37 | 38 | int N,M[5000],P[5000]; 39 | in>>N; 40 | for(int i = 0; i < N; i++) { 41 | in>>M[i]>>P[i]; 42 | } 43 | out< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | #define MAX_N 51 18 | #define MAX_G 101 19 | 20 | int main() 21 | { 22 | FILE *in,*out; 23 | in = fopen(FILE_INPUT,"r"); 24 | out = fopen(FILE_OUTPUT,"w"); 25 | if(!in || !out) return -1; 26 | 27 | int N,G,R; 28 | map giocatori; 29 | if(fscanf(in,"%d\n",&N)) { 30 | for(int i = 0; i < N; i++) { 31 | if(fscanf(in,"%d %d\n",&G, &R)) giocatori[G] += R; 32 | } 33 | int maxg = 0, maxr = 0; 34 | for(map::iterator it = giocatori.begin(); it != giocatori.end(); it++) { 35 | if(maxr < it->second) { 36 | maxr = it->second; 37 | maxg = it->first; 38 | } 39 | } 40 | fprintf(out,"%d %d",maxg, maxr); 41 | } 42 | 43 | fclose(in); 44 | fclose(out); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /OII/[2014][gator]fulcrodelgioco/Fulcro del gioco (fulcro).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2014][gator]fulcrodelgioco/Fulcro del gioco (fulcro).pdf -------------------------------------------------------------------------------- /OII/[2014][gator]fulcrodelgioco/fulcrodelgioco.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2014][gator]fulcrodelgioco/fulcrodelgioco.cpp -------------------------------------------------------------------------------- /OII/[2014][gator]fuorigioco/Fuorigioco (fuorigioco).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2014][gator]fuorigioco/Fuorigioco (fuorigioco).pdf -------------------------------------------------------------------------------- /OII/[2014][gator]sorteggio/Pilota il sorteggio (sorteggio).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2014][gator]sorteggio/Pilota il sorteggio (sorteggio).pdf -------------------------------------------------------------------------------- /OII/[2014][gator]sorteggio/sorteggio2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | #define MAX_N 17 | 18 | char sol16[] = "VFFHHHHHHHQQQQGG"; 19 | char sol32[] = "VFFFFHHHHHHHHHHHHHHQQQQQQQOOOOGG"; 20 | char sol64[] = "VFFFFFFFHHHHHHHHHHHHHHHHHHHHHHHHHHHHQQQQQQQQQQQQQQOOOOOOOOSSSSGG"; 21 | 22 | int main() 23 | { 24 | ifstream in(FILE_INPUT); 25 | ofstream out(FILE_OUTPUT); 26 | 27 | if(!in || !out) return 1; 28 | int M,S,temp,count = 0; 29 | in>>M; 30 | in>>S; 31 | for(int i = 0; i < M-1; i++) { 32 | in>>temp; 33 | if(temp > S) count++; 34 | } 35 | 36 | if(M == 16) out< 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | /* 17 | int collaz(int n, int count = 0) { 18 | if(n == 1) return count+1; 19 | else { 20 | if(n % 2 == 0) return collaz(n/2,count+1); 21 | else return collaz((n*3)+1,count+1); 22 | } 23 | }*/ 24 | 25 | int main() 26 | { 27 | FILE *in,*out; 28 | in = fopen(FILE_INPUT,"r"); 29 | out = fopen(FILE_OUTPUT,"w"); 30 | if(!in || !out) return 0; 31 | 32 | int N; 33 | if(fscanf(in,"%d",&N) != 1) return 0; 34 | 35 | int count = 0; 36 | while(1) { 37 | if(N <= 1) { 38 | count+=1; 39 | break; 40 | } 41 | else { 42 | if(N % 2 == 0) { 43 | N = N/2; 44 | count+=1; 45 | } 46 | else { 47 | N = (N*3)+1; 48 | count+=1; 49 | } 50 | } 51 | } 52 | fprintf(out,"%d",count); 53 | 54 | fclose(in); 55 | fclose(out); 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /OII/[2014][reg]mojito/Giochiamo con Mojito (mojito).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2014][reg]mojito/Giochiamo con Mojito (mojito).pdf -------------------------------------------------------------------------------- /OII/[2014][reg]sommelier/Corso per Sommelier (sommelier).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2014][reg]sommelier/Corso per Sommelier (sommelier).pdf -------------------------------------------------------------------------------- /OII/[2014][reg]sommelier/sommelier.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | #define MAX_N 1000 17 | 18 | int main() 19 | { 20 | FILE *in,*out; 21 | in = fopen(FILE_INPUT,"r"); 22 | out = fopen(FILE_OUTPUT,"w"); 23 | if(!in || !out) return 0; 24 | int N; 25 | int Alchol[MAX_N]; 26 | if(fscanf(in,"%d",&N) != 1) return 0; 27 | for(int i = 0; i < N; i++) { 28 | if(fscanf(in,"%d",&Alchol[i]) != 1) return 0; 29 | } 30 | 31 | int Soluzione[MAX_N] = {1,0}; 32 | int max = 0; 33 | for(int i = 1; i < N; i++) { 34 | for(int j = i-2; j > -1; j--) { 35 | if(Alchol[j] <= Alchol[i] && Soluzione[j] > max) max = Soluzione[j]; 36 | } 37 | Soluzione[i] = max+1; 38 | max = 0; 39 | } 40 | max = 0; 41 | for(int i = 0; i < N; i++) { 42 | if(Soluzione[i] > max) max = Soluzione[i]; 43 | } 44 | 45 | fprintf(out,"%d",max); 46 | 47 | fclose(in); 48 | fclose(out); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /OII/[2015][gator]canoa/Canottaggio (canoa).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/OII/[2015][gator]canoa/Canottaggio (canoa).pdf -------------------------------------------------------------------------------- /OII/[2015][gator]canoa/canoa.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | #define m_p(a,b) make_pair(a,b) 18 | 19 | typedef pair pif; 20 | 21 | struct cmp { 22 | bool operator()(pif const& a, pif const& b) const { 23 | return a.second < b.second; 24 | } 25 | }; 26 | 27 | int main() 28 | { 29 | ifstream fin(FILE_INPUT); 30 | ofstream fout(FILE_OUTPUT); 31 | 32 | if(!fin || !fout) return 1; 33 | int N, K, p, f; 34 | pif top; 35 | priority_queue, cmp> V; 36 | fin>>N>>K; 37 | for(int i = 1; i <= N; i++) { 38 | fin>>f>>p; 39 | V.push(m_p(i,f-1.5*p)); 40 | } 41 | for(int i = 0; i < K; i++) { 42 | top = V.top(); 43 | V.pop(); 44 | fout< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | int main() 18 | { 19 | ifstream fin(FILE_INPUT); 20 | ofstream fout(FILE_OUTPUT); 21 | 22 | if(!fin || !fout) return 1; 23 | 24 | int N , g1, g2, s1, s2, max_g = 0, max_s = 0; 25 | fin>>N; 26 | vector S(N+1); 27 | while(!fin.eof()) { 28 | for(int i = 0; i < N; i++) { 29 | if(fin>>s1>>s2>>g1>>g2) { 30 | if(g1 > g2) S[s1]+=3; 31 | else if(g2 > g1) S[s2]+=3; 32 | else {S[s1]++;S[s2]++;} 33 | } 34 | } 35 | } 36 | for(int s = 1; s <= N; s++) { 37 | if(S[s] > max_g || S[s] == max_g && s < max_s) { 38 | max_s = s; 39 | max_g = S[s]; 40 | } 41 | } 42 | fout< 10 | 11 | #define FILE_INPUT "input.txt" 12 | #define FILE_OUTPUT "output.txt" 13 | 14 | int main() { 15 | FILE *in, *out; 16 | in = fopen(FILE_INPUT,"r"); 17 | out = fopen(FILE_OUTPUT,"w"); 18 | if(!in || !out) return 1; 19 | 20 | //fscanf(in,"%d", &N); 21 | //fprintf(out,"%d", N); 22 | 23 | fclose(in); 24 | fclose(out); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /OII/shelton.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | //#include 13 | //#include 14 | //#include 15 | //#include 16 | //#include 17 | //#include 18 | //#include 19 | //#include 20 | 21 | //#include 22 | //#include 23 | 24 | using namespace std; 25 | 26 | #define FILE_INPUT "input.txt" 27 | #define FILE_OUTPUT "output.txt" 28 | 29 | int main() { 30 | ios_base::sync_with_stdio(false); // faster I/O 31 | ifstream in(FILE_INPUT); 32 | ofstream out(FILE_OUTPUT); 33 | if(!in || !out) return 1; 34 | 35 | //in >> N; 36 | //out << N; 37 | 38 | in.close(); 39 | out.close(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | competitive-programming 2 | =========== 3 | 4 | Hello World! 5 | 6 | This repository contains all the solutions for problems I solved in programming competitions. 7 | 8 | The solutions are organized by the source of the problems in different folders. 9 | 10 | > Algorithms (Templates for algorithms and data structures) 11 | 12 | > OII (Italian Olympiads in Informatics) http://www.olimpiadi-informatica.it/ 13 | 14 | > UNPI (Università di Pisa) http://cms.di.unipi.it 15 | 16 | > IOI (International Olympiads in Informatics) http://www.ioinformatics.org/ 17 | 18 | > UVA (University of Valladolid Online Judge) https://uva.onlinejudge.org/ 19 | -------------------------------------------------------------------------------- /UNIPI/biglietti/Biglietti a Milano (biglietti).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/biglietti/Biglietti a Milano (biglietti).pdf -------------------------------------------------------------------------------- /UNIPI/biglietti/biglietti.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | #define MAX_N 18 | 19 | int main() 20 | { 21 | ifstream fin(FILE_INPUT); 22 | ofstream fout(FILE_OUTPUT); 23 | 24 | if(!fin || !fout) return 1; 25 | 26 | int N, A, M, B, ans; 27 | fin>>N>>M>>A>>B; 28 | 29 | if(A*M < B || A*N < B) { 30 | ans = A*N; 31 | } 32 | else { 33 | ans = (N/M)*B; 34 | int rest = (N%M)*A; 35 | ans += rest < B ? rest : B; 36 | } 37 | 38 | fout< 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | int main() 17 | { 18 | ifstream in(FILE_INPUT); 19 | ofstream out(FILE_OUTPUT); 20 | 21 | if(!in || !out) return 1; 22 | 23 | int N; 24 | char c; 25 | in>>N; 26 | in.get(c); 27 | for(int i = 0; i < N; i++) { 28 | in.get(c); 29 | if('A' <= c && c <= 'Z') c |= (1<<5); 30 | else if('a' <= c && c <= 'z') c &= ~(0<<5); 31 | out< 10 | 11 | #define FILE_INPUT "input.txt" 12 | #define FILE_OUTPUT "output.txt" 13 | 14 | int main() 15 | { 16 | FILE *fin = fopen(FILE_INPUT,"r"); 17 | FILE *fout = fopen(FILE_OUTPUT,"w"); 18 | 19 | int N; 20 | char c; 21 | fscanf(fin, "%d", &N); 22 | fscanf(fin, "%c", &c); 23 | for(int i = 0; i < N; i++) { 24 | fscanf(fin, "%c", &c); 25 | if('A' <= c && c <= 'Z') c |= (1<<5); 26 | else if('a' <= c && c <= 'z') c &= ~(1<<5); 27 | fprintf(fout, "%c", c); 28 | } 29 | 30 | fclose(fout); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /UNIPI/cotte~/Cottarelle in classe (cotte).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/cotte~/Cottarelle in classe (cotte).pdf -------------------------------------------------------------------------------- /UNIPI/cotte~/cotte.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | #define FILE_INPUT "input.txt" 19 | #define FILE_OUTPUT "output.txt" 20 | 21 | #define MAX_N 22 | 23 | int main() 24 | { 25 | ifstream in(FILE_INPUT); 26 | ofstream out(FILE_OUTPUT); 27 | 28 | if(!in || !out) return 1; 29 | 30 | in.close(); 31 | out.close(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /UNIPI/crittografia/Crittografia (crittografia).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/crittografia/Crittografia (crittografia).pdf -------------------------------------------------------------------------------- /UNIPI/cubetti/Cubetti colorati (cubetti).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/cubetti/Cubetti colorati (cubetti).pdf -------------------------------------------------------------------------------- /UNIPI/cubetti/Cubetti colorati (cubetti_n).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/cubetti/Cubetti colorati (cubetti_n).pdf -------------------------------------------------------------------------------- /UNIPI/cubetti/cubetti.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | int main() 18 | { 19 | ifstream in(FILE_INPUT); 20 | ofstream out(FILE_OUTPUT); 21 | 22 | if(!in || !out) return 1; 23 | 24 | int N,read,count = 0; 25 | in>>N; 26 | vector check(N+1); 27 | for(int i = 0; i < N; i++) { 28 | in>>read; 29 | if(!check[read]) check[read] = true; 30 | else count++; 31 | } 32 | 33 | out< 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | int main() 17 | { 18 | ifstream fin(FILE_INPUT); 19 | ofstream fout(FILE_OUTPUT); 20 | 21 | if(!fin || !fout) return 1; 22 | 23 | int N, M, K, p[2], pos = 0, cnt = 0; 24 | fin>>N>>M>>K; 25 | 26 | fin>>p[0]; 27 | for(int i = 1; i < N; i++) { 28 | fin>>p[i%2]; 29 | if(p[i%2]-pos < M) continue; 30 | else if(p[i%2]-pos == M) { 31 | pos = p[i%2]; 32 | cnt++; 33 | } 34 | else { 35 | pos = p[(i-1)%2]; 36 | cnt++; 37 | } 38 | } 39 | if(pos+M < K) cnt++; 40 | 41 | fout< 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | int main() 17 | { 18 | ifstream in(FILE_INPUT); 19 | ofstream out(FILE_OUTPUT); 20 | 21 | if(!in || !out) return 1; 22 | 23 | int N, max = 0, temp; 24 | in>>N; 25 | for(int i = 0; i < N; i++) { 26 | in>>temp; 27 | if(temp > max|| i == 0) max = temp; 28 | } 29 | out< 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | int main() 17 | { 18 | ifstream in(FILE_INPUT); 19 | ofstream out(FILE_OUTPUT); 20 | 21 | if(!in || !out) return 1; 22 | 23 | int N,t1,t2,max = -1,temp; 24 | 25 | in>>N; 26 | 27 | for(int i = 0; i < N; i++) { 28 | in>>t1; 29 | in>>t2; 30 | temp = t1 + t2; 31 | if(temp % 2 != 0) continue; 32 | if(temp > max) max = temp; 33 | } 34 | 35 | out< 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | int insert(int n, int var[]) { 17 | if(n > var[0]) { 18 | var[1] = var[0]; 19 | var[0] = n; 20 | return 1; 21 | } 22 | else if(n > var[1]) { 23 | var[1] = n; 24 | return 1; 25 | } 26 | return 0; 27 | } 28 | 29 | int main() 30 | { 31 | ifstream in(FILE_INPUT); 32 | ofstream out(FILE_OUTPUT); 33 | 34 | if(!in || !out) return 1; 35 | 36 | int N,temp,s1,s2; 37 | int odd[2] = {-1,-1}, even[2] = {-1,-1}; 38 | in>>N; 39 | 40 | for(int i = 0; i < N; i++) { 41 | in>>temp; 42 | if(temp % 2 == 0) { //pari 43 | insert(temp,even); 44 | } 45 | else { 46 | insert(temp,odd); 47 | } 48 | } 49 | if(odd[1] != -1 || even[1] != -1) { 50 | s1 = odd[0]+odd[1]; 51 | s2 = even[0]+even[1]; 52 | out<< (s1 > s2 ? s1 : s2); 53 | } 54 | else { 55 | out<<-1; 56 | } 57 | in.close(); 58 | out.close(); 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /UNIPI/figonacci/Numeri di Figonacci (figonacci).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/figonacci/Numeri di Figonacci (figonacci).pdf -------------------------------------------------------------------------------- /UNIPI/figonacci/figonacci.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #define F0 -1 10 | #define F1 0 11 | 12 | using namespace std; 13 | 14 | int enumera(int N, int M) { 15 | int temp, Fn, sum; 16 | 17 | sum = M+(F0+F1); 18 | for(int i = 1; i < N; i++) { 19 | temp = Fn; 20 | Fn = (((((i % M) * (Fn % M)) % M) - sum) + M) % M; 21 | sum = (sum + temp) % M; 22 | } 23 | return Fn; 24 | } 25 | 26 | #include 27 | #include 28 | 29 | int main() { 30 | FILE *fr, *fw; 31 | int N, M; 32 | 33 | fr = fopen("input.txt", "r"); 34 | fw = fopen("output.txt", "w"); 35 | assert(2 == fscanf(fr, "%d%d", &N, &M)); 36 | 37 | fprintf(fw, "%d\n", enumera(N, M)); 38 | fclose(fr); 39 | fclose(fw); 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /UNIPI/giardino/Giardino imperiale (giardino).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/giardino/Giardino imperiale (giardino).pdf -------------------------------------------------------------------------------- /UNIPI/interrogazioni/Interrogazioni equilibrate (interrogazioni).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/interrogazioni/Interrogazioni equilibrate (interrogazioni).pdf -------------------------------------------------------------------------------- /UNIPI/interrogazioni/interrogazioni2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define FILE_INPUT "input.txt" 17 | #define FILE_OUTPUT "output.txt" 18 | 19 | #define ui unsigned int 20 | 21 | int main() 22 | { 23 | ifstream fin(FILE_INPUT); 24 | ofstream fout(FILE_OUTPUT); 25 | 26 | if(!fin || !fout) return 1; 27 | 28 | vector D; 29 | ui N, K, read, sum, maxsub = numeric_limits::max(); 30 | 31 | fin>>N>>K; 32 | D.reserve(N-1); 33 | 34 | if(K == 1) maxsub = 0; 35 | else { 36 | for(ui i = 0; i < N; i++) { 37 | fin>>read; 38 | D.push_back(read); 39 | } 40 | sort(D.begin(), D.end()); 41 | maxsub = D[K-1]-D[0]; 42 | for(int i = 1; K-1+i < N; i++) { 43 | sum = D[K-1+i] - D[i]; 44 | if(sum < maxsub) maxsub = sum; 45 | } 46 | } 47 | fout< 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | #define MAX_N 100000 17 | 18 | bool check[MAX_N]; 19 | 20 | int main() 21 | { 22 | ifstream in(FILE_INPUT); 23 | ofstream out(FILE_OUTPUT); 24 | 25 | if(!in || !out) return 1; 26 | 27 | int N, K, a, count = 0,max = 0; 28 | in>>N>>K; 29 | 30 | if(K == 1) { 31 | out<<0; 32 | in.close(); 33 | out.close(); 34 | return 0; 35 | } 36 | 37 | for(int i = 0; i < N; i++) { 38 | in>>a; 39 | check[a] = true; 40 | if(a > max) max = a; 41 | } 42 | for(a = 1; a <= max; a++) { 43 | if(check[a] == true) { 44 | if(a*K <= max) check[a*K] = false; 45 | count++; 46 | } 47 | } 48 | out< 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | #define FILE_INPUT "input.txt" 16 | #define FILE_OUTPUT "output.txt" 17 | 18 | #define MAX_N 100000 19 | 20 | bool check[MAX_N]; 21 | 22 | int main() 23 | { 24 | ifstream in(FILE_INPUT); 25 | ofstream out(FILE_OUTPUT); 26 | 27 | if(!in || !out) return 1; 28 | 29 | int N, K, a, count = 0,max = 0; 30 | in>>N>>K; 31 | 32 | if(K == 1) { 33 | out<<0; 34 | in.close(); 35 | out.close(); 36 | return 0; 37 | } 38 | 39 | for(int i = 0; i < N; i++) { 40 | in>>a; 41 | if(a > max) max = a; 42 | check[a] = true; 43 | } 44 | for(int a = max; a > 0; a--) { 45 | if(check[a] == true) { 46 | if(a%K == 0) check[a/K] = false; 47 | count++; 48 | } 49 | } 50 | out< 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define FILE_INPUT "input.txt" 17 | #define FILE_OUTPUT "output.txt" 18 | 19 | int main() 20 | { 21 | ifstream in(FILE_INPUT); 22 | ofstream out(FILE_OUTPUT); 23 | 24 | if(!in || !out) return 1; 25 | int N,M; 26 | int idx_now, idx_next; 27 | string row; 28 | vector soluzione; 29 | 30 | in>>N>>M; 31 | 32 | soluzione.resize(M); 33 | soluzione[0] = 1; 34 | for(int i = 0; i < N; i++) { 35 | in>>row; 36 | 37 | for(int j = 0; j < M; j++) { 38 | if(row[j] == '*') { 39 | if(j+1 < M) soluzione[j+1] += soluzione[j]; 40 | } 41 | else soluzione[j] = 0; 42 | } 43 | } 44 | 45 | out< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | typedef unsigned int ui; 18 | 19 | int main() 20 | { 21 | ifstream fin(FILE_INPUT); 22 | ofstream fout(FILE_OUTPUT); 23 | 24 | if(!fin || !fout) return 1; 25 | 26 | ui N, K; 27 | fin>>N>>K; 28 | vector B(N); 29 | for(ui i = 0; i < N; i++) fin>>B[i]; 30 | 31 | for(ui i = 0; i < N-K; i++) { 32 | ui best = B[i]; 33 | if(best > 0 && K > 0) { 34 | ui index = 0; 35 | for(ui j = 1; j <= K; j++) { 36 | if(B[i+j] < best) { 37 | best = B[i+j]; 38 | index = j; 39 | if(best == 0) break; 40 | } 41 | } 42 | K -= index; 43 | i += index; 44 | } 45 | fout< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | int main() 18 | { 19 | ifstream fin(FILE_INPUT); 20 | ofstream fout(FILE_OUTPUT); 21 | 22 | if(!fin || !fout) return 1; 23 | 24 | int N, M, A, B; 25 | fin>>N>>M; 26 | vector< vector > G(N); 27 | for(int i = 0; i < M; i++) { 28 | fin>>A>>B; 29 | G[A].push_back(B); 30 | G[B].push_back(A); 31 | } 32 | 33 | fout<<""< 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | #define FILE_INPUT "input.txt" 19 | #define FILE_OUTPUT "output.txt" 20 | 21 | #define MAX_N 22 | 23 | int main() 24 | { 25 | ifstream in(FILE_INPUT); 26 | ofstream out(FILE_OUTPUT); 27 | 28 | if(!in || !out) return 1; 29 | int N; 30 | in>>N; 31 | 32 | for(int i = 0; i < N; i++) { 33 | int a, b; 34 | in>>a>>b; 35 | } 36 | in.close(); 37 | out.close(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /UNIPI/papa~/Papà (papa).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/papa~/Papà (papa).pdf -------------------------------------------------------------------------------- /UNIPI/papa~/papa.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define FILE_INPUT "input.txt" 17 | #define FILE_OUTPUT "output.txt" 18 | 19 | int main(){ 20 | ifstream in(FILE_INPUT); 21 | ofstream out(FILE_OUTPUT); 22 | int N, j, k; 23 | in>>N; 24 | string temp; 25 | vector M(N); 26 | for(int i = 0; i < N; i++) in>>M[i]; 27 | for(int r = 0; r < N; r++) { 28 | bool flag = false; 29 | vector< unordered_set > S(M[r]*2000); 30 | for(int s = 0; s < M[r]; s++) { 31 | in>>j; 32 | in>>k; 33 | in>>temp; 34 | for(int s = 0; s < k; s++) { 35 | if(temp[s] == '?') continue; 36 | S[j+s].insert(temp[s]); 37 | if(S[j+s].size() > 2) { 38 | flag = true; 39 | break; 40 | } 41 | } 42 | if(flag) break; 43 | } 44 | if(flag) out<<1< 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define FILE_INPUT "input.txt" 17 | #define FILE_OUTPUT "output.txt" 18 | 19 | int main(){ 20 | ifstream in(FILE_INPUT); 21 | ofstream out(FILE_OUTPUT); 22 | int N, j, k; 23 | in>>N; 24 | string temp; 25 | vector M(N); 26 | for(int i = 0; i < N; i++) in>>M[i]; 27 | for(int r = 0; r < N; r++) { 28 | bool flag = false; 29 | vector< unordered_set > S(M[r]*2000); 30 | for(int s = 0; s < M[r]; s++) { 31 | in>>j; 32 | in>>k; 33 | in>>temp; 34 | for(int s = 0; s < k; s++) { 35 | if(temp[s] == '?') continue; 36 | S[j+s].insert(temp[s]); 37 | if(S[j+s].size() > 2) { 38 | flag = true; 39 | break; 40 | } 41 | } 42 | if(flag) break; 43 | } 44 | if(flag) out<<1< 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | #define FILE_INPUT "input.txt" 16 | #define FILE_OUTPUT "output.txt" 17 | 18 | #define MAX_N 19 | 20 | int main() 21 | { 22 | ifstream in(FILE_INPUT); 23 | ofstream out(FILE_OUTPUT); 24 | 25 | if(!in || !out) return 1; 26 | int N,M; 27 | vector ord; 28 | int t1,t2,first = 0; 29 | in>>N>>M; 30 | for(int i = 0; i < N; i++) ord.push_back(i); 31 | 32 | for(int i = 0; i < M; i++) { 33 | in>>t1>>t2; 34 | 35 | swap(ord[t1],ord[t2]); 36 | if(ord[t1] == 0) first = t1; 37 | else if(ord[t2] == 0) first = t2; 38 | } 39 | out< 10 | #include 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define FILE_INPUT "input.txt" 17 | #define FILE_OUTPUT "output.txt" 18 | 19 | #define MAX_N 20 | 21 | unsigned short N; 22 | ofstream out; 23 | ifstream in; 24 | vector arr; 25 | void compositions(unsigned short n = N, unsigned short size = 0) 26 | { 27 | for(int k = 1; k <= 2; k++) 28 | { 29 | arr[size] = k; 30 | if(n-k > 0) compositions(n-k, size+1); 31 | else if(n-k == 0) { 32 | for(int i = 0; i < size+1; i++) { 33 | if(arr[i] == 1) out<<"[O]"; 34 | else if(arr[i] == 2) out<<"[OOOO]"; 35 | } 36 | out<>N; 49 | arr.resize(N); 50 | compositions(); 51 | 52 | in.close(); 53 | out.close(); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /UNIPI/ponti/Ponti (ponti).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/ponti/Ponti (ponti).pdf -------------------------------------------------------------------------------- /UNIPI/race/Box Car Race (race).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/race/Box Car Race (race).pdf -------------------------------------------------------------------------------- /UNIPI/rangetree1/Flipping Coins (rangetree1).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/rangetree1/Flipping Coins (rangetree1).pdf -------------------------------------------------------------------------------- /UNIPI/rangetree1/rangetree1_1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | vector coins; 18 | 19 | int query(int A, int B) { 20 | int count = 0; 21 | for(int i = A; i <= B; i++) if(coins[i]) count++; 22 | return count; 23 | } 24 | 25 | void update(int A, int B) { 26 | for(int i = A; i <= B; i++) coins[i] = !coins[i]; 27 | return; 28 | } 29 | 30 | int main() 31 | { 32 | ifstream in(FILE_INPUT); 33 | ofstream out(FILE_OUTPUT); 34 | 35 | if(!in || !out) return 1; 36 | 37 | int N, Q; 38 | in>>N>>Q; 39 | coins.resize(N); 40 | 41 | int T, A, B; 42 | for(int i = 0; i < Q; i++) { 43 | in>>T>>A>>B; 44 | if(T) out< 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | #define FILE_INPUT "input.txt" 18 | #define FILE_OUTPUT "output.txt" 19 | 20 | #define MAX_N 21 | 22 | int main() 23 | { 24 | ifstream in(FILE_INPUT); 25 | ofstream out(FILE_OUTPUT); 26 | 27 | if(!in || !out) return 1; 28 | int N,D,M,temp,profitto=0; 29 | vector costi; 30 | in>>N>>D; 31 | costi.resize(N); 32 | 33 | for(int i = 0; i < N; i++) { 34 | in>>costi[i]; 35 | } 36 | in>>M; 37 | 38 | sort(costi.begin(),costi.end()); 39 | 40 | for(int i = 0; i < (N < M ? N : M); i++) profitto += costi[i]; 41 | if(N < M) profitto -= D*(M-N); 42 | 43 | out< 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | #define FILE_INPUT "input.txt" 18 | #define FILE_OUTPUT "output.txt" 19 | 20 | #define MAX_N 21 | 22 | int main() 23 | { 24 | ifstream in(FILE_INPUT); 25 | ofstream out(FILE_OUTPUT); 26 | 27 | if(!in || !out) return 1; 28 | 29 | int N,D,M,temp,profitto=0; 30 | priority_queue Q; 31 | 32 | in>>N>>D; 33 | for(int i = 0; i < N; i++) { 34 | in>>temp; 35 | Q.push(-temp); 36 | } 37 | in>>M; 38 | 39 | for(int i = 0; i < (N < M ? N : M); i++) { 40 | profitto += -Q.top(); 41 | Q.pop(); 42 | } 43 | if(N < M) profitto -= D*(M-N); 44 | 45 | out< 10 | 11 | #define FILE_INPUT "input.txt" 12 | #define FILE_OUTPUT "output.txt" 13 | 14 | int main() { 15 | FILE *in, *out; 16 | in = fopen(FILE_INPUT,"r"); 17 | out = fopen(FILE_OUTPUT,"w"); 18 | if(!in || !out) return 1; 19 | 20 | //fscanf(in,"%d", &N); 21 | //fprintf(out,"%d", N); 22 | 23 | fclose(in); 24 | fclose(out); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /UNIPI/shelton.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | //#include 13 | //#include 14 | //#include 15 | //#include 16 | //#include 17 | //#include 18 | //#include 19 | //#include 20 | 21 | //#include 22 | //#include 23 | 24 | using namespace std; 25 | 26 | #define FILE_INPUT "input.txt" 27 | #define FILE_OUTPUT "output.txt" 28 | 29 | int main() { 30 | ios_base::sync_with_stdio(false); // faster I/O 31 | ifstream in(FILE_INPUT); 32 | ofstream out(FILE_OUTPUT); 33 | if(!in || !out) return 1; 34 | 35 | //in >> N; 36 | //out << N; 37 | 38 | in.close(); 39 | out.close(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /UNIPI/subs/Massima sottostringa (subs).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/subs/Massima sottostringa (subs).pdf -------------------------------------------------------------------------------- /UNIPI/subs/subs.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | #define FILE_INPUT "input.txt" 19 | #define FILE_OUTPUT "output.txt" 20 | 21 | #define MAX_N 22 | 23 | int main() 24 | { 25 | ifstream in(FILE_INPUT); 26 | ofstream out(FILE_OUTPUT); 27 | 28 | if(!in || !out) return 1; 29 | 30 | in.close(); 31 | out.close(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /UNIPI/suffarr~/Suffix Array (suffarr).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/suffarr~/Suffix Array (suffarr).pdf -------------------------------------------------------------------------------- /UNIPI/suffarr~/suffarr.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | #define FILE_INPUT "input.txt" 20 | #define FILE_OUTPUT "output.txt" 21 | 22 | struct suffix { 23 | string sub; 24 | unsigned short idx; 25 | }; 26 | 27 | bool sort_func(suffix a, suffix b) { 28 | return a.sub < b.sub; 29 | } 30 | 31 | int main() 32 | { 33 | ifstream in(FILE_INPUT); 34 | ofstream out(FILE_OUTPUT); 35 | 36 | if(!in || !out) return 1; 37 | 38 | string S; 39 | 40 | in >> S; 41 | unsigned short len = S.size(); 42 | vector V(len); 43 | 44 | for(unsigned short i = 0; i < len; i++) { 45 | V[i].sub = S.substr(i, len-i); 46 | cout< 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | #define FILE_INPUT "input.txt" 18 | #define FILE_OUTPUT "output.txt" 19 | 20 | int len; 21 | string S; 22 | 23 | bool sort_func(int a, int b) { 24 | while(a < len && b b; 30 | } 31 | 32 | int main() 33 | { 34 | ifstream in(FILE_INPUT); 35 | ofstream out(FILE_OUTPUT); 36 | 37 | if(!in || !out) return 1; 38 | 39 | 40 | in >> S; 41 | len = S.size(); 42 | vector V(len); 43 | 44 | for(unsigned short i = 0; i < len; i++) { 45 | V[i] = i; 46 | } 47 | sort(V.begin(), V.end(), sort_func); 48 | for(unsigned short i = 0; i < len; i++) out << V[i] << " "; 49 | 50 | in.close(); 51 | out.close(); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /UNIPI/suffarr~/suffarr3.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | #define FILE_INPUT "input.txt" 19 | #define FILE_OUTPUT "output.txt" 20 | 21 | int len; 22 | string S; 23 | 24 | bool sort_func(int a, int b) { 25 | return S.substr(a) < S.substr(b); 26 | } 27 | 28 | int main() 29 | { 30 | ifstream in(FILE_INPUT); 31 | ofstream out(FILE_OUTPUT); 32 | 33 | if(!in || !out) return 1; 34 | 35 | 36 | in >> S; 37 | len = S.size(); 38 | vector V(len); 39 | 40 | for(unsigned short i = 0; i < len; i++) { 41 | V[i] = i; 42 | } 43 | sort(V.begin(), V.end(), sort_func); 44 | for(unsigned short i = 0; i < len; i++) out << V[i] << " "; 45 | 46 | in.close(); 47 | out.close(); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /UNIPI/talmart/Tal Mart (talmart).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UNIPI/talmart/Tal Mart (talmart).pdf -------------------------------------------------------------------------------- /UNIPI/talmart/telmart.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | struct person { 18 | unsigned int floor, sol; 19 | bool from; 20 | }; 21 | 22 | int main() 23 | { 24 | ifstream in(FILE_INPUT); 25 | ofstream out(FILE_OUTPUT); 26 | 27 | if(!in || !out) return 1; 28 | int N, P; 29 | in>>N>>P; 30 | vector People(N); 31 | 32 | int max; 33 | bool from; 34 | for(int i = 0; i < N; i++) { 35 | in>>People[i].floor; 36 | max = 0; 37 | from = true; 38 | for(int j = i-1; j > -1; j--) { 39 | if(People[j].sol < max) break; 40 | else if(People[j].from == (People[j].floor > People[i].floor)) { 41 | from = !People[j].from; 42 | max = People[j].sol; 43 | } 44 | } 45 | People[i].from = from; 46 | People[i].sol = max+1; 47 | } 48 | out< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | struct person { 18 | unsigned int floor, sol; 19 | bool from; 20 | }; 21 | 22 | int main() 23 | { 24 | ifstream in(FILE_INPUT); 25 | ofstream out(FILE_OUTPUT); 26 | 27 | if(!in || !out) return 1; 28 | int N, P; 29 | in>>N>>P; 30 | vector People(N); 31 | 32 | in>>People[0].floor; 33 | People[0].from = true; 34 | People[0].sol = 1; 35 | for(int i = 1; i < N; i++) { 36 | int j = i-1; 37 | in>>People[i].floor; 38 | if(People[j].from == (People[j].floor > People[i].floor)) { 39 | People[i].from = !People[j].from; 40 | People[i].sol = People[j].sol+1; 41 | } 42 | else { 43 | People[i].from = People[j].from; 44 | People[i].sol = People[j].sol; 45 | } 46 | } 47 | out< 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define FILE_INPUT "input.txt" 15 | #define FILE_OUTPUT "output.txt" 16 | 17 | int main() 18 | { 19 | ifstream in(FILE_INPUT); 20 | ofstream out(FILE_OUTPUT); 21 | 22 | if(!in || !out) return 1; 23 | 24 | int N, tot = 0, max = 0; 25 | vector H,C; 26 | vector solution; 27 | 28 | in>>N; 29 | H.resize(N+1); 30 | C.resize(N+1); 31 | solution.resize(N+1); 32 | 33 | H[0]=2000; 34 | C[0]=0; 35 | solution[0]=0; 36 | 37 | for(int i = 1; i <= N; i++) { 38 | in>>H[i]>>C[i]; 39 | tot += C[i]; 40 | for(int j = i-1; j >= 0; j--) { 41 | if(H[i] < H[j] && solution[i] < solution[j] + C[i]) solution[i] = solution[j] + C[i]; 42 | } 43 | if(max < solution[i]) max = solution[i]; 44 | } 45 | 46 | out< 10 | 11 | using namespace std; 12 | 13 | #define FILE_INPUT "input.txt" 14 | #define FILE_OUTPUT "output.txt" 15 | 16 | struct last { 17 | int val,len; 18 | bool sign; 19 | bool undef; 20 | }; 21 | 22 | int main() 23 | { 24 | ifstream in(FILE_INPUT); 25 | ofstream out(FILE_OUTPUT); 26 | 27 | if(!in || !out) return 1; 28 | int N, read; 29 | last solution; 30 | in>>N; 31 | 32 | in>>solution.val; 33 | solution.undef = true; 34 | solution.len = 1; 35 | 36 | for(int i = 1; i < N; i++) { 37 | in>>read; 38 | if(solution.val != read) { 39 | bool sign = (solution.val - read > 0); 40 | if(solution.sign != sign || solution.undef) { 41 | solution.sign = sign; 42 | solution.undef = false; 43 | solution.len++; 44 | } 45 | } 46 | solution.val = read; 47 | } 48 | out< 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | int N, r; 18 | int mid, sum; 19 | vector houses; 20 | 21 | cin >> N; 22 | for(int i = 0; i < N; i++) { 23 | cin >> r; 24 | 25 | houses.clear(); 26 | houses.resize(r); 27 | for(int j = 0; j < r; j++) { 28 | cin >> houses[j]; 29 | } 30 | 31 | sum = 0; 32 | mid = r/2; 33 | nth_element(houses.begin(), houses.begin()+mid, houses.end()); 34 | for(int k = 0; k < mid; k++) { 35 | if(houses[k] == houses[mid]) continue; 36 | sum += houses[mid]-houses[k]; 37 | } 38 | for(int k = mid+1; k < houses.size(); k++) { 39 | if(houses[k] == houses[mid]) continue; 40 | sum += houses[k]-houses[mid]; 41 | } 42 | 43 | cout << sum << endl; 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /UVA/100141/Vito’s family (10041).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/100141/Vito’s family (10041).pdf -------------------------------------------------------------------------------- /UVA/10017/The Never Ending Towers of Hanoi (10017).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10017/The Never Ending Towers of Hanoi (10017).pdf -------------------------------------------------------------------------------- /UVA/10038/10038.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | using namespace std; 18 | 19 | int main() { 20 | ios_base::sync_with_stdio(false); // faster I/O 21 | 22 | while(true) { 23 | int N; 24 | if (!(cin >> N)) break; 25 | 26 | unordered_set S; 27 | int prev; 28 | cin >> prev; 29 | for (int i = 1; i < N; i++) { 30 | int num; 31 | cin >> num; 32 | S.insert(abs(num - prev)); 33 | prev = num; 34 | } 35 | if (N == 1 || (S.size() == N - 1 && S.find(1) != S.end() && S.find(N - 1) != S.end())) cout << "Jolly" << endl; 36 | else cout << "Not jolly" << endl; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /UVA/10038/Jolly Jumpers (10038).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10038/Jolly Jumpers (10038).pdf -------------------------------------------------------------------------------- /UVA/10102/The path in the colored field (10102).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10102/The path in the colored field (10102).pdf -------------------------------------------------------------------------------- /UVA/10114/Loansome Car Buyer (10114).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10114/Loansome Car Buyer (10114).pdf -------------------------------------------------------------------------------- /UVA/10130/SuperSale (10130).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10130/SuperSale (10130).pdf -------------------------------------------------------------------------------- /UVA/10141/10141.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | 18 | int cases = 0; 19 | string req, name, maxName; 20 | double price, maxPrice; 21 | int N, P, R, maxScore; 22 | 23 | while (true) { 24 | maxScore = 0; 25 | maxPrice = 0; 26 | 27 | cin >> N >> P; 28 | if (N == 0 && P == 0) break; 29 | 30 | cin.ignore(); 31 | for (int i = 0; i < N; i++) getline(cin, req); 32 | 33 | for (int i = 0; i < P; i++) { 34 | getline(cin, name); 35 | cin >> price >> R; 36 | 37 | if (R > maxScore || (R == maxScore && price < maxPrice)) { 38 | maxScore = R; 39 | maxPrice = price; 40 | maxName = name; 41 | } 42 | 43 | cin.ignore(); 44 | for (int j = 0; j < R; j++) getline(cin, req); 45 | } 46 | if (cases) cout << endl; 47 | cout << "RFP #" << ++cases << endl; 48 | cout << maxName << endl; 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /UVA/10141/Request for Proposal (10141).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10141/Request for Proposal (10141).pdf -------------------------------------------------------------------------------- /UVA/10189/Minesweeper (10189).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10189/Minesweeper (10189).pdf -------------------------------------------------------------------------------- /UVA/10284/Chessboard in FEN (10284).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10284/Chessboard in FEN (10284).pdf -------------------------------------------------------------------------------- /UVA/10300/10300.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | int N, f; 18 | int space, animals, envgrade, sum; 19 | 20 | cin >> N; 21 | for(int i = 0; i < N; i++) { 22 | sum = 0; 23 | 24 | cin >> f; 25 | for(int j = 0; j < f; j++) { 26 | cin >> space >> animals >> envgrade; 27 | sum += space * envgrade; 28 | } 29 | cout << sum << endl; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /UVA/10300/Ecological Premium (10300).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10300/Ecological Premium (10300).pdf -------------------------------------------------------------------------------- /UVA/10324/10324.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | int main() { 18 | ios_base::sync_with_stdio(false); // faster I/O 19 | 20 | int cases = 0; 21 | int Q, from, to, len, dist; 22 | string str; 23 | vector diff(1000000); 24 | 25 | while (cin >> str) { 26 | len = str.size(); 27 | if (len == 0) break; 28 | diff.reserve(len); 29 | 30 | diff[0] = str[0] == '0' ? -1 : 1; 31 | for (int i = 1, j = 0; i < len; i++, j++) { 32 | diff[i] = diff[j] + (str[i] == '0' ? -1 : 1); 33 | } 34 | 35 | cin >> Q; 36 | 37 | cout << "Case " << ++cases << ":" << endl; 38 | for (int i = 0; i < Q; i++) { 39 | cin >> from >> to; 40 | 41 | if (from > to) swap(from, to); 42 | dist = to - from; 43 | if (str[from] == '0') dist *= -1; 44 | 45 | if (diff[from] + dist == diff[to]) cout << "Yes" << endl; 46 | else cout << "No" << endl; 47 | } 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /UVA/10324/Zeros and Ones (10324).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10324/Zeros and Ones (10324).pdf -------------------------------------------------------------------------------- /UVA/10341/Solve It (10341).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10341/Solve It (10341).pdf -------------------------------------------------------------------------------- /UVA/10424/Love Calculator (10424).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10424/Love Calculator (10424).pdf -------------------------------------------------------------------------------- /UVA/10443/Rock, Scissors, Paper (10443).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10443/Rock, Scissors, Paper (10443).pdf -------------------------------------------------------------------------------- /UVA/10487/Closest Sums (10487).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10487/Closest Sums (10487).pdf -------------------------------------------------------------------------------- /UVA/10550/10550.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int getDist(int from, int to) { 14 | return (40 + from - to) % 40; 15 | } 16 | 17 | int toDegree(int dist) { 18 | return dist*9; 19 | } 20 | 21 | int main() { 22 | ios_base::sync_with_stdio(false); // faster I/O 23 | int pos, c1, c2, c3, count; 24 | 25 | while(true) { 26 | cin >> pos >> c1 >> c2 >> c3; 27 | if(!pos && !c1 && !c2 && !c3) break; 28 | 29 | count = 1080 + toDegree(getDist(pos, c1) + getDist(c2, c1) + getDist(c2, c3)); 30 | 31 | cout << count << endl; 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /UVA/10550/Combination Lock (10550).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10550/Combination Lock (10550).pdf -------------------------------------------------------------------------------- /UVA/10576/Y2K Accounting Bug (10576).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10576/Y2K Accounting Bug (10576).pdf -------------------------------------------------------------------------------- /UVA/1061/Consanguine Calculations (1061).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/1061/Consanguine Calculations (1061).pdf -------------------------------------------------------------------------------- /UVA/10646/10646.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int getValue(string card) { 16 | switch (card[0]) { 17 | case 'A': case 'K': case 'Q': case 'J': case 'T': 18 | return 10; 19 | } 20 | return card[0] - '0'; 21 | } 22 | 23 | int main() { 24 | ios_base::sync_with_stdio(false); // faster I/O 25 | 26 | int T; 27 | string cards[52]; 28 | 29 | cin >> T; 30 | 31 | for (int test = 1; test <= T; test++) { 32 | for (int i = 0; i < 52; i++) { 33 | cin >> cards[i]; 34 | } 35 | 36 | int Y = 0; 37 | int pos = 27; 38 | for (int k = 0; k < 3; k++) { 39 | int val = getValue(cards[pos]); 40 | Y += val; 41 | pos -= 1 + (10 - val); 42 | } 43 | 44 | if (Y <= pos) cout << "Case " << test << ": " << cards[Y] << endl; 45 | else cout << "Case " << test << ": " << cards[Y + 27 - pos - 1] << endl; 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /UVA/10646/What is the Card? (10646).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10646/What is the Card? (10646).pdf -------------------------------------------------------------------------------- /UVA/10706/Number Sequence (10706).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10706/Number Sequence (10706).pdf -------------------------------------------------------------------------------- /UVA/10812/10812.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | 16 | int N, s, d, max, min; 17 | 18 | cin >> N; 19 | while (N-- > 0) { 20 | cin >> s >> d; 21 | if (s < d || s % 2 != d % 2) { 22 | cout << "impossible" << endl; 23 | continue; 24 | } 25 | 26 | // a >= b 27 | // s = a + b -> a = s - b -> s - b = d + b -> 2b = s - d -> b = (s - d) / 2 28 | // d = a - b -> a = d + b -> a = d + b -> a = d + b -> a = (s + d) / 2 29 | 30 | int max = (s + d) / 2; // s + d is always an even number. 31 | int min = s - max; 32 | cout << max << " " << min << endl; 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /UVA/10812/Beat the Spread! (10812).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10812/Beat the Spread! (10812).pdf -------------------------------------------------------------------------------- /UVA/10813/Traditional BINGO (10813).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10813/Traditional BINGO (10813).pdf -------------------------------------------------------------------------------- /UVA/10855/Rotated square (10855).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10855/Rotated square (10855).pdf -------------------------------------------------------------------------------- /UVA/10919/10919.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | int chosen[10000] = {0}; 12 | 13 | int main() { 14 | int K, M, C, R, course; 15 | int i, j; 16 | int test = 0; 17 | 18 | while (1) { 19 | test++; // Works only if there are less than 2^(sizeof(int)*8)-1 tests 20 | int pass = 1; 21 | if (scanf("%d %d", &K, &M) != 2) break; 22 | 23 | for (i = 0; i < K; i++) { 24 | scanf("%d", &course); 25 | chosen[course] = test; 26 | } 27 | for (i = 0; i < M; i++) { 28 | int r = 0; 29 | scanf("%d %d", &C, &R); 30 | 31 | for (j = 0; j < C; j++) { 32 | scanf("%d", &course); 33 | if (chosen[course] == test) r++; 34 | } 35 | if (r < R) pass = 0; 36 | } 37 | if (pass) printf("yes\n"); 38 | else printf("no\n"); 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /UVA/10919/10919.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | 18 | int K, M, C, R, course; 19 | unordered_map chosen; 20 | 21 | while (true) { 22 | bool pass = true; 23 | chosen.clear(); 24 | if (!(cin >> K >> M)) break; 25 | chosen.reserve(K); 26 | 27 | for (int i = 0; i < K; i++) { 28 | cin >> course; 29 | chosen[course] = true; 30 | } 31 | for (int i = 0; i < M; i++) { 32 | int r = 0; 33 | cin >> C >> R; 34 | 35 | for (int j = 0; j < C; j++) { 36 | cin >> course; 37 | if (chosen[course]) r++; 38 | } 39 | if (r < R) pass = false; 40 | } 41 | if (pass) cout << "yes" << endl; 42 | else cout << "no" << endl; 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /UVA/10919/Prerequisites? (10919).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10919/Prerequisites? (10919).pdf -------------------------------------------------------------------------------- /UVA/10920/Spiral Tap (10920).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10920/Spiral Tap (10920).pdf -------------------------------------------------------------------------------- /UVA/10945/Mother bear (10945).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10945/Mother bear (10945).pdf -------------------------------------------------------------------------------- /UVA/10963/10963.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | int N, W, y0, y1; 18 | string s; 19 | 20 | cin >> N; 21 | for(int i = 0; i < N; i++) { 22 | getline(cin, s); 23 | cin >> W; 24 | 25 | int dif = -1, tmp; 26 | for(int i = 0; i < W; i++) { 27 | cin >> y0 >> y1; 28 | if(dif == -2) continue; 29 | tmp = abs(y0 - y1); 30 | if(dif == -1) dif = tmp; 31 | else if(tmp != dif) dif = -2; 32 | } 33 | if(dif == -2) cout << "no" << endl; 34 | else cout << "yes" << endl; 35 | if(i < N-1) cout << endl; 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /UVA/10963/The swallowing Ground (10963).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/10963/The swallowing Ground (10963).pdf -------------------------------------------------------------------------------- /UVA/11044/11044.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); // faster I/O 16 | int t, n, m; 17 | 18 | cin >> t; 19 | for(int i = 0; i < t; i++) { 20 | cin >> n >> m; 21 | cout << int(ceil((n-2)/3.0) * ceil((m-2)/3.0)) << endl; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /UVA/11044/Searching for Nessy (11044).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11044/Searching for Nessy (11044).pdf -------------------------------------------------------------------------------- /UVA/11057/Exact Sum (11057).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11057/Exact Sum (11057).pdf -------------------------------------------------------------------------------- /UVA/11172/11172.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | int N; 16 | long a, b; 17 | 18 | cin >> N; 19 | for(int i = 0; i < N; i++) { 20 | cin >> a >> b; 21 | if(a < b) cout << "<" << endl; 22 | else if(a > b) cout << ">" << endl; 23 | else cout << "=" << endl; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /UVA/11172/Relational Operator (11172).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11172/Relational Operator (11172).pdf -------------------------------------------------------------------------------- /UVA/11221/Magic square palindromes. (11221).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11221/Magic square palindromes. (11221).pdf -------------------------------------------------------------------------------- /UVA/1124/1124.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | char c; 15 | 16 | while(scanf("%c", &c) == 1) { 17 | printf("%c", c); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /UVA/1124/Celebrity joepardy (1124).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/1124/Celebrity joepardy (1124).pdf -------------------------------------------------------------------------------- /UVA/11332/11332.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | string sum(string str) { 16 | string s = ""; 17 | int tmp = 0; 18 | for(int i = 0; i < str.length(); i++) { 19 | tmp += str[i] - '0'; 20 | } 21 | return to_string(tmp); 22 | } 23 | 24 | int main() { 25 | ios_base::sync_with_stdio(false); // faster I/O 26 | string n; 27 | 28 | while(true) { 29 | cin >> n; 30 | if(n.length() == 1 && n[0] == '0') break; 31 | while(n.length() > 1) { 32 | n = sum(n); 33 | } 34 | cout << n << endl; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /UVA/11332/Summing Digits (11332).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11332/Summing Digits (11332).pdf -------------------------------------------------------------------------------- /UVA/11340/11340.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | int main() { 18 | ios_base::sync_with_stdio(false); // faster I/O 19 | 20 | int T; 21 | cin >> T; 22 | 23 | while (T--) { 24 | int K; 25 | cin >> K; 26 | 27 | unordered_map values; 28 | for (int i = 0; i < K; i++) { 29 | char c; 30 | cin >> c; 31 | cin >> values[c]; 32 | } 33 | 34 | int M; 35 | cin >> M; 36 | cin.ignore(); 37 | 38 | int pay = 0; 39 | string line; 40 | while (M--) { 41 | getline(cin, line); 42 | for (char c : line) { 43 | pay += values[c]; 44 | } 45 | } 46 | 47 | cout << setprecision(2) << fixed << pay / 100.0 << "$" << endl; 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /UVA/11340/Newspaper (11340).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11340/Newspaper (11340).pdf -------------------------------------------------------------------------------- /UVA/11364/11364.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); // faster I/O 16 | int t, N, s, min, max; 17 | 18 | cin >> t; 19 | for(int i = 0; i < t; i++) { 20 | min = numeric_limits::max(); 21 | max = 0; 22 | 23 | cin >> N; 24 | for(int j = 0; j < N; j++) { 25 | cin >> s; 26 | if(s > max) max = s; 27 | if(s < min) min = s; 28 | } 29 | cout << (max - min) * 2 << endl; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /UVA/11364/Parking (11364).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11364/Parking (11364).pdf -------------------------------------------------------------------------------- /UVA/11459/Snakes and Ladders (11459).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11459/Snakes and Ladders (11459).pdf -------------------------------------------------------------------------------- /UVA/11498/11498.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | int K, N, M, x, y; 16 | 17 | while(true) { 18 | cin >> K; 19 | if(!K) break; 20 | 21 | cin >> N >> M; 22 | for(int i = 0; i < K; i++) { 23 | cin >> x >> y; 24 | if(x == N || y == M) cout << "divisa" << endl; 25 | else if(x > N && y > M) cout << "NE" << endl; 26 | else if(x > N && y < M) cout << "SE" << endl; 27 | else if(x < N && y < M) cout << "SO" << endl; 28 | else if(x < N && y > M) cout << "NO" << endl; 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /UVA/11498/Division of Nlogonia (11498).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11498/Division of Nlogonia (11498).pdf -------------------------------------------------------------------------------- /UVA/11507/Bender B. Rodríguez Problem (11507).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11507/Bender B. Rodríguez Problem (11507).pdf -------------------------------------------------------------------------------- /UVA/11547/11547.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); // faster I/O 16 | int t, n, num, ans; 17 | 18 | cin >> t; 19 | for(int i = 0; i < t; i++) { 20 | cin >> n; 21 | 22 | num = 315*n + 36962; 23 | ans = abs((num - (num / 100)*100) / 10); 24 | 25 | cout << ans << endl; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /UVA/11547/Automatic Answer (11547).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11547/Automatic Answer (11547).pdf -------------------------------------------------------------------------------- /UVA/11553/11553.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | const int INF = numeric_limits::max(); 17 | 18 | int N; 19 | char COL[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; 20 | int M[9][9]; 21 | 22 | int main() { 23 | ios_base::sync_with_stdio(false); // faster I/O 24 | 25 | int T; 26 | cin >> T; 27 | while (T-- > 0) { 28 | cin >> N; 29 | for (int i = 0; i < N; i++) { 30 | for (int j = 0; j < N; j++) { 31 | cin >> M[i][j]; 32 | } 33 | } 34 | 35 | // when next_permutation return false, it also rearranges the elements 36 | // according to the first permutation. 37 | int min = INF; 38 | do { 39 | int total = 0; 40 | for (int k = 0; k < N; k++) { 41 | total += M[k][COL[k]]; 42 | } 43 | if (total < min) min = total; 44 | } while (next_permutation(COL, COL + N)); 45 | 46 | cout << min << endl; 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /UVA/11553/Grid Game (11553).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11553/Grid Game (11553).pdf -------------------------------------------------------------------------------- /UVA/11559/11559.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | 16 | int N, B, H, W; 17 | while(cin >> N >> B >> H >> W) { 18 | int minc = -1; 19 | for (int i = 0; i < H; i++) { 20 | int price; 21 | cin >> price; 22 | int cost = price * N; 23 | for (int j = 0; j < W; j++) { 24 | int beds; 25 | cin >> beds; 26 | if (cost > B) continue; 27 | if (beds < N) continue; 28 | if (cost < minc || minc == -1) minc = cost; 29 | } 30 | } 31 | if (minc == -1) { 32 | cout << "stay home" << endl; 33 | } else { 34 | cout << minc << endl; 35 | } 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /UVA/11559/Event Planning (11559).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11559/Event Planning (11559).pdf -------------------------------------------------------------------------------- /UVA/11565/11565.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | int main() { 17 | ios_base::sync_with_stdio(false); // faster I/O 18 | 19 | int N; 20 | int a, b, c; 21 | cin >> N; 22 | for (int i = 0; i < N; i++) { 23 | cin >> a >> b >> c; 24 | 25 | // Complete Search with simple pruning. 26 | int range = min(b, (int)ceil(sqrt(c))); 27 | bool stop = false; 28 | for (int x = -range; x <= range; x++) { 29 | for (int y = x + 1; y <= range; y++) { 30 | for (int z = y + 1; z <= range; z++) { 31 | if (x + y + z != a) continue; 32 | if (x * y * z != b) continue; 33 | if (x * x + y * y + z * z != c) continue; 34 | cout << x << " " << y << " " << z << endl; 35 | stop = true; 36 | break; 37 | } 38 | if (stop) break; 39 | } 40 | if (stop) break; 41 | } 42 | if (!stop) { 43 | cout << "No solution." << endl; 44 | } 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /UVA/11565/Simple Equations (11565).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11565/Simple Equations (11565).pdf -------------------------------------------------------------------------------- /UVA/11581/Grid Successors (11581).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11581/Grid Successors (11581).pdf -------------------------------------------------------------------------------- /UVA/11586/Train Tracks (11586).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11586/Train Tracks (11586).pdf -------------------------------------------------------------------------------- /UVA/11661/11661.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | 18 | int L; 19 | string S; 20 | 21 | while (true) { 22 | cin >> L; 23 | if (L == 0) break; 24 | cin >> S; 25 | 26 | int minDist = -1; 27 | int dist = 0; 28 | char last = 0; 29 | for (string::iterator it = S.begin(); it != S.end(); it++) { 30 | dist++; 31 | if (*it == '.') continue; 32 | if (*it == 'Z') { 33 | minDist = 0; 34 | break; 35 | } 36 | if (((last == 'R' && *it == 'D') || (last == 'D' && *it == 'R')) && (dist < minDist || minDist == -1)) { 37 | minDist = dist; 38 | } 39 | last = *it; 40 | dist = 0; 41 | } 42 | 43 | cout << minDist << endl; 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /UVA/11661/Burger Time? (11661).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11661/Burger Time? (11661).pdf -------------------------------------------------------------------------------- /UVA/11679/11679.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | 18 | while(true) { 19 | int B, N; 20 | cin >> B >> N; 21 | if (B == 0 && N == 0) break; 22 | vector R(B+1); 23 | 24 | for (int i = 1; i <= B; i++) { 25 | cin >> R[i]; 26 | } 27 | for (int i = 0; i < N; i++) { 28 | int D, C, V; 29 | cin >> D >> C >> V; 30 | R[C] += V; 31 | R[D] -= V; 32 | } 33 | 34 | bool bailout = false; 35 | for (int i = 1; i <= B; i++) { 36 | if (R[i] < 0) { 37 | bailout = true; 38 | break; 39 | } 40 | } 41 | 42 | if (bailout) cout << 'N' << endl; 43 | else cout << 'S' << endl; 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /UVA/11679/Sub-prime (11679).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11679/Sub-prime (11679).pdf -------------------------------------------------------------------------------- /UVA/11683/11683.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | 16 | int A, C, height, max = 0, last = 0, cut; 17 | 18 | while (true) { 19 | cin >> A; 20 | if (A == 0) break; 21 | cin >> C; 22 | 23 | cut = 0; 24 | last = A; 25 | for (int i = 0; i < C; i++) { 26 | cin >> height; 27 | if (height >= last) { 28 | last = height; 29 | continue; 30 | } 31 | cut += last - height; 32 | last = height; 33 | } 34 | cout << cut << endl; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /UVA/11683/Laser Sculpture (11683).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11683/Laser Sculpture (11683).pdf -------------------------------------------------------------------------------- /UVA/11687/11687.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | 18 | int i; 19 | string str, next; 20 | 21 | while (true) { 22 | i = 0; 23 | getline(cin, str); 24 | if (str[0] == 'E') break; 25 | 26 | while (true) { 27 | i++; 28 | next = to_string(str.size()); 29 | if (next == str) break; 30 | str.swap(next); 31 | } 32 | cout << i << endl; 33 | } 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /UVA/11687/Digits (11687).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11687/Digits (11687).pdf -------------------------------------------------------------------------------- /UVA/11727/11727.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | int T; 18 | vector E(3); 19 | 20 | cin >> T; 21 | for(int i = 1; i <= T; i++) { 22 | cin >> E[0] >> E[1] >> E[2]; 23 | 24 | sort(E.begin(), E.end()); 25 | cout << "Case " << i << ": " << E[1] << endl; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /UVA/11727/Cost Cutting (11727).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11727/Cost Cutting (11727).pdf -------------------------------------------------------------------------------- /UVA/11764/11764.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | 16 | int T, N, h[2]; 17 | cin >> T; 18 | 19 | for (int i = 1; i <= T; i++) { 20 | cin >> N; 21 | 22 | int l = 0, g = 0, k = 0; 23 | for (int j = 0; j < N; j++) { 24 | k = !k; 25 | cin >> h[k]; 26 | 27 | if (j == 0 || h[0] == h[1]) continue; 28 | if (h[k] > h[!k]) g++; 29 | else l++; 30 | } 31 | cout << "Case " << i << ": " << g << " " << l << endl; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /UVA/11764/Jumping Mario (11764).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11764/Jumping Mario (11764).pdf -------------------------------------------------------------------------------- /UVA/11799/11799.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | 16 | int T, N, s; 17 | cin >> T; 18 | 19 | for (int i = 1; i <= T; i++) { 20 | cin >> N; 21 | 22 | int max = 0; 23 | for (int j = 0; j < N; j++) { 24 | cin >> s; 25 | if (s > max) max = s; 26 | } 27 | cout << "Case " << i << ": " << max << endl; 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /UVA/11799/Horror Dash (11799).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11799/Horror Dash (11799).pdf -------------------------------------------------------------------------------- /UVA/11831/Sticker Collector Robot (11831).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11831/Sticker Collector Robot (11831).pdf -------------------------------------------------------------------------------- /UVA/119/Greedy Gift Givers (119).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/119/Greedy Gift Givers (119).pdf -------------------------------------------------------------------------------- /UVA/11906/Knight in a War Grid (11906).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11906/Knight in a War Grid (11906).pdf -------------------------------------------------------------------------------- /UVA/11942/11942.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | //#include 12 | //#include 13 | //#include 14 | //#include 15 | //#include 16 | //#include 17 | //#include 18 | //#include 19 | 20 | //#include 21 | //#include 22 | 23 | using namespace std; 24 | 25 | int main() { 26 | ios_base::sync_with_stdio(false); // faster I/O 27 | 28 | int N, tmp[2]; 29 | cin >> N; 30 | 31 | cout << "Lumberjacks:" << endl; 32 | for (int i = 0; i < N; i++) { 33 | int k = 1; 34 | int state = -1; 35 | bool unordered = false; 36 | 37 | for (int j = 0; j < 10; j++) { 38 | k = !k; 39 | cin >> tmp[k]; 40 | if (j == 0 || tmp[0] == tmp[1]|| unordered) continue; 41 | if (state == -1) { 42 | state = tmp[0] > tmp[1]; 43 | continue; 44 | } 45 | if (tmp[k] > tmp[!k] == state) unordered = true; 46 | } 47 | 48 | if (unordered) cout << "Unordered" << endl; 49 | else cout << "Ordered" << endl; 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /UVA/11942/Lumberjack Sequencing (11942).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11942/Lumberjack Sequencing (11942).pdf -------------------------------------------------------------------------------- /UVA/11946/11946.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int map[] = { 16 | 'O', 17 | 'I', 18 | 'Z', 19 | 'E', 20 | 'A', 21 | 'S', 22 | 'G', 23 | 'T', 24 | 'B', 25 | 'P' 26 | }; 27 | 28 | char decode(char c) { 29 | int idx = c - '0'; 30 | if (idx < 0 || idx > 9) return c; 31 | return map[idx]; 32 | } 33 | 34 | int main() { 35 | ios_base::sync_with_stdio(false); // faster I/O 36 | 37 | int T; 38 | string line; 39 | 40 | cin >> T; 41 | cin.ignore(); 42 | 43 | while (T-- > 0) { 44 | while (true) { 45 | getline(cin, line); 46 | if (line.size() == 0) break; 47 | for (int i = 0; i < line.size(); i++) { 48 | cout << decode(line[i]); 49 | } 50 | cout << endl; 51 | } 52 | if (T == 1) cout << endl; 53 | } 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /UVA/11946/Code Number (11946).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11946/Code Number (11946).pdf -------------------------------------------------------------------------------- /UVA/11953/Battleships (11953).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11953/Battleships (11953).pdf -------------------------------------------------------------------------------- /UVA/11956/Brainfuck (11956).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/11956/Brainfuck (11956).pdf -------------------------------------------------------------------------------- /UVA/12015/12015.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | int main() { 17 | ios_base::sync_with_stdio(false); // faster I/O 18 | 19 | string url; 20 | vector rel; 21 | int T, rank; 22 | cin >> T; 23 | 24 | for (int i = 1; i <= T; i++) { 25 | int max = 0; 26 | rel.clear(); 27 | rel.reserve(10); 28 | for (int j = 0; j < 10; j++) { 29 | cin >> url >> rank; 30 | if (max > rank) continue; 31 | if (max < rank) { 32 | max = rank; 33 | rel.clear(); 34 | rel.reserve(10); 35 | } 36 | rel.push_back(url); 37 | } 38 | 39 | cout << "Case #" << i << ":" << endl; 40 | for (vector::iterator it = rel.begin(); it != rel.end(); it++) { 41 | cout << *it << endl; 42 | } 43 | } 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /UVA/12015/Google is Feeling Lucky (12015).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12015/Google is Feeling Lucky (12015).pdf -------------------------------------------------------------------------------- /UVA/12157/12157.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); // faster I/O 16 | 17 | const int MILE_COST = 10, MILE_FRAME = 30; 18 | const int JUICE_COST = 15, JUICE_FRAME = 60; 19 | 20 | int T, N, d; 21 | cin >> T; 22 | 23 | for (int i = 1; i <= T; i++) { 24 | int mile = 0, juice = 0; 25 | cin >> N; 26 | for (int j = 0; j < N; j++) { 27 | cin >> d; 28 | mile += MILE_COST + (d / MILE_FRAME) * MILE_COST; 29 | juice += JUICE_COST + (d / JUICE_FRAME) * JUICE_COST; 30 | } 31 | if (mile < juice) cout << "Case " << i << ": Mile " << mile << endl; 32 | else if(mile > juice) cout << "Case " << i << ": Juice " << juice << endl; 33 | else cout << "Case " << i << ": Mile Juice " << mile << endl; 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /UVA/12157/Tariff Plan (12157).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12157/Tariff Plan (12157).pdf -------------------------------------------------------------------------------- /UVA/12247/Jollo (12247).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12247/Jollo (12247).pdf -------------------------------------------------------------------------------- /UVA/12250/12250.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | int count = 1; 18 | string str; 19 | map::iterator lng; 20 | map dict = { 21 | {"HELLO", "ENGLISH"}, 22 | {"HOLA", "SPANISH"}, 23 | {"HALLO", "GERMAN"}, 24 | {"BONJOUR", "FRENCH"}, 25 | {"CIAO", "ITALIAN"}, 26 | {"ZDRAVSTVUJTE", "RUSSIAN"} 27 | }; 28 | 29 | while(true) { 30 | cin >> str; 31 | 32 | if(str[0] == '#' && str.length() == 1) break; 33 | lng = dict.find(str); 34 | if(lng != dict.end()) { 35 | cout << "Case " << count << ": " << lng->second << endl; 36 | } 37 | else { 38 | cout << "Case " << count << ": " << "UNKNOWN" << endl; 39 | } 40 | count++; 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /UVA/12250/Language Detection (12250).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12250/Language Detection (12250).pdf -------------------------------------------------------------------------------- /UVA/12279/12279.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | int N, e, balance, count = 1; 16 | 17 | while(true) { 18 | cin >> N; 19 | if(!N) break; 20 | 21 | balance = 0; 22 | for(int i = 0; i < N; i++) { 23 | cin >> e; 24 | if(!e) balance--; 25 | else if(e >= 1 && e <= 99) balance++; 26 | } 27 | 28 | cout << "Case " << count << ": " << balance << endl; 29 | count++; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /UVA/12279/Emoogle Balance (12279).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12279/Emoogle Balance (12279).pdf -------------------------------------------------------------------------------- /UVA/12289/12289.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); // faster I/O 16 | int N, count; 17 | string num; 18 | char one[] = {'o', 'n', 'e'}; 19 | 20 | cin >> N; 21 | 22 | for(int i = 0; i < N; i++) { 23 | cin >> num; 24 | if(num.length() == 5) { 25 | cout << 3 << endl; 26 | } 27 | else { 28 | count = 0; 29 | for(int j = 0; j < 3; j++) { 30 | if(num[j] == one[j]) count++; 31 | } 32 | if(count >= 2) cout << 1 << endl; 33 | else cout << 2 << endl; 34 | } 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /UVA/12289/One-Two-Three (12289).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12289/One-Two-Three (12289).pdf -------------------------------------------------------------------------------- /UVA/12356/Army Buddies (12356).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12356/Army Buddies (12356).pdf -------------------------------------------------------------------------------- /UVA/12372/12372.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | int T, L, W, H; 16 | 17 | cin >> T; 18 | 19 | for(int i = 1; i <= T; i++) { 20 | cin >> L >> W >> H; 21 | if(L > 20 || W > 20 || H > 20) cout << "Case " << i << ": bad" << endl; 22 | else cout << "Case " << i << ": good" << endl; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /UVA/12372/Packing for Holiday (12372).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12372/Packing for Holiday (12372).pdf -------------------------------------------------------------------------------- /UVA/12403/12403.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); // faster I/O 16 | int T; 17 | int balance = 0, k; 18 | string str; 19 | 20 | cin >> T; 21 | 22 | for(int i = 1; i <= T; i++) { 23 | cin >> str; 24 | if(str[0] == 'd') { 25 | cin >> k; 26 | balance += k; 27 | } 28 | else cout << balance << endl; 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /UVA/12403/Save Setu (12403).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12403/Save Setu (12403).pdf -------------------------------------------------------------------------------- /UVA/12442/Forwarding Emails (12442).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12442/Forwarding Emails (12442).pdf -------------------------------------------------------------------------------- /UVA/12467/Secret Word (12467).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12467/Secret Word (12467).pdf -------------------------------------------------------------------------------- /UVA/12468/12468.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int roundMinDistance(int from, int to, int cycle) { 15 | if (from > to) { 16 | return min(from-to, (cycle-from)+to); 17 | } 18 | return min(to-from, (cycle-to)+from); 19 | } 20 | 21 | int main() { 22 | ios_base::sync_with_stdio(false); // faster I/O 23 | 24 | int a, b; 25 | 26 | while(true) { 27 | cin >> a >> b; 28 | if (a == -1 && b == -1) break; 29 | cout << roundMinDistance(a, b, 100) << endl; 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /UVA/12468/Zapping (12468).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12468/Zapping (12468).pdf -------------------------------------------------------------------------------- /UVA/12478/12478.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | ios_base::sync_with_stdio(false); // faster I/O 15 | 16 | cout << "KABIR" << endl; 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /UVA/12478/Hardest Problem Ever (12478).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12478/Hardest Problem Ever (12478).pdf -------------------------------------------------------------------------------- /UVA/12503/12503.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | int main() { 17 | ios_base::sync_with_stdio(false); // faster I/O 18 | 19 | string cmd; 20 | vector list; 21 | int T, N, move; 22 | 23 | cin >> T; 24 | 25 | for (int i = 0; i < T; i++) { 26 | int pos = 0; 27 | cin >> N; 28 | list.clear(); 29 | list.reserve(N); 30 | 31 | cin.ignore(); 32 | for (int j = 0; j < N; j++) { 33 | getline(cin, cmd); 34 | 35 | switch (cmd[0]) { 36 | case 'L': move = -1; 37 | break; 38 | case 'R': move = 1; 39 | break; 40 | default: move = list[stoi(cmd.substr(8))-1]; 41 | } 42 | list.push_back(move); 43 | pos += move; 44 | } 45 | cout << pos << endl; 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /UVA/12503/Robot Instructions (12503).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12503/Robot Instructions (12503).pdf -------------------------------------------------------------------------------- /UVA/12554/12554.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | int main() { 17 | ios_base::sync_with_stdio(false); // faster I/O 18 | 19 | const string song[] = { "Happy", "birthday", "to", "you", "Happy", "birthday", "to", "you", "Happy", "birthday", "to", "Rujia", "Happy", "birthday", "to", "you" }; 20 | const int len = sizeof(song) / sizeof(song[0]); 21 | 22 | int N, idx = 0; 23 | string name; 24 | cin >> N; 25 | 26 | vector peoples; 27 | peoples.reserve(N); 28 | 29 | int carry = len % N; 30 | 31 | for (int i = 0; i < N; i++) { 32 | cin >> name; 33 | if (i < carry) { 34 | peoples.push_back(name); 35 | } 36 | cout << name << ": " << song[idx] << endl; 37 | idx = (idx + 1) % len; 38 | } 39 | int p = 0; 40 | while (idx != len) { 41 | cout << peoples[p] << ": " << song[idx] << endl; 42 | p = (p + 1) % peoples.size(); 43 | idx++; 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /UVA/12554/A Special "Happy Birthday" Song!!! (12554).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12554/A Special "Happy Birthday" Song!!! (12554).pdf -------------------------------------------------------------------------------- /UVA/12577/12577.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); // faster I/O 16 | int count = 1; 17 | string line; 18 | 19 | while(true) { 20 | cin >> line; 21 | if(line[0] == '*' && line.length() == 1) break; 22 | if(line[0] == 'H') cout << "Case " << count << ": Hajj-e-Akbar" << endl; 23 | else cout << "Case " << count << ": Hajj-e-Asghar" << endl; 24 | count++; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /UVA/12577/Hajj-e-Akbar (12577).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12577/Hajj-e-Akbar (12577).pdf -------------------------------------------------------------------------------- /UVA/12694/12694.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | typedef pair pii; 17 | 18 | int main() { 19 | ios_base::sync_with_stdio(false); // faster I/O 20 | 21 | int T, a, b; 22 | vector intervals; 23 | cin >> T; 24 | 25 | while (T-- > 0) { 26 | intervals.clear(); 27 | intervals.reserve(20); 28 | while (true) { 29 | cin >> a >> b; 30 | if (a == 0 && b == 0) break; 31 | if (a < 0 || b > 10 || a > b) continue; 32 | // We swap them to use the natural order of pairs. 33 | intervals.push_back(make_pair(b, a)); 34 | } 35 | 36 | // Order by end increasing 37 | sort(intervals.begin(), intervals.end()); 38 | 39 | int count = 0; 40 | int hour = 0; 41 | for(int i = 0; i < intervals.size(); i++) { 42 | if(hour > intervals[i].second) continue; 43 | hour = intervals[i].first; 44 | count++; 45 | } 46 | cout << count << endl; 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /UVA/12694/Meeting Room Arrangement (12694).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12694/Meeting Room Arrangement (12694).pdf -------------------------------------------------------------------------------- /UVA/12696/12696.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | bool isValid(double length, double width, double depth, double weight) { 14 | bool valid = false; 15 | valid |= (length > 0 && width > 0 && depth > 0 && 16 | length <= 56 && width <= 45 && depth <= 25); 17 | valid |= (length + width + depth <= 125); 18 | valid &= (weight <= 7); 19 | return valid; 20 | } 21 | 22 | int main() { 23 | ios_base::sync_with_stdio(false); // faster I/O 24 | int N; 25 | 26 | cin >> N; 27 | 28 | int count = 0; 29 | double x, y, z, w; 30 | for (int i = 0; i < N; i++) { 31 | cin >> x >> y >> z >> w; 32 | bool valid = isValid(x, y, z, w); 33 | count += valid; 34 | cout << valid << endl; 35 | } 36 | cout << count << endl; 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /UVA/12696/Cabin Baggage (12696).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12696/Cabin Baggage (12696).pdf -------------------------------------------------------------------------------- /UVA/12854/12854.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | 18 | while (true) { 19 | bitset<5> p[2]; 20 | for (int i = 0; i < 2; i++) { 21 | for (int j = 0; j < 5; j++) { 22 | bool c; 23 | cin >> c; 24 | if (!cin) break; 25 | p[i].set(j, c); 26 | } 27 | if (!cin) break; 28 | } 29 | if (!cin) break; 30 | 31 | if ((p[0] ^ p[1]).count() == 5) { 32 | cout << "Y" << endl; 33 | } else { 34 | cout << "N" << endl; 35 | } 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /UVA/12854/Automated Checking Machine (12854).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12854/Automated Checking Machine (12854).pdf -------------------------------------------------------------------------------- /UVA/12861/12861.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | int lag(int a, int b) { 17 | int diff = abs(a - b); 18 | return min(diff, 24 - diff); 19 | } 20 | 21 | int main() { 22 | ios_base::sync_with_stdio(false); // faster I/O 23 | 24 | int N; 25 | vector peoples; 26 | 27 | while (true) { 28 | cin >> N; 29 | if (!cin) break; 30 | peoples.resize(N); 31 | 32 | for (int i = 0; i < N; i++) { 33 | cin >> peoples[i]; 34 | } 35 | sort(peoples.begin(), peoples.end()); 36 | 37 | int sol1 = 0; 38 | for (int i = 0; i < peoples.size() - 1; i += 2) { 39 | sol1 += lag(peoples[i], peoples[i + 1]); 40 | } 41 | int sol2 = lag(peoples[peoples.size() - 1], peoples[0]); 42 | for (int i = 1; i < peoples.size() - 1; i += 2) { 43 | sol2 += lag(peoples[i], peoples[i + 1]); 44 | } 45 | 46 | cout << min(sol1, sol2) << endl; 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /UVA/12861/Help cupid (12861).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12861/Help cupid (12861).pdf -------------------------------------------------------------------------------- /UVA/12862/Intrepid climber (12862).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/12862/Intrepid climber (12862).pdf -------------------------------------------------------------------------------- /UVA/130/Roman Roulette (130).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/130/Roman Roulette (130).pdf -------------------------------------------------------------------------------- /UVA/156/156.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | int main() { 18 | ios_base::sync_with_stdio(false); // faster I/O 19 | 20 | string word; 21 | map> dict; 22 | map out; 23 | while (true) { 24 | cin >> word; 25 | if (word.size() == 1 && word[0] == '#') break; 26 | 27 | string sword = word; 28 | transform(sword.begin(), sword.end(), sword.begin(), ::toupper); 29 | sort(sword.begin(), sword.end()); 30 | dict[sword].first = word; 31 | dict[sword].second++; 32 | } 33 | 34 | for (map>::iterator it = dict.begin(); it != dict.end(); it++) { 35 | if (it->second.second == 1) { 36 | out[it->second.first] = true; 37 | } 38 | } 39 | for (map::iterator it = out.begin(); it != out.end(); it++) { 40 | cout << it->first << endl; 41 | } 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /UVA/156/Ananagrams (156).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/156/Ananagrams (156).pdf -------------------------------------------------------------------------------- /UVA/161/Traffic Lights (161).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/161/Traffic Lights (161).pdf -------------------------------------------------------------------------------- /UVA/183/Bit Maps (183).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/183/Bit Maps (183).pdf -------------------------------------------------------------------------------- /UVA/193/Graph Coloring (193).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/193/Graph Coloring (193).pdf -------------------------------------------------------------------------------- /UVA/195/Anagram (195).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/195/Anagram (195).pdf -------------------------------------------------------------------------------- /UVA/272/272.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() { 14 | char c; 15 | bool state = 0; 16 | 17 | while(scanf("%c", &c) == 1) { 18 | if(c == '"') { 19 | if(state) printf("''"); 20 | else printf("``"); 21 | state = !state; 22 | } 23 | else printf("%c", c); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /UVA/272/TEX Quotes (272).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/272/TEX Quotes (272).pdf -------------------------------------------------------------------------------- /UVA/278/Chess (278).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/278/Chess (278).pdf -------------------------------------------------------------------------------- /UVA/401/Palindromes (401).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/401/Palindromes (401).pdf -------------------------------------------------------------------------------- /UVA/454/Anagrams (454).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/454/Anagrams (454).pdf -------------------------------------------------------------------------------- /UVA/462/Bridge Hand Evaluator (462).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/462/Bridge Hand Evaluator (462).pdf -------------------------------------------------------------------------------- /UVA/489/Hangman Judge (489).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/489/Hangman Judge (489).pdf -------------------------------------------------------------------------------- /UVA/573/573.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | 18 | int H, U, D, F; 19 | while(true) { 20 | cin >> H >> U >> D >> F; 21 | if (H == 0) break; 22 | 23 | 24 | int day = 0; 25 | double heigth = 0; 26 | double L = (U * F / 100.0); 27 | while (true) { 28 | heigth += max(U - day * L, 0.0); 29 | if (heigth > H) { 30 | cout << "success on day " << day+1 << endl; 31 | break; 32 | } 33 | heigth -= D; 34 | if (heigth < 0) { 35 | cout << "failure on day " << day+1 << endl; 36 | break; 37 | } 38 | day++; 39 | } 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /UVA/573/The Snail (573).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/573/The Snail (573).pdf -------------------------------------------------------------------------------- /UVA/574/Sum It Up (574).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/574/Sum It Up (574).pdf -------------------------------------------------------------------------------- /UVA/579/579.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | int main() { 18 | ios_base::sync_with_stdio(false); // faster I/O 19 | 20 | string line; 21 | 22 | // Print always 3 decimal places. 23 | cout << setprecision(3) << fixed; 24 | 25 | while (true) { 26 | cin >> line; 27 | double m, h; 28 | if (line.size() == 5) { 29 | h = (line[0] - '0') * 10 + line[1] - '0'; 30 | m = (line[3] - '0') * 10 + line[4] - '0'; 31 | } else { 32 | h = line[0] - '0'; 33 | m = (line[2] - '0') * 10 + line[3] - '0'; 34 | } 35 | if (m == 0 && h == 0) break; 36 | if (m > 0) { 37 | h += m / 60.0; 38 | if (h > 12) h -= 12; 39 | } 40 | 41 | // 360 : 12 = ah : h 42 | double a1 = 360.0 * h / 12; 43 | 44 | // 360 : 60 = am : m 45 | double a2 = 360.0 * m / 60; 46 | 47 | double diff = abs(a1 - a2); 48 | if (diff > 180) diff = 360.0 - diff; 49 | 50 | cout << diff << endl; 51 | } 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /UVA/579/Clock Hands (579).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/579/Clock Hands (579).pdf -------------------------------------------------------------------------------- /UVA/584/Bowling (584).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/584/Bowling (584).pdf -------------------------------------------------------------------------------- /UVA/608/Counterfeit Dollar (608).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/608/Counterfeit Dollar (608).pdf -------------------------------------------------------------------------------- /UVA/621/621.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | using namespace std; 14 | 15 | int main() { 16 | ios_base::sync_with_stdio(false); // faster I/O 17 | int N, len; 18 | string S; 19 | 20 | cin >> N; 21 | for(int i = 0; i < N; i++) { 22 | cin >> S; 23 | len = S.length(); 24 | 25 | if((len == 1 && (S[0] == '1' || S[0] == '4')) || (len == 2 && S[0] == '7' && S[1] == '8')) { 26 | cout << '+' << endl; 27 | } 28 | else if((len >= 2 && S[len-2] == '3' && S[len-1] == '5')) { 29 | cout << '-' << endl; 30 | } 31 | else if((len >= 2 && S[0] == '9' && S[len-1] == '4')) { 32 | cout << '*' << endl; 33 | } 34 | else if((len >= 3 && S[0] == '1' && S[1] == '9' && S[2] == '0')) { 35 | cout << '?' << endl; 36 | } 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /UVA/621/Secret Research (621).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/621/Secret Research (621).pdf -------------------------------------------------------------------------------- /UVA/637/Booklet Printing (637).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/637/Booklet Printing (637).pdf -------------------------------------------------------------------------------- /UVA/661/Blowing Fuses (661).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/661/Blowing Fuses (661).pdf -------------------------------------------------------------------------------- /UVA/696/696.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std; 16 | 17 | int main() { 18 | ios_base::sync_with_stdio(false); // faster I/O 19 | 20 | int R, C, m, M; 21 | while (true) { 22 | cin >> R >> C; 23 | if (R == 0 && C == 0) break; 24 | 25 | m = R, M = C; 26 | if (m > M) swap(m, M); 27 | 28 | // See UVa 278 for explaination. 29 | switch (m) { 30 | case 1: { 31 | cout << M << " knights may be placed on a " << R << " row " << C << " column board." << endl; 32 | break; 33 | } 34 | case 2: { 35 | int r = M % 4; 36 | if (r == 3) r = 1; 37 | cout << M + r << " knights may be placed on a " << R << " row " << C << " column board." << endl; 38 | break; 39 | } 40 | default: { 41 | cout << ceil(R * C / 2.0) << " knights may be placed on a " << R << " row " << C << " column board." << endl; 42 | } 43 | } 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /UVA/696/How Many Knights (696).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/696/How Many Knights (696).pdf -------------------------------------------------------------------------------- /UVA/846/846.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(false); // faster I/O 16 | int N, x, y, steps, diff, n, s, r, c; 17 | 18 | cin >> N; 19 | for(int i = 0; i < N; i++) { 20 | cin >> x >> y; 21 | steps = 0; 22 | diff = y - x; 23 | n = floor((sqrt(1+4*diff)-1)/2); 24 | s = n*(n+1); 25 | r = (diff - s); 26 | 27 | c = (r > 0) ? ((r <= n+1) ? 1 : 2) : (0); 28 | steps = 2*n + c; 29 | 30 | //cout << "diff: " << diff << endl; 31 | //cout << " sumn: " << n << endl; 32 | //cout << " sum: " << s << endl; 33 | //cout << "remain: " << r << endl; 34 | //cout << " additional: " << c << endl; 35 | //cout << "steps:" << steps << endl; 36 | 37 | cout << steps << endl; 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /UVA/846/Steps (846).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/846/Steps (846).pdf -------------------------------------------------------------------------------- /UVA/872/Ordering (872).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/872/Ordering (872).pdf -------------------------------------------------------------------------------- /UVA/927/927.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | int main() { 17 | ios_base::sync_with_stdio(false); // faster I/O 18 | 19 | int C; 20 | double K, D; 21 | int degree; 22 | int coeff[21]; 23 | 24 | cin >> C; 25 | 26 | while (C-- > 0) { 27 | cin >> degree; 28 | for (int i = 0; i <= degree; i++) { 29 | cin >> coeff[i]; 30 | } 31 | 32 | cin >> D; 33 | cin >> K; 34 | 35 | // D is a common factor. 36 | K /= D; 37 | // Now K is the sum of n elements (Gauss sum) 38 | // K = n * (n + 1) / 2 39 | // n = 1/2 (sqrt(1 + 8 * K) - 1) 40 | int n = ceil(0.5 * (sqrt(1 + 8 * K) - 1)); 41 | 42 | // Compute an as explained in the problem. 43 | double an = 0.0; 44 | for (int j = 0; j <= degree; j++) { 45 | an += coeff[j] * pow(n, j); 46 | } 47 | 48 | cout << fixed << setprecision(0) << an << endl; 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /UVA/927/Integer Sequences from Addition of Terms (927).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/927/Integer Sequences from Addition of Terms (927).pdf -------------------------------------------------------------------------------- /UVA/948/Fibonaccimal Base (948).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simonepri/competitive-programming/839e1dc862bdf70ec5658f4b7b123654a9e7390e/UVA/948/Fibonaccimal Base (948).pdf -------------------------------------------------------------------------------- /UVA/shelton.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | int main() { 12 | 13 | //scanf(in,"%d", &N); 14 | //printf(out,"%d", N); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /UVA/shelton.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Competitive Programming - Collection of solved problems. 3 | * 4 | * @author Simone Primarosa,(http://simoneprimarosa.com) 5 | * @link (https://github.com/simonepri/competitive-programming) 6 | * @license MIT License (https://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #include 10 | 11 | //#include 12 | //#include 13 | //#include 14 | //#include 15 | //#include 16 | //#include 17 | //#include 18 | //#include 19 | 20 | //#include 21 | //#include 22 | 23 | using namespace std; 24 | 25 | int main() { 26 | ios_base::sync_with_stdio(false); // faster I/O 27 | 28 | //in >> N; 29 | //out << N; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /pre-commit.bat: -------------------------------------------------------------------------------- 1 | del ./ *.txt -------------------------------------------------------------------------------- /pre-commit.command: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd "$(dirname $0)" 4 | find . -name "*.txt" -type f -delete -------------------------------------------------------------------------------- /pre-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd "$(dirname $0)" 4 | find . -name "*.txt" -type f -delete --------------------------------------------------------------------------------