├── BeginningAlgorithmContests ├── bookcodes │ ├── ch1-4 │ │ ├── 1-1.c │ │ ├── 1-10.c │ │ ├── 1-11.c │ │ ├── 1-12.c │ │ ├── 1-13.c │ │ ├── 1-14.c │ │ ├── 1-15.c │ │ ├── 1-2.c │ │ ├── 1-3.c │ │ ├── 1-4.c │ │ ├── 1-5.c │ │ ├── 1-6.c │ │ ├── 1-7.c │ │ ├── 1-8.c │ │ ├── 1-9.c │ │ ├── 2-1.c │ │ ├── 2-2.c │ │ ├── 2-3.c │ │ ├── 2-4.c │ │ ├── 2-5.c │ │ ├── 2-6.c │ │ ├── 2-7.c │ │ ├── 2-8.c │ │ ├── 2-9.c │ │ ├── 3-1.c │ │ ├── 3-2.c │ │ ├── 3-3.c │ │ ├── 3-4.c │ │ ├── 3-5.c │ │ ├── 3-6.c │ │ ├── 4-1.c │ │ ├── 4-2.c │ │ ├── 4-3.c │ │ ├── 4-4.c │ │ ├── 4-5.c │ │ └── 4-6.c │ ├── ch11 │ │ ├── bellman.cpp │ │ ├── dijkstra.cpp │ │ ├── dijkstraheap.cpp │ │ ├── gen1.cpp │ │ ├── gen2.cpp │ │ ├── maxflow.cpp │ │ ├── maxflow2.cpp │ │ ├── mincostflow.cpp │ │ ├── readme.txt │ │ ├── test_maxflow.bat │ │ └── test_sssp.bat │ ├── ch5 │ │ ├── 10035.cpp │ │ ├── 10035_uva.cpp │ │ ├── 10082.cpp │ │ ├── 143.cpp │ │ ├── 143_uva.cpp │ │ ├── 160.cpp │ │ ├── 160_uva.cpp │ │ ├── 263.cpp │ │ ├── 263_uva.cpp │ │ ├── 264.cpp │ │ ├── 264_uva.cpp │ │ ├── 264b.cpp │ │ ├── 264b_uva.cpp │ │ ├── 272.cpp │ │ ├── 455.cpp │ │ ├── 455_uva.cpp │ │ ├── 623.cpp │ │ ├── 623_uva.cpp │ │ ├── 642.cpp │ │ ├── 642_uva.cpp │ │ ├── bign.cpp │ │ ├── land.cpp │ │ └── readme.txt │ ├── ch6 │ │ ├── 10935.cpp │ │ ├── 10935_uva.cpp │ │ ├── 10935b.cpp │ │ ├── 122.cpp │ │ ├── 122_uva.cpp │ │ ├── 122b.cpp │ │ ├── 122b_uva.cpp │ │ ├── 514.cpp │ │ ├── 514_uva.cpp │ │ ├── 514b.cpp │ │ ├── 536.cpp │ │ ├── 679.cpp │ │ ├── 679_uva.cpp │ │ ├── 679b.cpp │ │ ├── bw.cpp │ │ ├── euler.cpp │ │ ├── euler.in │ │ ├── list1.cpp │ │ ├── list2.cpp │ │ ├── listgen.cpp │ │ ├── maze.cpp │ │ ├── maze.in │ │ ├── readme.txt │ │ ├── topo.cpp │ │ └── topo.in │ ├── ch7 │ │ ├── 129.cpp │ │ ├── 129_uva.cpp │ │ ├── 524.cpp │ │ ├── 524_uva.cpp │ │ ├── 524b.cpp │ │ ├── 8.cpp │ │ ├── 8a.in │ │ ├── 8b.cpp │ │ ├── 8b.in │ │ ├── 8c.cpp │ │ ├── 8d.cpp │ │ ├── pp.cpp │ │ ├── pp2.cpp │ │ ├── pp3.cpp │ │ ├── queen.c │ │ ├── queen2.c │ │ ├── queen3.c │ │ ├── readme.txt │ │ ├── subset.cpp │ │ ├── subset2.cpp │ │ ├── subset3.cpp │ │ └── water.cpp │ ├── ch8 │ │ ├── bsearch.c │ │ ├── bsearch2.c │ │ ├── inverse_pair.c │ │ ├── lbub.c │ │ ├── loan.c │ │ ├── merge_sort.c │ │ ├── range.cpp │ │ ├── readme.txt │ │ ├── seq.c │ │ └── seq.cpp │ ├── ch9 │ │ ├── box.cpp │ │ ├── box2.cpp │ │ ├── coin.cpp │ │ ├── coin2.cpp │ │ ├── knapsack.cpp │ │ └── readme.txt │ └── readme.txt ├── common_lisp │ ├── ch1 │ │ ├── ex1-1.lisp │ │ ├── ex1-10.lisp │ │ ├── ex1-2.lisp │ │ ├── ex1-3.lisp │ │ ├── ex1-4.lisp │ │ ├── ex1-5.lisp │ │ ├── ex1-6.lisp │ │ ├── ex1-7.lisp │ │ ├── ex1-8.lisp │ │ ├── ex1-9.lisp │ │ ├── p1-1.lisp │ │ ├── p1-2.lisp │ │ ├── p1-3.lisp │ │ ├── p1-4.lisp │ │ └── p1-5.lisp │ └── readme.txt ├── exercises │ ├── ch1 │ │ ├── ex1-1.c │ │ ├── ex1-10.c │ │ ├── ex1-2.c │ │ ├── ex1-3.c │ │ ├── ex1-4.c │ │ ├── ex1-5.c │ │ ├── ex1-6.c │ │ ├── ex1-7.c │ │ ├── ex1-8.c │ │ ├── ex1-9.c │ │ └── readme.txt │ ├── ch10 │ │ ├── UVa10006.cpp │ │ ├── UVa10079.cpp │ │ ├── UVa10105.cpp │ │ ├── UVa10157.cpp │ │ ├── UVa10183.cpp │ │ ├── UVa10219.cpp │ │ ├── UVa10277.cpp │ │ ├── UVa10303.cpp │ │ ├── UVa10334.cpp │ │ ├── UVa10359.cpp │ │ ├── UVa10375.cpp │ │ ├── UVa10516.cpp │ │ ├── UVa10519.cpp │ │ ├── UVa10673.cpp │ │ ├── UVa10717.cpp │ │ ├── UVa10721.cpp │ │ ├── UVa10791.cpp │ │ ├── UVa10820.cpp │ │ ├── UVa10910.cpp │ │ ├── UVa11029.cpp │ │ ├── UVa11069.cpp │ │ ├── UVa11121.cpp │ │ ├── UVa128.cpp │ │ ├── UVa991.cpp │ │ └── readme.txt │ ├── ch11 │ │ ├── UVa10034.cpp │ │ ├── UVa10048.cpp │ │ ├── UVa10099.cpp │ │ ├── UVa10330.cpp │ │ ├── UVa10397.cpp │ │ ├── UVa10594.cpp │ │ ├── UVa10746.cpp │ │ ├── UVa10986.cpp │ │ ├── UVa558.cpp │ │ ├── UVa820.cpp │ │ └── readme.txt │ ├── ch2 │ │ ├── ex2-1.c │ │ ├── ex2-10.c │ │ ├── ex2-2.c │ │ ├── ex2-3.c │ │ ├── ex2-4.c │ │ ├── ex2-5.c │ │ ├── ex2-6.c │ │ ├── ex2-7.c │ │ ├── ex2-8.c │ │ ├── ex2-9.c │ │ ├── readme.txt │ │ ├── stat.in │ │ └── stat.out │ ├── ch5 │ │ ├── UVa10014.cpp │ │ ├── UVa10106.cpp │ │ ├── UVa10110.cpp │ │ ├── UVa10112.cpp │ │ ├── UVa10115.cpp │ │ ├── UVa10161.cpp │ │ ├── UVa10188.cpp │ │ ├── UVa10250.cpp │ │ ├── UVa10252.cpp │ │ ├── UVa10361.cpp │ │ ├── UVa10387.cpp │ │ ├── UVa10392.cpp │ │ ├── UVa10420.cpp │ │ ├── UVa10474.cpp │ │ ├── UVa10494.cpp │ │ ├── UVa10499.cpp │ │ ├── UVa10790.cpp │ │ ├── UVa10815.cpp │ │ ├── UVa10879.cpp │ │ ├── UVa10916.cpp │ │ ├── UVa10970.cpp │ │ ├── UVa11044.cpp │ │ ├── UVa113.cpp │ │ ├── UVa120.cpp │ │ ├── UVa152.cpp │ │ ├── UVa156.cpp │ │ ├── UVa299.cpp │ │ ├── UVa340.cpp │ │ ├── UVa350.cpp │ │ ├── UVa375.cpp │ │ ├── UVa400.cpp │ │ ├── UVa401.cpp │ │ ├── UVa408.cpp │ │ ├── UVa409.cpp │ │ ├── UVa424.cpp │ │ ├── UVa465.cpp │ │ ├── UVa537.cpp │ │ ├── UVa568.cpp │ │ ├── UVa573.cpp │ │ ├── UVa575.cpp │ │ ├── UVa579.cpp │ │ ├── UVa591.cpp │ │ ├── UVa644.cpp │ │ ├── UVa748.cpp │ │ └── readme.txt │ ├── ch6 │ │ ├── UVa10004.cpp │ │ ├── UVa10050.cpp │ │ ├── UVa101.cpp │ │ ├── UVa10129.cpp │ │ ├── UVa10305.cpp │ │ ├── UVa10562.cpp │ │ ├── UVa127.cpp │ │ ├── UVa133.cpp │ │ ├── UVa297.cpp │ │ ├── UVa439.cpp │ │ ├── UVa442.cpp │ │ ├── UVa532.cpp │ │ ├── UVa540.cpp │ │ ├── UVa548.cpp │ │ ├── UVa572.cpp │ │ ├── UVa657.cpp │ │ ├── UVa673.cpp │ │ ├── UVa699.cpp │ │ ├── UVa712.cpp │ │ ├── UVa784.cpp │ │ ├── UVa839.cpp │ │ ├── readme.txt │ │ ├── uva10047.cpp │ │ └── uva10054.cpp │ ├── ch7 │ │ ├── UVa10098.cpp │ │ ├── UVa10344.cpp │ │ ├── UVa10422.cpp │ │ ├── UVa11205.cpp │ │ ├── UVa11218.cpp │ │ ├── UVa140.cpp │ │ ├── UVa146.cpp │ │ ├── UVa167.cpp │ │ ├── UVa193.cpp │ │ ├── UVa208.cpp │ │ ├── UVa216.cpp │ │ ├── UVa301.cpp │ │ ├── UVa331.cpp │ │ ├── UVa387.cpp │ │ ├── UVa539.cpp │ │ ├── UVa565.cpp │ │ ├── UVa729.cpp │ │ ├── UVa729b.cpp │ │ ├── UVa729c.cpp │ │ └── readme.txt │ ├── ch8 │ │ ├── UVa10026.cpp │ │ ├── UVa10041.cpp │ │ ├── UVa10340.cpp │ │ ├── UVa10391.cpp │ │ ├── UVa10487.cpp │ │ ├── UVa10670.cpp │ │ ├── UVa10700.cpp │ │ ├── UVa10714.cpp │ │ ├── UVa10718.cpp │ │ ├── UVa10763.cpp │ │ ├── UVa108.cpp │ │ ├── UVa10905.cpp │ │ ├── UVa10954.cpp │ │ ├── UVa11054.cpp │ │ ├── UVa11100.cpp │ │ ├── UVa270.cpp │ │ ├── UVa507.cpp │ │ └── readme.txt │ ├── ch9 │ │ ├── UVa10003.cpp │ │ ├── UVa10066.cpp │ │ ├── UVa10069.cpp │ │ ├── UVa10131.cpp │ │ ├── UVa10192.cpp │ │ ├── UVa10285.cpp │ │ ├── UVa103.cpp │ │ ├── UVa10304.cpp │ │ ├── UVa10405.cpp │ │ ├── UVa10617.cpp │ │ ├── UVa10739.cpp │ │ ├── UVa111.cpp │ │ ├── UVa116.cpp │ │ ├── UVa147.cpp │ │ ├── UVa348.cpp │ │ ├── UVa357.cpp │ │ ├── UVa437.cpp │ │ ├── UVa531.cpp │ │ ├── UVa562.cpp │ │ ├── UVa590.cpp │ │ ├── UVa624.cpp │ │ ├── UVa674.cpp │ │ ├── UVa825.cpp │ │ └── readme.txt │ ├── readme.txt │ └── warmup │ │ ├── UVa10055.cpp │ │ ├── UVa10071.cpp │ │ ├── UVa10300.cpp │ │ ├── UVa414.cpp │ │ ├── UVa445.cpp │ │ ├── UVa457.cpp │ │ ├── UVa458.cpp │ │ ├── UVa488.cpp │ │ ├── UVa489.cpp │ │ ├── UVa490.cpp │ │ ├── UVa494.cpp │ │ ├── UVa694.cpp │ │ └── readme.txt ├── haskell │ ├── ch1 │ │ ├── ex1-1.hs │ │ ├── ex1-10.hs │ │ ├── ex1-2.hs │ │ ├── ex1-3.hs │ │ ├── ex1-4.hs │ │ ├── ex1-5.hs │ │ ├── ex1-6.hs │ │ ├── ex1-7.hs │ │ ├── ex1-8.hs │ │ ├── ex1-9.hs │ │ ├── p1-1.hs │ │ ├── p1-2.hs │ │ ├── p1-3.hs │ │ ├── p1-4.hs │ │ ├── p1-5.hs │ │ └── readme.txt │ ├── ch2 │ │ ├── ex2-1.hs │ │ ├── ex2-10.hs │ │ ├── ex2-2.hs │ │ ├── ex2-3.hs │ │ ├── ex2-4.hs │ │ ├── ex2-5.hs │ │ ├── ex2-6.hs │ │ ├── ex2-7.hs │ │ ├── ex2-8.hs │ │ ├── ex2-9.hs │ │ ├── p2-1.hs │ │ ├── p2-2.hs │ │ ├── p2-3.hs │ │ ├── p2-4.hs │ │ ├── readme.txt │ │ ├── stat.in │ │ └── stat.out │ └── readme.txt ├── python │ ├── ch1 │ │ ├── ex1-1.py │ │ ├── ex1-10.py │ │ ├── ex1-2.py │ │ ├── ex1-3.py │ │ ├── ex1-4.py │ │ ├── ex1-5.py │ │ ├── ex1-6.py │ │ ├── ex1-7.py │ │ ├── ex1-8.py │ │ ├── ex1-9.py │ │ ├── p1-1.py │ │ ├── p1-2.py │ │ ├── p1-3.py │ │ ├── p1-4.py │ │ ├── p1-5.py │ │ └── readme.txt │ ├── ch2 │ │ ├── ex2-1.py │ │ ├── ex2-10.py │ │ ├── ex2-2.py │ │ ├── ex2-3.py │ │ ├── ex2-4.py │ │ ├── ex2-5.py │ │ ├── ex2-6.py │ │ ├── ex2-7.py │ │ ├── ex2-8.py │ │ ├── ex2-9.py │ │ ├── p2-1.py │ │ ├── p2-2.py │ │ ├── p2-3.py │ │ ├── p2-4.py │ │ ├── readme.txt │ │ ├── stat.in │ │ └── stat.out │ └── readme.txt └── readme_lang.txt └── TrainingGuide ├── bookcodes ├── ch1 │ ├── la2678.cpp │ ├── la2678_n2.cpp │ ├── la2678_n3.cpp │ ├── la2678_nlogn.cpp │ ├── la2965.cpp │ ├── la2995.cpp │ ├── la3029.cpp │ ├── la3177.cpp │ ├── la3401.cpp │ ├── la3401_make.cpp │ ├── la3635.cpp │ ├── la3695.cpp │ ├── la3708.cpp │ ├── la3882.cpp │ ├── la3902.cpp │ ├── la3905.cpp │ ├── la3905_int.cpp │ ├── la3971.cpp │ ├── la3983.cpp │ ├── la4794.cpp │ ├── readme.txt │ ├── uva10635.cpp │ ├── uva10755.cpp │ ├── uva10795.cpp │ ├── uva10859.cpp │ ├── uva10881.cpp │ ├── uva10891.cpp │ ├── uva10891_slow.cpp │ ├── uva11078.cpp │ ├── uva11210.cpp │ ├── uva11292.cpp │ ├── uva11300.cpp │ ├── uva11384.cpp │ ├── uva11462.cpp │ ├── uva11464.cpp │ ├── uva11520.cpp │ ├── uva11549.cpp │ ├── uva11729.cpp │ └── uva11825.cpp ├── ch2 │ ├── la3485.cpp │ ├── la3485_simpson.cpp │ ├── la3510.cpp │ ├── la3516.cpp │ ├── la3641.cpp │ ├── la3704.cpp │ ├── la4119.cpp │ ├── la4123.cpp │ ├── la5009.cpp │ ├── la5059.cpp │ ├── la5059_try.cpp │ ├── readme.txt │ ├── uva10253.cpp │ ├── uva10294.cpp │ ├── uva10341.cpp │ ├── uva10561.cpp │ ├── uva10828.cpp │ ├── uva10870.cpp │ ├── uva11021.cpp │ ├── uva11077.cpp │ ├── uva11361.cpp │ ├── uva11401.cpp │ ├── uva11426.cpp │ ├── uva11427.cpp │ ├── uva11538.cpp │ ├── uva11542.cpp │ ├── uva11722.cpp │ ├── uva11754.cpp │ ├── uva11762.cpp │ ├── uva11806.cpp │ └── uva11916.cpp ├── ch3 │ ├── dynamic_rmq.cpp │ ├── la3026.cpp │ ├── la3027.cpp │ ├── la3135.cpp │ ├── la3644.cpp │ ├── la3938.cpp │ ├── la3942.cpp │ ├── la4329.cpp │ ├── la4513.cpp │ ├── la4670.cpp │ ├── la5031.cpp │ ├── la5031_noremove.cpp │ ├── ranktree.cpp │ ├── readme.txt │ ├── search_engine.cpp │ ├── sequence1.cpp │ ├── sequence2.cpp │ ├── uva11019.cpp │ ├── uva11020.cpp │ ├── uva11107.cpp │ ├── uva11235.cpp │ ├── uva11468.cpp │ ├── uva11732.cpp │ ├── uva11922.cpp │ ├── uva11991.cpp │ ├── uva11992.cpp │ ├── uva11992b.cpp │ ├── uva11995.cpp │ ├── uva11996.cpp │ └── uva11997.cpp ├── ch4 │ ├── la2218.cpp │ ├── la2572.cpp │ ├── la2797.cpp │ ├── la3218.cpp │ ├── la3263.cpp │ ├── la3890.cpp │ ├── la4589.cpp │ ├── la4728.cpp │ ├── la4795.cpp │ ├── la4973.cpp │ ├── la4992.cpp │ ├── readme.txt │ ├── uva10256.cpp │ ├── uva10652.cpp │ ├── uva11168.cpp │ ├── uva11178.cpp │ ├── uva11275.cpp │ ├── uva11275_area.cpp │ ├── uva11275_barycentric.cpp │ ├── uva11796.cpp │ ├── uva12296.cpp │ └── uva12304.cpp ├── ch5 │ ├── la2238.cpp │ ├── la2531.cpp │ ├── la2957.cpp │ ├── la3126.cpp │ ├── la3211.cpp │ ├── la3415.cpp │ ├── la3523.cpp │ ├── la3561.cpp │ ├── la3661.cpp │ ├── la3661_complex.cpp │ ├── la3713.cpp │ ├── la3989.cpp │ ├── la4043.cpp │ ├── la4080.cpp │ ├── la4128.cpp │ ├── la4128_complex.cpp │ ├── la4255.cpp │ ├── la4287.cpp │ ├── la4287_kosaraju.cpp │ ├── la5135.cpp │ ├── la5713.cpp │ ├── readme.txt │ ├── uva10047.cpp │ ├── uva10054.cpp │ ├── uva10537.cpp │ ├── uva10779.cpp │ ├── uva10917.cpp │ ├── uva11090.cpp │ ├── uva11248.cpp │ ├── uva11248_dinic.cpp │ ├── uva11324.cpp │ ├── uva11354.cpp │ ├── uva11374.cpp │ ├── uva11383.cpp │ ├── uva11383_template.cpp │ ├── uva11419.cpp │ ├── uva11478.cpp │ ├── uva11613.cpp │ ├── uva11624.cpp │ └── uva11865.cpp ├── ch6 │ ├── la2397.cpp │ ├── la2659.cpp │ ├── la3532.cpp │ ├── la3620.cpp │ ├── la3700.cpp │ ├── la3789.cpp │ ├── la3809.cpp │ ├── la4125.cpp │ ├── la4127.cpp │ ├── la4451.cpp │ ├── la4488.cpp │ ├── la4488_bad.cpp │ ├── la4746.cpp │ ├── la5129.cpp │ ├── readme.txt │ ├── uva10498.cpp │ ├── uva10572.cpp │ ├── uva10966.cpp │ ├── uva11017.cpp │ ├── uva11270.cpp │ ├── uva11297.cpp │ ├── uva11297_build.cpp │ ├── uva11921.cpp │ ├── uva11990.cpp │ ├── uva12003.cpp │ ├── uva12298.cpp │ └── uva12303.cpp └── readme.txt └── exercises ├── ch1 ├── BruteForce │ ├── LA5844.cpp │ ├── UVA10085.cc │ ├── UVA10123.cc │ ├── Uva10496.cc │ ├── Uva11236.cc │ ├── Uva387.cc │ └── Uva529.cc ├── DP │ ├── Uva10051.cc │ ├── Uva10100.cc │ ├── Uva10130.cc │ ├── Uva10243.cc │ ├── Uva10306.cc │ ├── Uva10400.cc │ ├── Uva10534.cc │ ├── Uva10651.cc │ ├── Uva10700.cc │ ├── Uva10817.cc │ └── Uva11081.cc ├── Efficient │ ├── Uva10125.cc │ ├── Uva10391.cc │ ├── Uva10763.cc │ ├── Uva10827.cc │ ├── Uva10954.cc │ ├── Uva11054.cc │ ├── Uva11495.cc │ └── uva11589.cpp ├── General │ ├── Uva10340.cc │ ├── Uva10382.cc │ ├── Uva10706.cc │ ├── Uva10718.cc │ ├── Uva10905.cc │ └── Uva11100.cc └── readme.txt ├── ch2 ├── Basic Problems │ ├── UVa10710.cc │ ├── UVa11388.cpp │ ├── UVa11444.cc │ ├── UVa11526.cpp │ ├── UVa11609.cpp │ └── UVa11752.cc ├── CombinatorialGames │ ├── UVa10165.cc │ ├── UVa11927.cc │ ├── UVa12293.cc │ └── UVa847.cc ├── Counting │ ├── UVa10079.cc │ ├── UVa10081.cc │ ├── UVa10157.cc │ ├── UVa10312.cc │ ├── UVa10497.cc │ ├── UVa10883.cc │ ├── UVa11137.cpp │ ├── UVa11137_slow.cpp │ ├── UVa11174.cpp │ ├── UVa11375.cpp │ └── UVa1510.cc ├── Number Theory │ ├── UVa10061.cc │ ├── UVa10090.cc │ ├── UVa10104.cc │ ├── UVa10110.cc │ ├── UVa10127.cc │ ├── UVa10162.cc │ ├── UVa10325.cc │ ├── UVa10368.cc │ ├── UVa10616.cc │ ├── UVa10673.cc │ ├── UVa10990.cc │ ├── UVa11029.cc │ ├── UVa11180.cc │ ├── UVa11287.cc │ ├── UVa11317.cc │ ├── UVa11440.cpp │ └── UVa11718.cpp ├── Probability │ ├── UVa10491.cc │ ├── UVa10759.cc │ ├── UVa11181.cc │ ├── UVa11637.cpp │ └── UVa11971.cpp └── readme.txt ├── ch3 ├── 01-FundamentalDataStructures │ ├── UVa10895.cc │ ├── UVa11136.cc │ ├── UVa11987.cc │ └── UVa11988.cc ├── 02-MaintainingIntervalData │ ├── UVa12086.cc │ ├── UVa12299_build.cpp │ ├── UVa1455.cc │ └── uva12299.cpp ├── 03-StringAlgorithms │ ├── UVa11488.cc │ ├── UVa11855_hash.cc │ ├── UVa11855_sa.cc │ └── UVa1399.cc ├── 04-BST │ ├── UVa10909.cpp │ └── UVa1264.cc └── readme.txt ├── ch4 ├── 01-BasicProblems │ ├── UVa10347.cc │ ├── UVa10439.cc │ ├── UVa10522.cc │ ├── UVa10566.cc │ ├── UVa11437.cc │ ├── UVa11800.cc │ ├── UVa12300.cc │ ├── UVa12301.cc │ ├── uva11646.cpp │ └── uva11817.cpp ├── 02-GeometricComputations2D │ ├── UVa10075.cc │ ├── UVa10556.cc │ ├── UVa10585.cc │ ├── UVa10969.cc │ ├── UVa11928.cpp │ └── uva10674.cpp ├── 03-GeometricAlgorithms2D │ ├── UVa10084.cc │ └── UVa1303.cc ├── 04-GeometricComputations&Algorithms3D │ ├── UVa10794.cc │ ├── UVa11836.cc │ ├── UVa1333.cc │ ├── UVa1360.cc │ └── UVa1373.cc └── readme.txt ├── ch5 ├── LA2197.cc ├── LA2796.cc ├── LA3268.cc ├── LA3276.cc ├── LA3353.cc ├── LA3486.java ├── LA3487.cc ├── LA3887.cc ├── LA3972.cc ├── LA4288.cc ├── LA5095.cc ├── UVA11294.java ├── UVa10269.cc ├── UVa10600.cc ├── UVa10603.cc ├── UVa10765.cc ├── UVa10806.cc ├── UVa11396.cc ├── Uva11082.cc ├── la3486.cpp └── readme.txt ├── ch6 ├── 04-Geometry │ └── UVa1497.cc ├── UVa10996.cc ├── readme.txt └── uva1024.cpp └── readme.txt /BeginningAlgorithmContests/bookcodes/ch1-4/1-1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | printf("%d\n", 1+2); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-10.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b; 4 | scanf("%d%d", &a, &b); 5 | printf("%d %d\n", b, a); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-11.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b, n, m; 4 | scanf("%d%d", &n, &m); 5 | a = (4*n-m)/2; 6 | b = n-a; 7 | if(m % 2 == 1 || a < 0 || b < 0) 8 | printf("No answer\n"); 9 | else 10 | printf("%d %d\n", a, b); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-12.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b, c; 4 | scanf("%d%d%d", &a, &b, &c); 5 | if(a < b && b < c) printf("%d %d %d\n", a, b, c); 6 | if(a < c && c < b) printf("%d %d %d\n", a, c, b); 7 | if(b < a && a < c) printf("%d %d %d\n", b, a, c); 8 | if(b < c && c < a) printf("%d %d %d\n", b, c, a); 9 | if(c < a && a < b) printf("%d %d %d\n", c, a, b); 10 | if(c < b && b < a) printf("%d %d %d\n", c, b, a); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-13.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b, c; 4 | scanf("%d%d%d", &a, &b, &c); 5 | if(a <= b && b <= c) printf("%d %d %d\n", a, b, c); 6 | else if(a <= c && c <= b) printf("%d %d %d\n", a, c, b); 7 | else if(b <= a && a <= c) printf("%d %d %d\n", b, a, c); 8 | else if(b <= c && c <= a) printf("%d %d %d\n", b, c, a); 9 | else if(c <= a && a <= b) printf("%d %d %d\n", c, a, b); 10 | else if(c <= b && b <= a) printf("%d %d %d\n", c, b, a); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-14.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b, c, t; 4 | scanf("%d%d%d", &a, &b, &c); 5 | if(a > b) { t = a; a = b; b = t; } 6 | if(a > c) { t = a; a = c; c = t; } 7 | if(b > c) { t = b; b = c; c = t; } 8 | printf("%d %d %d\n", a, b, c); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-15.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b, c, x, y, z; 4 | scanf("%d%d%d", &a, &b, &c); 5 | x = a; if(b < x) x = b; if(c < x) x = c; 6 | z = a; if(b > z) z = b; if(c > z) z = c; 7 | y = a + b + c - x - z; 8 | printf("%d %d %d\n", x, y, z); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | printf("%.1lf\n", 8.0/5.0); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | printf("%.8lf\n", 1+2*sqrt(3)/(5-0.1)); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-4.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b; 4 | scanf("%d%d", &a, &b); 5 | printf("%d\n", a+b); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | const double pi = 4.0 * atan(1.0); 5 | double r, h, s1, s2, s; 6 | scanf("%lf%lf", &r, &h); 7 | s1 = pi * r * r; 8 | s2 = 2 * pi * r * h; 9 | s = s1 * 2.0 + s2; 10 | printf("Area = %.3lf\n", s); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-6.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n; 4 | scanf("%d", &n); 5 | printf("%d%d%d\n", n%10, n/10%10, n/100); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-7.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n, m; 4 | scanf("%d", &n); 5 | m = (n%10)*100 + (n/10%10)*10 + (n/100); 6 | printf("%03d\n", m); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-8.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b, t; 4 | scanf("%d%d", &a, &b); 5 | t = a; 6 | a = b; 7 | b = t; 8 | printf("%d %d\n", a, b); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/1-9.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int a, b; 4 | scanf("%d%d", &a, &b); 5 | a = a + b; 6 | b = a - b; 7 | a = a - b; 8 | printf("%d %d\n", a, b); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/2-1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int i, n; 4 | scanf("%d", &n); 5 | for(i = 1; i <= n; i++) 6 | printf("%d\n", i); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/2-2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | int a, b, n; 5 | double m; 6 | for(a = 1; a <= 9; a++) 7 | for(b = 0; b <= 9; b++) { 8 | n = a*1100 + b*11; 9 | m = sqrt(n); 10 | if(floor(m+0.5) == m) printf("%d\n", n); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/2-3.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int x, n, hi, lo; 4 | for(x = 1; ; x++) { 5 | n = x * x; 6 | if(n < 1000) continue; 7 | if(n > 9999) break; 8 | hi = n / 100; 9 | lo = n % 100; 10 | if(hi/10 == hi%10 && lo/10 == lo%10) printf("%d\n", n); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/2-4.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n, count = 0; 4 | scanf("%d", &n); 5 | while(n > 1) { 6 | if(n % 2 == 1) n = n*3+1; 7 | else n /= 2; 8 | count++; 9 | } 10 | printf("%d\n", count); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/2-5.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int i, j, n, S = 0; 4 | scanf("%d", &n); 5 | for(i = 1; i <= n; i++){ 6 | int factorial = 1; 7 | for(j = 1; j <= i; j++) 8 | factorial *= j; 9 | S += factorial; 10 | } 11 | printf("%d\n", S % 1000000); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/2-6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | const int MOD = 1000000; 5 | int i, j, n, S = 0; 6 | scanf("%d", &n); 7 | for(i = 1; i <= n; i++){ 8 | int factorial = 1; 9 | for(j = 1; j <= i; j++) 10 | factorial = (factorial * j % MOD); 11 | S = (S + factorial) % MOD; 12 | } 13 | printf("%d\n", S); 14 | printf("Time used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/2-7.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int x, n = 0, min, max, s = 0; 4 | while(scanf("%d", &x) == 1) { 5 | s += x; 6 | if(x < min) min = x; 7 | if(x > max) max = x; 8 | n++; 9 | } 10 | printf("%d %d %.3lf\n", min, max, (double)s/n); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/2-8.c: -------------------------------------------------------------------------------- 1 | #define LOCAL 2 | #include 3 | #define INF 1000000000 4 | int main(){ 5 | #ifdef LOCAL 6 | freopen("data.in", "r", stdin); 7 | freopen("data.out", "w", stdout); 8 | #endif 9 | int x, n = 0, min = INF, max = -INF, s = 0; 10 | while(scanf("%d", &x) == 1) { 11 | s += x; 12 | if(x < min) min = x; 13 | if(x > max) max = x; 14 | /* 15 | printf("x = %d, min = %d, max = %d\n", x, min, max); 16 | */ 17 | n++; 18 | } 19 | printf("%d %d %.3lf\n", min, max, (double)s/n); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/2-9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define INF 1000000000 3 | int main(){ 4 | FILE *fin, *fout; 5 | fin = fopen("data.in", "rb"); 6 | fout = fopen("data.out", "wb"); 7 | int x, n = 0, min = INF, max = -INF, s = 0; 8 | while(fscanf(fin, "%d", &x) == 1) { 9 | s += x; 10 | if(x < min) min = x; 11 | if(x > max) max = x; 12 | n++; 13 | } 14 | fprintf(fout, "%d %d %.3lf\n", min, max, (double)s/n); 15 | fclose(fin); 16 | fclose(fout); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/3-1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAXN 100 + 10 3 | int a[MAXN]; 4 | int main(){ 5 | int i, x, n = 0; 6 | while(scanf("%d", &x) == 1) 7 | a[n++] = x; 8 | for(i = n-1; i >= 1; i--) 9 | printf("%d ", a[i]); 10 | printf("%d\n", a[0]); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/3-2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAXN 1000 + 10 4 | int a[MAXN]; 5 | int main() { 6 | int i, j, n, k, first = 1; 7 | memset(a, 0, sizeof(a)); 8 | scanf("%d%d", &n, &k); 9 | for(i = 1; i <= k; i++) 10 | for(j = 1; j <= n; j++) 11 | if(j % i == 0) a[j] = !a[j]; 12 | for(i = 1; i <= n; i++) 13 | if(a[i]) { if(first) first = 0; else printf(" "); printf("%d", i); } 14 | printf("\n"); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/3-3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAXN 10 4 | int a[MAXN][MAXN]; 5 | int main(){ 6 | int n, x, y, tot = 0; 7 | scanf("%d", &n); 8 | memset(a, 0, sizeof(a)); 9 | tot = a[x=0][y=n-1] = 1; 10 | while(tot < n*n) { 11 | while(x+1=0 && !a[x][y-1]) a[x][--y] = ++tot; 13 | while(x-1>=0 && !a[x-1][y]) a[--x][y] = ++tot; 14 | while(y+1 2 | #include 3 | int main(){ 4 | int i, ok, abc, de, x, y, z, count = 0; 5 | char s[20], buf[99]; 6 | scanf("%s", s); 7 | for(abc = 111; abc <= 999; abc++) 8 | for(de = 11; de <= 99; de++) { 9 | x = abc*(de%10); y = abc*(de/10); z = abc*de; 10 | sprintf(buf, "%d%d%d%d%d", abc, de, x, y, z); 11 | ok = 1; 12 | for(i = 0; i < strlen(buf); i++) 13 | if(strchr(s, buf[i]) == NULL) ok = 0; 14 | if(ok) { 15 | printf("<%d>\n", ++count); 16 | printf("%5d\nX%4d\n-----\n%5d\n%4d\n-----\n%5d\n\n", abc, de, x, y, z); 17 | } 18 | } 19 | printf("The number of solutions = %d\n", count); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/3-5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define MAXN 5000 + 10 5 | char buf[MAXN], s[MAXN]; 6 | int main(){ 7 | int n, m = 0, max = 0; 8 | int i, j, k; 9 | fgets(buf, sizeof(s), stdin); 10 | n = strlen(buf); 11 | for(i = 0; i < n; i++) 12 | if(isalpha(buf[i])) s[m++] = toupper(buf[i]); 13 | for(i = 0; i < m; i++) 14 | for(j = i; j < m; j++) { 15 | int ok = 1; 16 | for(k = i; k <= j; k++) 17 | if(s[k] != s[i+j-k]) ok = 0; 18 | if(ok && j-i+1 > max) max = j-i+1; 19 | } 20 | printf("max = %d\n", max); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/4-1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int f(int n) { 3 | int i, m = 1; 4 | for(i = 1; i <= n; i++) 5 | m *= i; 6 | return m; 7 | } 8 | 9 | int main() { 10 | int m, n; 11 | scanf("%d%d", &m, &n); 12 | printf("%d\n", f(n)/(f(m)*f(n-m))); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/4-2.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* do NOT use this if x is very large or small */ 3 | int is_prime(int x){ 4 | int i; 5 | for(i = 2; i*i <= x; i++) 6 | if(x % i == 0) return 0; 7 | return 1; 8 | } 9 | 10 | int main(){ 11 | int i, m; 12 | scanf("%d", &m); 13 | for(i = m-2; i >= 3; i--) 14 | if(is_prime(i) && is_prime(i+2)) { 15 | printf("%d %d\n", i, i+2); 16 | break; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/4-3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int is_prime(int x){ 5 | int i, m; 6 | assert(x >= 0); 7 | if(x == 1) return 0; 8 | m = floor(sqrt(x) + 0.5); 9 | for(i = 2; i <= m; i++) 10 | if(x % i == 0) return 0; 11 | return 1; 12 | } 13 | 14 | int main(){ 15 | int i, m; 16 | scanf("%d", &m); 17 | for(i = m-2; i >= 3; i--) 18 | if(is_prime(i) && is_prime(i+2)) { 19 | printf("%d %d\n", i, i+2); 20 | break; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/4-4.c: -------------------------------------------------------------------------------- 1 | #include 2 | void swap(int a, int b){ 3 | int t = a; a = b; b = t; 4 | } 5 | 6 | int main(){ 7 | int a = 3, b = 4; 8 | swap(3, 4); 9 | printf("%d %d\n", a, b); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/4-5.c: -------------------------------------------------------------------------------- 1 | #include 2 | void swap(int* a, int* b){ 3 | int t = *a; *a = *b; *b = t; 4 | } 5 | 6 | int main(){ 7 | int a = 3, b = 4; 8 | swap(&a, &b); 9 | printf("%d %d\n", a, b); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch1-4/4-6.c: -------------------------------------------------------------------------------- 1 | #include 2 | int f(int n){ 3 | return n == 0 ? 1 : f(n-1)*n; 4 | } 5 | int main(){ 6 | printf("%d\n", f(3)); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch11/readme.txt: -------------------------------------------------------------------------------- 1 | 第十一章 图论模型与算法 2 | 3 | * 有向简单图生成器 4 | gen1.cpp (一个权值,适合最短路和最大流) 5 | gen2.cpp(两个权值,适合最小费用最大流) 6 | 7 | * 最短路 测试脚本: test_sssp.bat 8 | dijkstra.cpp (Dijkstra算法, 邻接矩阵) 9 | dijkstraheap.cpp (Dijkstra算法,邻接表+二叉堆) 10 | bellman.cpp (Bellman-Ford算法,邻接表) 11 | 12 | * 网络流 测试脚本: test_maxflow.bat 13 | maxflow.cpp (Ford-Fulkeson算法,DFS找增广路) 14 | maxflow2.cpp (Edmonds-Karp算法,BFS找增广路) 15 | mincostflow.cpp (连续最短路算法,Bellman-Ford找最短增广路) 16 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch11/test_maxflow.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | g++ gen1.cpp 3 | echo Generating data... 4 | a 1000 10000 > 1.in 5 | g++ maxflow.cpp 6 | echo Running maxflow 7 | a < 1.in > 1.a 8 | g++ maxflow2.cpp 9 | echo Running maxflow2 10 | a < 1.in > 1.b 11 | fc 1.a 1.b 12 | del a.exe 13 | del 1.in 14 | del 1.a 15 | del 1.b 16 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch11/test_sssp.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | g++ gen1.cpp 3 | echo Generating data... 4 | a 1000 10000 > 1.in 5 | g++ dijkstra.cpp 6 | echo Running dijkstra 7 | a < 1.in > 1.a 8 | g++ dijkstraheap.cpp 9 | echo Running dijkstraheap 10 | a < 1.in > 1.b 11 | g++ bellman.cpp 12 | echo Running bellman 13 | a < 1.in > 1.c 14 | fc 1.a 1.b 15 | fc 1.a 1.c 16 | del a.exe 17 | del 1.in 18 | del 1.a 19 | del 1.b 20 | del 1.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/10035.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int a, b; 4 | while (scanf("%d%d",&a,&b) == 2){ 5 | if (!a && !b) break; 6 | int c = 0, ans = 0; 7 | for (int i = 9; i >= 0; i--) { 8 | c = (a%10 + b%10 + c) > 9 ? 1 : 0; 9 | ans += c; 10 | a /= 10; b /= 10; 11 | } 12 | printf("%d\n", ans); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/10035_uva.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int a, b; 4 | while (scanf("%d%d",&a,&b) == 2){ 5 | if (!a && !b) break; 6 | int c = 0, ans = 0; 7 | for (int i = 9; i >= 0; i--) { 8 | c = (a%10 + b%10 + c) > 9 ? 1 : 0; 9 | ans += c; 10 | a /= 10; b /= 10; 11 | } 12 | if(ans == 0) printf("No carry operation.\n"); 13 | else if(ans == 1) printf("1 carry operation.\n"); 14 | else printf("%d carry operations.\n", ans); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/10082.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const char *s = "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"; 3 | int main(){ 4 | int i,c; 5 | while ((c = getchar()) != EOF) { 6 | for (i=1; s[i] && s[i]!=c; i++); 7 | if (s[i]) putchar(s[i-1]); else putchar(c); 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/143.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | double area(double x1, double y1, double x2, double y2, double x3, double y3) { 4 | return fabs(x1*y3+x2*y1+x3*y2-x2*y3-x3*y1-x1*y2); 5 | } 6 | 7 | int main() { 8 | double x1, y1, x2, y2, x3, y3; 9 | while(scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3) == 6) { 10 | int ans = 0; 11 | for(int x = 1; x <= 99; x++) 12 | for(int y = 1; y <= 99; y++) 13 | if(fabs(area(x1,y1,x2,y2,x,y)+area(x2,y2,x3,y3,x,y)+area(x3,y3,x1,y1,x,y)-area(x1,y1,x2,y2,x3,y3)) < 1e-8) ans++; 14 | printf("%d\n", ans); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/264.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; 4 | while(scanf("%d", &n) == 1) { 5 | int k = 1, s = 0; 6 | for(;;) { 7 | s += k; 8 | if(s >= n) { 9 | if(k % 2 == 1) 10 | printf("%d/%d\n", s-n+1, k-s+n); 11 | else 12 | printf("%d/%d\n", k-s+n, s-n+1); 13 | break; 14 | } 15 | k++; 16 | } 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/264_uva.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; 4 | while(scanf("%d", &n) == 1) { 5 | int k = 1, s = 0; 6 | for(;;) { 7 | s += k; 8 | if(s >= n) { 9 | if(k % 2 == 1) 10 | printf("TERM %d IS %d/%d\n", n, s-n+1, k-s+n); 11 | else 12 | printf("TERM %d IS %d/%d\n", n, k-s+n, s-n+1); 13 | break; 14 | } 15 | k++; 16 | } 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/264b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int n; 5 | while(scanf("%d", &n) == 1) { 6 | int k = (int)floor((sqrt(8.0*n+1)-1)/2 - 1e-9)+1; 7 | int s = k*(k+1)/2; 8 | if(k % 2 == 1) 9 | printf("%d/%d\n", s-n+1, k-s+n); 10 | else 11 | printf("%d/%d\n", k-s+n, s-n+1); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/264b_uva.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int n; 5 | while(scanf("%d", &n) == 1) { 6 | int k = (int)floor((sqrt(8.0*n+1)-1)/2 - 1e-9)+1; 7 | int s = k*(k+1)/2; 8 | if(k % 2 == 1) 9 | printf("TERM %d IS %d/%d\n", n, s-n+1, k-s+n); 10 | else 11 | printf("TERM %d IS %d/%d\n", n, k-s+n, s-n+1); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/272.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int c, q = 1; 4 | while((c= getchar()) != EOF) { 5 | if(c == '"') { printf("%s", q ? "``" : "''"); q = !q; } 6 | else printf("%c", c); 7 | } 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/455.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | char word[100]; 5 | scanf("%s", word); 6 | int len = strlen(word); 7 | for (int i = 1; i <= len; i++) if (len % i == 0) { 8 | int ok = 1; 9 | for (int j = i; j < len; j++) 10 | if (word[j] != word[j % i]) { ok = 0; break; } 11 | if (ok) { printf("%d\n", i); break; } 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/455_uva.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | int T; 5 | scanf("%d", &T); 6 | while(T--) { 7 | char word[100]; 8 | scanf("%s", word); 9 | int len = strlen(word); 10 | for (int i = 1; i <= len; i++) if (len % i == 0) { 11 | int ok = 1; 12 | for (int j = i; j < len; j++) 13 | if (word[j] != word[j % i]) { ok = 0; break; } 14 | if (ok) { printf("%d\n", i); break; } 15 | } 16 | if(T > 0) printf("\n"); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/623.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int maxn = 3000; 4 | int f[maxn]; 5 | 6 | int main() { 7 | int i, j, n; 8 | scanf("%d", &n); 9 | memset(f, 0, sizeof(f)); 10 | f[0] = 1; 11 | for(i = 2; i <= n; i++) { 12 | int c = 0; 13 | for(j = 0; j < maxn; j++) { 14 | int s = f[j] * i + c; 15 | f[j] = s % 10; 16 | c = s / 10; 17 | } 18 | } 19 | for(j = maxn-1; j >= 0; j--) if(f[j]) break; 20 | for(i = j; i >= 0; i--) printf("%d", f[i]); 21 | printf("\n"); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch5/land.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int n; 4 | scanf("%d", &n); 5 | int V = 0, E = 0; 6 | for(int i = 0; i <= n-2; i++) 7 | V += i*(n-2-i), E += i*(n-2-i)+1; 8 | V = V*n/4+n; 9 | E = E*n/2+n; 10 | printf("%d\n", E-V+1); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/10935.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch6/10935.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/10935_uva.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch6/10935_uva.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/10935b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | queue q; 6 | int main() { 7 | int n; 8 | scanf("%d", &n); 9 | for(int i = 0; i < n; i++) q.push(i+1); 10 | while(!q.empty()) { 11 | printf("%d ", q.front()); 12 | q.pop(); 13 | q.push(q.front()); 14 | q.pop(); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/514.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int MAXN = 1000 + 10; 3 | int n, target[MAXN]; 4 | 5 | int main() { 6 | while(scanf("%d", &n) == 1) { 7 | int stack[MAXN], top = 0; 8 | int A = 1, B = 1; 9 | for(int i = 1; i <= n; i++) 10 | scanf("%d", &target[i]); 11 | int ok = 1; 12 | while(B <= n) { 13 | if(A == target[B]){ A++; B++; } 14 | else if(top && stack[top] == target[B]){ top--; B++; } 15 | else if(A <= n) stack[++top] = A++; 16 | else { ok = 0; break; } 17 | } 18 | printf("%s\n", ok ? "Yes" : "No"); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/514_uva.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | const int MAXN = 1000 + 10; 5 | 6 | int n, target[MAXN]; 7 | 8 | int main() { 9 | while(scanf("%d", &n) == 1 && n > 0) { 10 | stack s; 11 | while(scanf("%d", &target[1]) == 1 && target[1] != 0) { 12 | int A = 1, B = 1; 13 | for(int i = 2; i <= n; i++) 14 | scanf("%d", &target[i]); 15 | int ok = 1; 16 | while(B <= n) { 17 | if(A == target[B]){ A++; B++; } 18 | else if(!s.empty() && s.top() == target[B]){ s.pop(); B++; } 19 | else if(A <= n) s.push(A++); 20 | else { ok = 0; break; } 21 | } 22 | printf("%s\n", ok ? "Yes" : "No"); 23 | } 24 | printf("\n"); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/514b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | const int MAXN = 1000 + 10; 5 | 6 | int n, target[MAXN]; 7 | 8 | int main() { 9 | while(scanf("%d", &n) == 1) { 10 | stack s; 11 | int A = 1, B = 1; 12 | for(int i = 1; i <= n; i++) 13 | scanf("%d", &target[i]); 14 | int ok = 1; 15 | while(B <= n) { 16 | if(A == target[B]){ A++; B++; } 17 | else if(!s.empty() && s.top() == target[B]){ s.pop(); B++; } 18 | else if(A <= n) s.push(A++); 19 | else { ok = 0; break; } 20 | } 21 | printf("%s\n", ok ? "Yes" : "No"); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/536.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int MAXN = 30; 4 | 5 | void build(int n, char* s1, char* s2, char* s) { 6 | if(n <= 0) return; 7 | int p = strchr(s2, s1[0]) - s2; 8 | build(p, s1+1, s2, s); 9 | build(n-p-1, s1+p+1, s2+p+1, s+p); 10 | s[n-1] = s1[0]; 11 | } 12 | 13 | int main() { 14 | char s1[MAXN], s2[MAXN], ans[MAXN]; 15 | while(scanf("%s%s", s1, s2) == 2) { 16 | int n = strlen(s1); 17 | build(n, s1, s2, ans); 18 | ans[n] = '\0'; 19 | printf("%s\n", ans); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/679.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | const int MAXD = 20; 4 | int s[1< n) break; 16 | } 17 | } 18 | printf("%d\n", k/2); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/679_uva.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int T, D, I; 4 | scanf("%d", &T); 5 | while(T--) { 6 | scanf("%d%d", &D, &I); 7 | int k = 1; 8 | for(int i = 0; i < D-1; i++) 9 | if(I%2) { k = k*2; I = (I+1)/2; } 10 | else { k = k*2+1; I /= 2; } 11 | printf("%d\n", k); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/679b.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int D, I; 4 | while(scanf("%d%d", &D, &I) == 2) { 5 | int k = 1; 6 | for(int i = 0; i < D-1; i++) 7 | if(I%2) { k = k*2; I = (I+1)/2; } 8 | else { k = k*2+1; I /= 2; } 9 | printf("%d\n", k); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/bw.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch6/bw.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/euler.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch6/euler.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/euler.in: -------------------------------------------------------------------------------- 1 | 10 12 2 | 0 1 3 | 1 2 4 | 0 3 5 | 1 4 6 | 2 5 7 | 3 4 8 | 4 5 9 | 6 1 10 | 6 7 11 | 8 4 12 | 8 9 13 | 7 9 14 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/list2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | const int MAXN = 1000; 3 | int n, left[MAXN], right[MAXN]; 4 | 5 | void link(int X, int Y) { 6 | right[X] = Y; left[Y] = X; 7 | } 8 | 9 | int main() { 10 | int m, X, Y; 11 | char type[9]; 12 | scanf("%d%d", &n, &m); 13 | for(int i = 1; i <= n; i++) { 14 | left[i] = i-1; right[i] = i+1; 15 | } 16 | for(int i = 0; i < m; i++) { 17 | scanf("%s%d%d", &type, &X, &Y); 18 | link(left[X], right[X]); 19 | if(type[0] == 'A') { 20 | link(left[Y], X); 21 | link(X, Y); 22 | } else { 23 | link(X, right[Y]); 24 | link(Y, X); 25 | } 26 | } 27 | for(int X = right[0]; X != n+1; X = right[X]) 28 | printf("%d ", X); 29 | printf("\n"); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/listgen.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int n = 100, m = 100000; 6 | 7 | double random() { 8 | return (double)rand() / RAND_MAX; 9 | } 10 | 11 | int random(int m) { 12 | return (int)(random() * (m-1) + 0.5); 13 | } 14 | 15 | int main() { 16 | srand(time(NULL)); 17 | printf("%d %d\n", n, m); 18 | for(int i = 0; i < m; i++) { 19 | if(rand() % 2 == 0) printf("A"); else printf("B"); 20 | int X, Y; 21 | for(;;) { 22 | X = random(n)+1; 23 | Y = random(n)+1; 24 | if(X != Y) break; 25 | } 26 | printf(" %d %d\n", X, Y); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/maze.in: -------------------------------------------------------------------------------- 1 | 6 5 0 0 0 4 2 | 1 1 0 1 1 3 | 1 0 1 1 1 4 | 1 0 1 0 0 5 | 1 0 1 1 1 6 | 1 1 1 0 1 7 | 1 1 1 1 1 8 | 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/readme.txt: -------------------------------------------------------------------------------- 1 | 第六章 数据结构基础 2 | 3 | 6.1 栈和队列 4 | 6.1.1 卡片游戏 10935.cpp(数组版, 故意留有bug), 10935b.cpp(STL版) 5 | 6.1.2 铁轨 514.cpp(数组版), 514b.cpp(STL版) 6 | 7 | 6.2 链表 list1.cpp(数组版), list2.cpp(链表版), listgen.cpp(数据生成器) 8 | 9 | 6.3 二叉树 10 | 6.3.1 小球下落 679.cpp(模拟版), 679b.cpp(数学版) 11 | 6.3.2 层次遍历 122.cpp(指针版), 122b.cpp(数组版) 12 | 6.3.3 二叉树重建 536.cpp 13 | 14 | 6.4 图 15 | 6.4.1 黑白图像 bw.cpp 16 | 6.4.2 走迷宫 maze.cpp(样例输入:maze.in) 17 | 6.4.3 拓扑排序 topo.cpp(样例输入:topo.in) 18 | 6.4.4 欧拉回路 euler.cpp(样例输入:euler.in) 19 | 20 | 所有以数字作为主文件名的程序都代表着UVa上的题号。 21 | 22 | 但需要注意的时候,有的题目在uva上的输入输出格式与书上不同,这些题目会有一个以_uva.cpp为后缀的代码,这个代码才对应uva的输入输出格式。 23 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch6/topo.in: -------------------------------------------------------------------------------- 1 | 4 3 2 | 0 1 3 | 2 1 4 | 3 2 5 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/129.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch7/129.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/129_uva.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch7/129_uva.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/524.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int is_prime(int x) { 6 | for(int i = 2; i*i <= x; i++) 7 | if(x % i == 0) return 0; 8 | return 1; 9 | } 10 | 11 | int main() { 12 | int n, A[50], isp[50]; 13 | scanf("%d", &n); 14 | for(int i = 2; i <= n*2; i++) isp[i] = is_prime(i); 15 | for(int i = 0; i < n; i++) A[i] = i+1; 16 | do { 17 | int ok = 1; 18 | for(int i = 0; i < n; i++) if(!isp[A[i]+A[(i+1)%n]]) { 19 | ok = 0; 20 | break; 21 | } 22 | if(ok) { 23 | for(int i = 0; i < n; i++) printf("%d ", A[i]); 24 | printf("\n"); 25 | } 26 | }while(next_permutation(A+1, A+n)); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/8a.in: -------------------------------------------------------------------------------- 1 | 2 6 4 1 3 7 0 5 8 2 | 8 1 5 7 3 6 4 0 2 3 | 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/8b.in: -------------------------------------------------------------------------------- 1 | 1 2 3 4 5 6 7 8 0 2 | 1 2 3 4 5 6 8 7 0 3 | 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/pp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch7/pp.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/pp2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch7/pp2.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/pp3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch7/pp3.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/queen.c: -------------------------------------------------------------------------------- 1 | #include 2 | int C[50], tot = 0, n = 8, nc = 0; 3 | 4 | void search(int cur) { 5 | int i, j; 6 | nc++; 7 | if(cur == n) { 8 | for(i = 0; i < n; i++) 9 | for(j = i+1; j < n; j++) 10 | if(C[i] == C[j] || i-C[i] == j-C[j] || i+C[i] == j+C[j]) return; 11 | tot++; 12 | } else for(i = 0; i < n; i++) { 13 | C[cur] = i; 14 | search(cur+1); 15 | } 16 | } 17 | 18 | int main() { 19 | search(0); 20 | printf("%d\n", tot); 21 | printf("%d\n", nc); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/queen2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int C[50], tot = 0, n = 8, nc = 0; 3 | 4 | void search(int cur) { 5 | int i, j; 6 | nc++; 7 | if(cur == n) { 8 | tot++; 9 | } else for(i = 0; i < n; i++) { 10 | int ok = 1; 11 | C[cur] = i; 12 | for(j = 0; j < cur; j++) 13 | if(C[cur] == C[j] || cur-C[cur] == j-C[j] || cur+C[cur] == j+C[j]) { 14 | ok = 0; 15 | break; 16 | } 17 | if(ok) search(cur+1); 18 | } 19 | } 20 | 21 | int main() { 22 | search(0); 23 | printf("%d\n", tot); 24 | printf("%d\n", nc); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/queen3.c: -------------------------------------------------------------------------------- 1 | #include 2 | int C[50], vis[3][50], tot = 0, n = 8, nc = 0; 3 | 4 | void search(int cur) { 5 | int i, j; 6 | nc++; 7 | if(cur == n) { 8 | tot++; 9 | } else for(i = 0; i < n; i++) { 10 | if(!vis[0][i] && !vis[1][cur+i] && !vis[2][cur-i+n]) { 11 | C[cur] = i; 12 | vis[0][i] = vis[1][cur+i] = vis[2][cur-i+n] = 1; 13 | search(cur+1); 14 | vis[0][i] = vis[1][cur+i] = vis[2][cur-i+n] = 0; 15 | } 16 | } 17 | } 18 | 19 | int main() { 20 | memset(vis, 0, sizeof(vis)); 21 | search(0); 22 | printf("%d\n", tot); 23 | printf("%d\n", nc); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/readme.txt: -------------------------------------------------------------------------------- 1 | 第七章 暴力求解法 2 | 3 | 7.2 枚举排列 4 | pp.cpp(无重复元素,递归) 5 | pp2.cpp(有重复元素,递归) 6 | pp3.cpp(有重复元素,STL) 7 | 8 | 7.3 子集生成 9 | 7.3.1 增量构造法 subset.cpp 10 | 7.3.2 位向量法 subset2.cpp 11 | 7.3.3 二进制法 subset3.cpp 12 | 13 | 7.4 回溯法 14 | 7.4.1 八皇后问题 queen.c(生成-测试法), queen2.c(回溯法), queen3.c(优化的回溯法) 15 | 7.4.2 素数环 524.cpp(生成-测试法), 524b.cpp(回溯法) 16 | 7.4.3 困难的串 129.cpp 17 | 18 | 7.5 隐式图搜索 19 | 7.5.2 倒水问题 water.cpp(书上无此代码) 20 | 7.5.3 八数码问题 21 | 8.cpp(STL集合+取值为int的单射) 22 | 8b.cpp(哈希表) 23 | 8c.cpp(全排列的编码/解码) 24 | 8d.cpp(STL集合+memcmp) 25 | 8a.in(有解输入数据), 8b.in(无解输入数据) 26 | 27 | 注意:为了比较queen2.c和queen3.c的时间效率,请调大n的值。 -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/subset.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch7/subset.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/subset2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch7/subset2.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch7/subset3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/bookcodes/ch7/subset3.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch8/bsearch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int A[] = {1,2,3,4,5,6,7,8,9,10,11}; 5 | 6 | int bsearch(int* A, int x, int y, int v) { 7 | int m = x + (y-x)/2; 8 | if(y <= x) return -1; 9 | if(A[m] == v) return m; 10 | else return A[m]>v ? bsearch(A,x,m,v) : bsearch(A,m+1,y,v); 11 | } 12 | 13 | int main() { 14 | int i; 15 | for(i = 1; i <= 11; i++) 16 | assert(bsearch(A, 0, 11, i) == i-1); 17 | printf("Ok!\n"); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch8/bsearch2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int A[] = {1,2,3,4,5,6,7,8,9,10,11}; 5 | 6 | int bsearch(int* A, int x, int y, int v) { 7 | int m; 8 | while(x < y) { 9 | m = x+(y-x)/2; 10 | if(A[m] == v) return m; 11 | else if(A[m] > v) y = m; 12 | else x = m+1; 13 | } 14 | return -1; 15 | } 16 | 17 | int main() { 18 | int i; 19 | for(i = 1; i <= 11; i++) 20 | assert(bsearch(A, 0, 11, i) == i-1); 21 | printf("Ok!\n"); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch8/inverse_pair.c: -------------------------------------------------------------------------------- 1 | #include 2 | void inverse_pair(int* A, int x, int y, int* cnt, int* T) { 3 | if(y-x > 1){ 4 | int m = x + (y-x)/2; 5 | int p = x, q = m, i = x; 6 | inverse_pair(A, x, m, cnt, T); 7 | inverse_pair(A, m, y, cnt, T); 8 | while(p < m || q < y) { 9 | if(q >= y || (p < m && A[p] <= A[q])) 10 | T[i++] = A[p++]; 11 | else { 12 | T[i++] = A[q++]; 13 | *cnt += m-p; 14 | } 15 | } 16 | for(i = x; i < y; i++) A[i] = T[i]; 17 | } 18 | } 19 | 20 | int A[] = {1,1,1,1,1,1,1,1,1}; 21 | int T[] = {0,0,0,0,0,0,0,0,0}; 22 | int main(){ 23 | int i, cnt = 0;; 24 | inverse_pair(A, 0, 9, &cnt, T); 25 | printf("%d\n", cnt); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch8/loan.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | double a, c, x = 0, y = 100; 4 | int i, b; 5 | scanf("%lf%d%lf", &a, &b, &c); 6 | while(y-x > 1e-5) { 7 | double m = x+(y-x)/2; 8 | double f = a; 9 | for(i = 0; i < b; i++) f += f*m/100.0-c; 10 | if(f < 0) x=m; else y=m; 11 | } 12 | printf("%.3lf%%\n", x); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch8/range.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int v[10000]; 5 | int main(){ 6 | int n, m, a, b; 7 | scanf("%d%d", &n, &m); 8 | for(int i = 0; i < n; i++) scanf("%d", &v[i]); 9 | sort(v, v+n); 10 | for(int i = 0; i < m; i++){ 11 | scanf("%d%d", &a, &b); 12 | printf("%d\n", upper_bound(v, v+n, b)-lower_bound(v, v+n, a)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch8/readme.txt: -------------------------------------------------------------------------------- 1 | 第八章 高效算法设计 2 | 3 | * 最大连续和合集 seq.c(C语言), seq.cpp(C++语言) 4 | * 归并排序 merge_sort.c(含测试代码) 5 | * 逆序对统计 inverse_pair.c 6 | * 二分查找 bsearch.c(递归), bsearch2.c(迭代), lbub.c(上界/下界) 7 | * 范围统计 range.cpp(STL) 8 | * 贷款 loan.c 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch9/knapsack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | #define MAXN 1000 6 | #define MAXC 100000 7 | int V[MAXN], W[MAXN]; 8 | int d[MAXN][MAXC]; 9 | 10 | int main() { 11 | int n, C; 12 | for(int i = 0; i < n; i++) 13 | scanf("%d%d", &V[i], &W[i]); 14 | 15 | for(int i = n; i >= 1; i--) 16 | for(int j = 0; j <= C; j++) { 17 | d[i][j] = (i==n ? 0 : d[i+1][j]); 18 | if(j >= V[i]) max(d[i][j], d[i+1][j-V[i]]+W[i]); 19 | } 20 | 21 | printf("%d\n", d[1][C]); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/ch9/readme.txt: -------------------------------------------------------------------------------- 1 | 第九章 动态规划初步 2 | 3 | * 嵌套矩形(记忆化搜索) 4 | box.cpp(输出字典序最小解) 5 | box2.cpp(输出所有解) 6 | 7 | * 硬币问题(递推) 8 | coin.cpp(根据指标函数重建方案) 9 | coin2.cpp(递推时保存最优决策) 10 | 11 | * 0-1背包问题 12 | knapsack.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/bookcodes/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 书上范例代码 4 | 5 | 6 | 更新历史 7 | 8 | 2012-10-11 9 | 加入第5~7章例题的uva版本代码 10 | 11 | 2012-9-10 12 | 修正代码与g++ 4.6.2的不兼容处 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-1.lisp: -------------------------------------------------------------------------------- 1 | (let ((a (read)) (b (read)) (c (read))) 2 | (format t "~,3F" (/ (+ a b c) 3))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-10.lisp: -------------------------------------------------------------------------------- 1 | (defun leap-year-p (year) 2 | (destructuring-bind (fh h f) 3 | (mapcar #'(lambda (n) (zerop (mod year n))) '(400 100 4)) 4 | (or fh (and (not h) f)))) 5 | 6 | (let ((n (read))) 7 | (format t "~D" (if (leap-year-p n) "yes" "no"))) 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-2.lisp: -------------------------------------------------------------------------------- 1 | (let ((f (read))) 2 | (format t "~,3F" (/ (* (- f 32) 5) 9))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-3.lisp: -------------------------------------------------------------------------------- 1 | (let ((n (read))) 2 | (format t "~D" (/ (* n (+ n 1)) 2))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-4.lisp: -------------------------------------------------------------------------------- 1 | (let* ((n (read)) (rad (/ (* n pi) 180))) 2 | (format t "~,3F ~,3F" (sin rad) (cos rad))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-5.lisp: -------------------------------------------------------------------------------- 1 | (let* ((x1 (read)) (y1 (read)) (x2 (read)) (y2 (read))) 2 | (format t "~,3F" (sqrt (+ (expt (- x1 x2) 2) (expt (- y1 y2) 2))))) 3 | 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-6.lisp: -------------------------------------------------------------------------------- 1 | (let ((n (read))) 2 | (format t "~D" (if (evenp n) "yes" "no"))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-7.lisp: -------------------------------------------------------------------------------- 1 | (let* ((n (read)) (money (* 95 n))) 2 | (format t "~,3F" (if (>= money 300) (* 0.85 money) money))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-8.lisp: -------------------------------------------------------------------------------- 1 | (let* ((x (read))) 2 | (format t "~,2F" (abs x))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/ex1-9.lisp: -------------------------------------------------------------------------------- 1 | (defun solve (a b c) 2 | (let* ((lst (sort (list a b c) #'<)) (a2 (first lst)) (b2 (second lst)) (c2 (third lst))) 3 | (cond ((= (+ (* a2 a2) (* b2 b2)) (* c2 c2)) "yes") 4 | ((<= (+ a2 b2) c2) "not a triangle") 5 | (t "no")))) 6 | 7 | (let ((a (read)) (b (read)) (c (read))) 8 | (format t "~A" (solve a b c))) 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/p1-1.lisp: -------------------------------------------------------------------------------- 1 | (let ((r (read)) (h (read))) 2 | (format t "Area = ~,3F" (+ (* pi r r 2) (* 2 pi r h)))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/p1-2.lisp: -------------------------------------------------------------------------------- 1 | (let ((x (read-line))) 2 | (format t "~A" (reverse x))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/p1-3.lisp: -------------------------------------------------------------------------------- 1 | (let ((x (read)) (y (read))) 2 | (format t "~A ~A" y x)) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/p1-4.lisp: -------------------------------------------------------------------------------- 1 | (defun solve (n m) 2 | (let* ((a (/ (- (* n 4) m) 2)) (b (- n a))) 3 | (if (or (oddp m) (< a 0) (< b 0)) 4 | "No answer" 5 | (format nil "~A ~A" a b)))) 6 | 7 | (let ((n (read)) (m (read))) 8 | (format t "~A" (solve n m))) 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/ch1/p1-5.lisp: -------------------------------------------------------------------------------- 1 | (let* ((a (read)) (b (read)) (c (read)) (lst (sort (list a b c) #'<))) 2 | (format t "~D ~D ~D" (car lst) (second lst) (third lst))) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/common_lisp/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》Common Lisp代码 2 | 3 | 刘汝佳 4 | 5 | 看过《黑客与画家》么?看过的话,相信你对Lisp还是会有点兴趣的 6 | 7 | Lisp的方言很多,但因为笔者是实用主义,最符合我个人胃口的是Common Lisp(我用vi远多于emacs,所以Emacs LISP我平时基本不用) 8 | 9 | 不过我倒是在工作中会用Lisp——AutoLISP(因为我们会编写AutoCAD插件) 10 | 11 | 那为什么要给本书的Common Lisp代码呢?因为笔者对Lisp有一种特殊的情结。 12 | 13 | 最早的时候是对SICP中这样一句话产生了兴趣:Lisp is for building organisms 14 | 15 | 如果你也对这句话很好奇,那就绝对不要错过Lisp :) 16 | 17 | 笔者的入门书籍是PG的《Ansi Common Lisp》,时间紧迫的读者也可以看《Common LISP Hints》来走马观花式的学学 :) 18 | 19 | 和Haskell一样,因为笔者也只是个实践经验很少的初学者,所以如果出现了什么非常土鳖的代码,还请高手门不要见笑,并且不吝赐教和指正 :) 20 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-1.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-10.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-10.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-2.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-3.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-3.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-4.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-4.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-5.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-5.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-6.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-6.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-7.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-7.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-8.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-8.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/ex1-9.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch1/ex1-9.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch1/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 第一章习题代码 4 | 5 | 10个习题都来自于书上。强烈建议读者自行编写程序之后再参考这些代码 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10006.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10006.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10079.cpp: -------------------------------------------------------------------------------- 1 | // UVa10079 Pizza Cutting 2 | // Rujia Liu 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | long long n; 8 | while(cin >> n && n >= 0) { 9 | cout << n*(n+1)/2+1 << "\n"; 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10105.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10105.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10157.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10157.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10183.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10183.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10219.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10219.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10277.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10277.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10303.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10303.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10359.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10359.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10375.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10375.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10516.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10516.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10519.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10519.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10673.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10673.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10717.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10717.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10721.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10721.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10791.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10791.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10820.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10820.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa10910.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa10910.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa11029.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa11029.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa11069.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa11069.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa11121.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa11121.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa128.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa128.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch10/UVa991.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch10/UVa991.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa10034.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa10034.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa10048.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa10048.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa10099.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa10099.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa10330.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa10330.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa10397.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa10397.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa10594.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa10594.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa10746.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa10746.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa10986.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa10986.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa558.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa558.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/UVa820.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch11/UVa820.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch11/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 第十一章习题代码 4 | 5 | 注意:有些题目并没有在书中出现,但是仍然有一定的启发意义,所以一并放在这里,供读者参考。 6 | 7 | 所有代码中都写了题目大意。 8 | 9 | UVa10034 Freckles 最小生成树 10 | UVa10397 Connect the Campus 最小生成树 11 | UVa10048 Audiophobia Floyd算法变形 12 | UVa10099 The Tourist Guide Floyd算法变形 13 | UVa10986 Sending email Dijkstra 14 | UVa558 Wormholes Bellman-Ford找负圈 15 | UVa820 Internet Bandwidth 最大流 16 | UVa10330 Power Transmission 最大流,拆点 17 | UVa10594 Data Flow 最小费用最大流 18 | UVa10746 Crime Wave - The Sequel 二分图最小权匹配(用最小费用最大流实现) 19 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-1.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-10.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-10.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-2.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-3.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-3.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-4.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-4.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-5.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-5.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-6.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-6.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-7.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-7.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-8.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-8.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/ex2-9.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch2/ex2-9.c -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 第一章习题代码 4 | 5 | 10个习题都来自于书上。强烈建议读者自行编写程序之后再参考这些代码 6 | 7 | 虽然书上说的要用文件输入输出,但为了和其他题目统一,这里除了第5题外均使用了标准输入输出 8 | 9 | 为什么第5题要用文件输入?因为第二章还没有介绍数组,而只处理一次输入是不足以完成统计的 10 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/stat.in: -------------------------------------------------------------------------------- 1 | 8 3 6 5 4 9 1 12 8 6 2 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch2/stat.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10014.cpp: -------------------------------------------------------------------------------- 1 | // UVa10014 Simple calculations 2 | // Rujia Liu 3 | // 题意:已知a[i]=(a[i-1]+a[i+1])/2-c[i]。输入a[0], a[n+1]和c[1~n],求a[1] 4 | // 算法:n个未知数(a[1~n])和n个方程,手工消元可以直接解出a[1]的表达式 5 | // 具体消元方法很多人的blog都有写,请自行搜索之 :) 6 | // 表达式:a[1] = (n*a[0]+a[n+1]-2*sum{(n+1-i)c[i]}) / (n+1) 7 | 8 | #include 9 | int main() { 10 | int T; 11 | scanf("%d", &T); 12 | while(T--) { 13 | int n; 14 | double a0, an1, c; 15 | scanf("%d%lf%lf", &n, &a0, &an1); 16 | double sum = n*a0 + an1; 17 | for(int i = 1; i <= n; i++) { 18 | scanf("%lf", &c); 19 | sum -= (n+1-i) * c * 2; 20 | } 21 | printf("%.2lf\n", sum / (n+1)); 22 | if(T) printf("\n"); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10110.cpp: -------------------------------------------------------------------------------- 1 | // UVa10110 Light, more light 2 | // Rujia Liu 3 | // 题意:经典的开灯问题,即判断n是否为完全平方数 4 | 5 | #include 6 | #include 7 | 8 | int main() { 9 | long long n; 10 | while(scanf("%lld", &n) == 1 && n) { 11 | long long s = floor(sqrt(n) + 0.5); 12 | if(s*s == n) printf("yes\n"); else printf("no\n"); // 注意如果s是int类型,s*s可能会溢出 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10250.cpp: -------------------------------------------------------------------------------- 1 | // UVa10250 The Other Two Trees 2 | // Rujia Liu 3 | // 题意:输入正方形两个对角顶点P1, P2,求另外两个点的坐标 4 | // 算法:先求中点O,然后分别把向量P1-O逆时针旋转90度和-90度,与O相加 5 | // 向量(vx,vy)逆时针旋转90度为(-vy,vx),顺时针转90度为(vy,-vx) 6 | #include 7 | int main() { 8 | double x1, y1, x2, y2; 9 | while(scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2) == 4) { 10 | if(x1 == x2 && y1 == y2) printf("Impossible.\n"); 11 | else { 12 | double ox = (x1 + x2) / 2, oy = (y1 + y2) / 2; // 中点 13 | double vx = x1 - ox, vy = y1 - oy; // 向量v = p1 - o 14 | printf("%.10lf %.10lf %.10lf %.10lf\n", ox-vy, oy+vx, ox+vy, oy-vx); 15 | } 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10387.cpp: -------------------------------------------------------------------------------- 1 | // UVa10387 Billiard 2 | // Rujiu Liu 3 | // 题意:a*b的矩形中心有一个球,沿着某方向匀速运动,s秒后回到中点,途中和左右边界碰撞m次、和上下边界碰撞n次。碰撞时遵守反射定律,没有能量损失。求速度的极角和大小 4 | // 算法:分开计算速度的水平和竖直分量即可。比如水平方向走了m个来回,因此距离为a*m,除以时间s,得到水平方向速度am/s 5 | #include 6 | #include 7 | const double PI = acos(-1.0); 8 | int main() { 9 | int a, b, s, m, n; 10 | while(scanf("%d%d%d%d%d", &a, &b, &s, &m, &n) == 5 && a) { 11 | double vx = (double)a * m / s, vy = (double)b * n / s; 12 | printf("%.2lf %.2lf\n", atan2(vy, vx) / PI * 180, sqrt(vx*vx+vy*vy)); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10392.cpp: -------------------------------------------------------------------------------- 1 | // UVa10392 Factoring Large Numbers 2 | // Rujia Liu 3 | // 题意:分解素因子。输入64位带符号整数,保证最多只有一个因子超过10^6 4 | // 算法:直接枚举因子 5 | #include 6 | #include 7 | int main() { 8 | long long n; 9 | while(scanf("%lld", &n) == 1 && n >= 0) { 10 | long long limit = floor(sqrt(n) + 0.5); 11 | if(limit > 1000000) limit = 1000000; 12 | for(int i = 2; i <= limit; i++) 13 | while(n % i == 0) { printf(" %d\n", i); n /= i; } 14 | if(n > 1) printf(" %lld\n", n); 15 | printf("\n"); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10420.cpp: -------------------------------------------------------------------------------- 1 | // UVa10420 List of Conquests 2 | // Rujia Liu 3 | // 题意:输入n行,每行为一个国家名和一个人名。要求统计每个国家的人数,按国家名字字典序输出 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | const int maxn = 100; 11 | char line[maxn], country[maxn]; 12 | map cnt; 13 | 14 | int main() { 15 | int n; 16 | scanf("%d\n", &n); 17 | while(n--) { 18 | fgets(line, maxn, stdin); 19 | sscanf(line, "%s", country); 20 | string c = country; 21 | if(!cnt.count(c)) cnt[c] = 0; 22 | cnt[c]++; 23 | } 24 | for(map::iterator it = cnt.begin(); it != cnt.end(); ++it) { 25 | printf("%s %d\n", it->first.c_str(), it->second); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10474.cpp: -------------------------------------------------------------------------------- 1 | // UVa10474 Where is the Marble? 2 | // Rujia Liu 3 | // 题意:输入n个正整数,从小到大排序 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | const int maxn = 10000; 10 | 11 | int main() { 12 | int n, q, x, a[maxn], kase = 0; 13 | while(scanf("%d%d", &n, &q) == 2 && n) { 14 | printf("CASE# %d:\n", ++kase); 15 | for(int i = 0; i < n; i++) scanf("%d", &a[i]); 16 | sort(a, a+n); 17 | while(q--) { 18 | scanf("%d", &x); 19 | int p = lower_bound(a, a+n, x) - a; 20 | if(a[p] == x) printf("%d found at %d\n", x, p+1); 21 | else printf("%d not found\n", x); 22 | } 23 | } 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10499.cpp: -------------------------------------------------------------------------------- 1 | // UVa10499 The Land of Justice 2 | // Rujia Liu 3 | // 题意:把球均分成n分,表面积增加了百分之多少? 4 | // 算法:球的表面积为4*pi*r^2,切割之后每一块的总侧面积为pi*r^2。把pi*r^2提出来,相当于原来是4,增加了n,除非n=1 5 | #include 6 | int main() { 7 | int n; 8 | while(scanf("%d", &n) == 1 && n >= 0) { 9 | printf("%lld%%\n", n == 1 ? 0 : 25LL*n); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10790.cpp: -------------------------------------------------------------------------------- 1 | // UVa10790 How Many Points of Intersection? 2 | // Rujia Liu 3 | // 题意:两条平行直线,上面有a个点,下面有b个点。两两连接之后最多会有多少个交点? 4 | // 算法:上面第i个点和下面第j个点组成的线段与哪些线段相交呢?上端点一定是第i个点左边(i-1种),下端点一定是第j个点右边(b-j种),求和整理即可 5 | 6 | #include 7 | int main() { 8 | int kase = 0, a, b; 9 | while(scanf("%d%d", &a, &b) == 2 && a) 10 | printf("Case %d: %lld\n", ++kase, (long long)a*(a-1)*b*(b-1)/4); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10815.cpp: -------------------------------------------------------------------------------- 1 | // UVa10815 Andy's First Dictionary 2 | // Rujia Liu 3 | // 题意:输入一个文本,找出所有不同的单词(连续字母序列),按字典序从小到大输出。单词不分大小写。 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | set dict; 11 | string s, buf; 12 | 13 | int main() { 14 | while(cin >> s) { 15 | for(int i = 0; i < s.length(); i++) 16 | if(isalpha(s[i])) s[i] = tolower(s[i]); else s[i] = ' '; 17 | stringstream ss(s); 18 | while(ss >> buf) dict.insert(buf); 19 | } 20 | for(set::iterator it = dict.begin(); it != dict.end(); ++it) 21 | cout << *it << "\n"; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10879.cpp: -------------------------------------------------------------------------------- 1 | // UVa10879 Code Refactoring 2 | // Rujia Liu 3 | // 题意:输入正整数n,找出四个不同的正整数a, b, c, d使得n=a*b=c*d 4 | // 算法:直接枚举因子 5 | #include 6 | int main() { 7 | int T, n, kase = 0; 8 | scanf("%d", &T); 9 | while(T--) { 10 | scanf("%d", &n); 11 | int a = 0, c = 0; 12 | for(int i = 2; i <= n; i++) 13 | if(n % i == 0) { 14 | if(!a) a = i; else c = i; 15 | if(c) break; 16 | } 17 | printf("Case #%d: %d = %d * %d = %d * %d\n", ++kase, n, a, n/a, c, n/c); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10916.cpp: -------------------------------------------------------------------------------- 1 | // UVa10916 Factstone Benchmark 2 | // Rujia Liu 3 | // 题意:假设计算机字长10年翻一翻,比如1960是4-bit, 1970是8-bit, ..., 2000是64-bit。输入年份,求最大的n使得最新计算机的字长可以装下n! 4 | // 算法:枚举即可,用对数判断 5 | 6 | #include 7 | #include 8 | 9 | // 求最大的n使得n!<=2^(2^k),即sum{log(i)} <= 2^k * log(2) 10 | int solve(int k) { 11 | double M = pow(2, k), sum = 0; 12 | for(int i = 1; ; i++) { 13 | sum += log(i); 14 | if(sum > M * log(2)) return i-1; 15 | } 16 | } 17 | 18 | int main() { 19 | int y; 20 | while(scanf("%d", &y) == 1 && y) printf("%d\n", solve(y/10 - 194)); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa10970.cpp: -------------------------------------------------------------------------------- 1 | // UVa10970 Big Chocolate 2 | // Rujia Liu 3 | // 题意:m*n的巧克力,至少切几刀能切成m*n个1*1的巧克力?每次只能把一块切成两块 4 | // 算法:切一刀多一块,一共多了m*n-1块,所以... 5 | 6 | #include 7 | int main() { 8 | int m, n; 9 | while(scanf("%d%d", &m, &n) == 2) printf("%d\n", m*n-1); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa11044.cpp: -------------------------------------------------------------------------------- 1 | // UVa11044 Searching for Nessy 2 | // Rujia Liu 3 | // 题意:最少用多少个3x3棋盘覆盖nxm棋盘?边界格子不用覆盖 4 | // 算法:实际只需要覆盖(n-2)*(m-2),行需要((n-2)-1)/3+1个,化简为n/3,列需要m/3个,相乘即可 5 | 6 | #include 7 | int main() { 8 | int T, n, m; 9 | scanf("%d", &T); 10 | while(T--) { 11 | scanf("%d%d", &n, &m); 12 | printf("%d\n", (n/3)*(m/3)); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa113.cpp: -------------------------------------------------------------------------------- 1 | // UVa113 Power of Cryptography 2 | // Rujia Liu 3 | // 输入n和p,求p的n次方根。输出保证为1~10^9的整数 4 | // 算法:题目给出的范围在double之内,直接用库函数求即可 5 | #include 6 | #include 7 | 8 | int main() { 9 | double n, p; 10 | while(scanf("%lf%lf", &n, &p) == 2) 11 | printf("%.0lf\n", pow(p, 1 / n)); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa299.cpp: -------------------------------------------------------------------------------- 1 | // UVa299 Train Swapping 2 | // Rujia Liu 3 | // 题意:输入n的一个全排列,每次可以交换相邻两个数,最少要几次才能变成升序排列? 4 | // 算法:逆序对数 5 | #include 6 | const int maxn = 100; 7 | int main() { 8 | int T, n, a[maxn]; 9 | scanf("%d", &T); 10 | while(T--) { 11 | scanf("%d", &n); 12 | for(int i = 0; i < n; i++) scanf("%d", &a[i]); 13 | int cnt = 0; 14 | for(int i = 0; i < n; i++) 15 | for(int j = i+1; j < n; j++) if(a[i] > a[j]) cnt++; 16 | printf("Optimal train swapping takes %d swaps.\n", cnt); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa350.cpp: -------------------------------------------------------------------------------- 1 | // UVa350 Pseudo-Random Numbers 2 | // Rujia Liu 3 | // 题意:一种伪随机数发生器是利用递推式L' = (Z*L+I) mod M。输入Z, I, M, L,输出循环节长度 4 | // 例如Z=7,I=5,M=12,L=4,产生序列为4, 9, 8, 1, 0, 5, 4, 9, ..., 答案为6 5 | // 算法:注意到M<10000,直接用vis[x]表示x首次出现的位置 6 | 7 | #include 8 | #include 9 | const int maxn = 10000 + 5; 10 | int vis[maxn]; 11 | 12 | int main() { 13 | int kase = 0, Z, I, M, L; 14 | while(scanf("%d%d%d%d", &Z, &I, &M, &L) == 4 && M) { 15 | memset(vis, 0, sizeof(vis)); 16 | vis[L] = 1; 17 | for(int i = 1; ; i++) { 18 | L = (Z*L + I) % M; 19 | if(vis[L]) { printf("Case %d: %d\n", ++kase, i - vis[L] + 1); break; } 20 | vis[L] = i+1; 21 | } 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa375.cpp: -------------------------------------------------------------------------------- 1 | // UVa375 Inscribed Circles and Isosceles Triangles 2 | // Rujia Liu 3 | // 题意:输入一个等腰三角形的底和高,从下往上连续画内切圆,直到半径小于给定值,求所有内切圆的周长和 4 | // 算法:每画一个圆,在上方做一条切线,则问题转化为了一个较小的等腰三角形 5 | #include 6 | #include 7 | const double PI = acos(-1.0); 8 | 9 | double solve(double B, double H) { 10 | double ang = atan(H/(B/2)), R = tan(ang/2) * B/2; // ang为腰和底的夹角 11 | if(R < 1e-6) return 0; 12 | return 2*PI*R + solve(B*(H-2*R)/H, H-2*R); // 根据相似三角形的比例计算新等腰三角形的底和高 13 | } 14 | 15 | int main() { 16 | int T; 17 | scanf("%d", &T); 18 | while(T--) { 19 | double B, H; 20 | scanf("%lf%lf", &B, &H); 21 | printf("%13.6lf\n", solve(B, H)); 22 | if(T) printf("\n"); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa408.cpp: -------------------------------------------------------------------------------- 1 | // UVa408 Uniform Generator 2 | // Rujia Liu 3 | // 题意: 4 | // 一种伪随机数生成方法是利用递推式 seed(x+1) = [seed(x) + STEP)%MOD。 5 | // 输入STEP和MOD,判断随机数出现循环之前是否可以遍历0~MOD-1的所有数 6 | // 比如STEP = 3, MOD = 5,生成的随机数为0, 3, 1, 4, 2, 0, 3, 1, 4, 2, ... 符合要求 7 | // 再比如STEP = 15, MOD = 20,生成的随机数为0, 15, 10, 5, ... 不符合要求 8 | // 算法:分析可知当且仅当STEP, MOD互素的时候符合要求 9 | 10 | #include 11 | 12 | int gcd(int a, int b) { 13 | return b == 0 ? a : gcd(b, a%b); 14 | } 15 | 16 | int main() { 17 | int a, b; 18 | while(scanf("%d%d", &a, &b) == 2) { 19 | printf("%10d%10d ", a, b); 20 | if(gcd(a, b) == 1) printf("Good"); else printf("Bad"); 21 | printf(" Choice\n\n"); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa465.cpp: -------------------------------------------------------------------------------- 1 | // UVa465 Overflow 2 | // Rujia Liu 3 | // 题意:输入两个非负整数a, b,判断a, b, a+b或者a*b是否溢出 4 | // 算法:直接作为double输入 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | const double BIG = 2147483647; // 2^31-1 12 | 13 | int main() { 14 | string s, op; 15 | while(getline(cin, s)) { 16 | stringstream ss(s); 17 | double a, b; 18 | ss >> a >> op >> b; 19 | double result = (op[0] == '+' ? a + b : a * b); 20 | cout << s << "\n"; 21 | if(a > BIG) cout << "first number too big\n"; 22 | if(b > BIG) cout << "second number too big\n"; 23 | if(result > BIG) cout << "result too big\n"; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa568.cpp: -------------------------------------------------------------------------------- 1 | // UVa568 Just the Facts 2 | // Rujia Liu 3 | // 题意:输入整数0<=n<=10000,输出n!最右的非零数字 4 | // 算法:预处理时用递推计算出所有结果。因为范围n<=10000比较小,保留结果的最后5位数字即可。 5 | 6 | #include 7 | const int maxn = 10001; 8 | int ans[maxn]; 9 | 10 | int main() { 11 | ans[0] = 1; 12 | for(int i = 1; i < maxn; i++) { 13 | ans[i] = ans[i-1] * i; 14 | while(ans[i] % 10 == 0) ans[i] /= 10; 15 | ans[i] %= 100000; // 不能只保留个位数(想一想,为什么) 16 | } 17 | int n; 18 | while(scanf("%d", &n) == 1) 19 | printf("%5d -> %d\n", n, ans[n] % 10); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa573.cpp: -------------------------------------------------------------------------------- 1 | // UVa573 The Snail 2 | // Rujia Liu 3 | // 题意:输入H, U, D, F,有一堵高度为H的墙,蜗牛第一天爬U米,后面每天少爬前一天U*F%,每天固定下滑D米,问第几天爬上来(高度>H)或者失败(高度<0)。 4 | // 算法:模拟 5 | 6 | #include 7 | int main() { 8 | double H, U, D, F; 9 | while(scanf("%lf%lf%lf%lf", &H, &U, &D, &F) == 4 && H) { 10 | double p = 0, loss = U*F/100; 11 | for(int day = 1; ; day++) { 12 | if(U > 0) p += U; 13 | U -= loss; 14 | if(p > H) { printf("success on day %d\n", day); break; } 15 | p -= D; 16 | if(p < 0) { printf("failure on day %d\n", day); break; } 17 | } 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa575.cpp: -------------------------------------------------------------------------------- 1 | // UVa575 Skew Binary 2 | // Rujia Liu 3 | // 题意:输入一个Skew Binary,转化成10进制。Skew Binary的右数第k位(k>=0)代表2^(k+1)-1 4 | 5 | #include 6 | #include 7 | const int maxn = 100; 8 | 9 | int main() { 10 | char s[maxn]; 11 | while(scanf("%s", s) == 1) { 12 | int n = strlen(s); 13 | if(n == 1 && s[0] == '0') break; 14 | long long v = 0; 15 | for(int k = 0; k < n; k++) 16 | v += (s[n-1-k] - '0') * ((1<<(k+1)) - 1); 17 | printf("%lld\n", v); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa579.cpp: -------------------------------------------------------------------------------- 1 | // UVa579 ClockHands 2 | // Rujia Liu 3 | // 题意:注意题目最后一段的开头:The history of clocks is fascinating, but unrelated to this problem,所以前面都不用读。 4 | // 输入时间,求时针和分针的夹角(转化为最小正数)。注意,时针是连续的走(每小时1格,则每分钟1/60格,即0.5度) 5 | // 算法:a点b分,时针的极角为a*30+b*0.5,分针的极角为6*b 6 | #include 7 | int main() { 8 | int a, b; 9 | while(scanf("%d:%d", &a, &b) == 2 && (a || b)) { 10 | double d = a*30+b*0.5 - 6*b; 11 | if(d < 0) d = -d; // 调整为正数 12 | if(360 - d < d) d = 360 - d; // 变小 13 | printf("%.3lf\n", d); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch5/UVa591.cpp: -------------------------------------------------------------------------------- 1 | // UVa591 Box of Bricks 2 | // Rujia Liu 3 | // 题意:有n列砖,第i列有h[i]个砖。总砖数是n的整数倍。最少移动多少块砖,使得每列砖的个数相同? 4 | // 算法:贪心。先算平均数,所有多的砖都拿出来,补齐剩下的 5 | 6 | #include 7 | const int maxn = 50 + 5; 8 | int h[maxn]; 9 | 10 | int main() { 11 | int kase = 0, n; 12 | while(scanf("%d", &n) == 1 && n) { 13 | int sum = 0; 14 | for(int i = 0; i < n; i++) { 15 | scanf("%d", &h[i]); 16 | sum += h[i]; 17 | } 18 | int avg = sum / n, ans = 0; 19 | for(int i = 0; i < n; i++) 20 | if(h[i] > avg) ans += h[i] - avg; 21 | printf("Set #%d\nThe minimum number of moves is %d.\n\n", ++kase, ans); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa10004.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa10004.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa10050.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa10050.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa101.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa101.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa10129.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa10129.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa10305.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa10305.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa10562.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa10562.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa127.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa127.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa133.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa133.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa297.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa297.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa439.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa439.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa442.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa442.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa532.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa532.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa540.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa540.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa548.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa548.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa572.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa572.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa657.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa657.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa673.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa673.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa699.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa699.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa712.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa712.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa784.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa784.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/UVa839.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/UVa839.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/uva10047.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/uva10047.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch6/uva10054.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch6/uva10054.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa10098.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa10098.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa10344.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa10344.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa10422.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa10422.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa11205.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa11205.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa11218.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa11218.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa140.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa140.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa146.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa146.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa167.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa167.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa193.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa193.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa208.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa208.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa216.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa216.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa301.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa301.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa331.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa331.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa387.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa387.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa539.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa539.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa565.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa565.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa729.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa729.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa729b.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa729b.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/UVa729c.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch7/UVa729c.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch7/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 第七章习题代码 4 | 5 | 注意:有些题目并没有在书中出现,但是仍然有一定的启发意义,所以一并放在这里,供读者参考。 6 | 7 | 所有代码中都写了题目大意。 8 | 9 | 基础题目 10 | UVa146 ID Codes 11 | UVa10098 Generating Fast, Sorted Permutation 12 | UVa11205 The Broken Pedometer 13 | UVa729 The Hamming Distance Problem 包含三种解法 14 | UVa11218 KTV 15 | UVa167 The Sultan's Successors 16 | UVa140 Bandwidth 17 | 18 | 回溯法(基础) 19 | UVa216 Getting in Line 20 | UVa10344 23 Out of 5 21 | UVa331 Mapping the Swaps 22 | UVa539 The Settlers of Catan 23 | UVa301 Transportation 24 | UVa208 Firetruck 25 | UVa193 Graph Coloring 26 | 27 | 回溯法(提高) 28 | UVa387 A Puzzling Problem 29 | UVa565 Pizza Anyone? 30 | 31 | 状态空间搜索 32 | UVa10422 Knights in FEN 采用IDA*算法而非BFS 33 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10026.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10026.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10041.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10041.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10340.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10340.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10391.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10391.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10487.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10487.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10670.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10670.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10700.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10700.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10714.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10714.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10718.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10718.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10763.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10763.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa108.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa108.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10905.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10905.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa10954.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa10954.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa11054.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa11054.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa11100.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa11100.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa270.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa270.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/UVa507.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch8/UVa507.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch8/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 第八章习题代码 4 | 5 | 注意:有些题目并没有在书中出现,但是仍然有一定的启发意义,所以一并放在这里,供读者参考。 6 | 7 | 所有代码中都写了题目大意。 8 | 9 | UVa11100 The Trip, 2007 10 | UVa10905 Children's Game 11 | UVa10718 Bit Mask 12 | UVa11054 Wine trading in Gergovia 13 | UVa10954 Add All 14 | UVa10763 Foreign Exchange 15 | UVa10340 All in All 16 | UVa10391 Compound Words 17 | UVa10487 Closest Sums 18 | UVa270 Lining Up 19 | UVa10714 Ants 20 | UVa10041 Vito's Family 21 | UVa10026 Shoemaker's Problem 22 | UVa10670 Work Reduction 23 | UVa10700 Camel trading 24 | UVa108 Maximum Sum 25 | UVa507 Jill Rides Again 26 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10003.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10003.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10066.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10066.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10069.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10069.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10131.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10131.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10192.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10192.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10285.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10285.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa103.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa103.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10304.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10304.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10405.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10405.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10617.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10617.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa10739.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa10739.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa111.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa111.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa116.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa116.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa147.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa147.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa348.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa348.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa357.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa357.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa437.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa437.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa531.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa531.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa562.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa562.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa590.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa590.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa624.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa624.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa674.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa674.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/ch9/UVa825.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/ch9/UVa825.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》习题相关代码 2 | 3 | 为了进一步帮助初学者学习,这里给出了一些习题的代码 4 | 5 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa10055.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/warmup/UVa10055.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa10071.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/warmup/UVa10071.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa10300.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/warmup/UVa10300.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa414.cpp: -------------------------------------------------------------------------------- 1 | // UVa414 Machined Surfaces 2 | // Rujia Liu 3 | #include 4 | #include 5 | const int maxn = 30; 6 | char line[maxn]; 7 | 8 | int main() { 9 | int n; 10 | while(scanf("%d\n", &n) == 1 && n) { 11 | int tot = 0, mincnt = maxn; 12 | for(int i = 0; i < n; i++) { 13 | fgets(line, maxn, stdin); 14 | int cnt = 0; 15 | for(int j = 0; j < strlen(line); j++) 16 | if(line[j] == ' ') cnt++; 17 | tot += cnt; 18 | if(cnt < mincnt) mincnt = cnt; 19 | } 20 | printf("%d\n", tot - mincnt * n); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa445.cpp: -------------------------------------------------------------------------------- 1 | // UVa445 Marvelous Mazes 2 | // Rujia Liu 3 | #include 4 | #include 5 | #include 6 | const int maxn = 10000; 7 | char line[maxn]; 8 | int cnt; 9 | 10 | void print(int ch, int x) { 11 | while(x--) printf("%c", ch); 12 | cnt = 0; 13 | } 14 | 15 | int main() { 16 | while(fgets(line, maxn, stdin) != NULL) { 17 | int len = strlen(line); 18 | cnt = 0; 19 | for(int i = 0; i < len; i++) 20 | if(isdigit(line[i])) cnt += line[i] - '0'; 21 | else if(line[i] == '!') print('\n', 1); 22 | else if(line[i] == 'b') print(' ', cnt); 23 | else print(line[i], cnt); 24 | printf("\n"); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa457.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/warmup/UVa457.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa458.cpp: -------------------------------------------------------------------------------- 1 | // UVa458 The Decoder 2 | // Rujia Liu 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | string s; 9 | while(cin >> s) { 10 | for(int i = 0; i < s.length(); i++) s[i] -= 7; 11 | cout << s << "\n"; 12 | } 13 | return 0; 14 | } -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa488.cpp: -------------------------------------------------------------------------------- 1 | // UVa488 Triangle Wave 2 | // Rujia Liu 3 | #include 4 | 5 | int main() { 6 | int T; 7 | scanf("%d", &T); 8 | while(T--) { 9 | int a, f; 10 | scanf("%d%d", &a, &f); 11 | while(f--) { 12 | for(int i = 1; i <= a*2-1; i++) { 13 | int cnt = (i <= a ? i : a*2-i); 14 | for(int j = 0; j < cnt; j++) printf("%d", cnt); 15 | printf("\n"); 16 | } 17 | if(f) printf("\n"); 18 | } 19 | if(T) printf("\n"); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa490.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/warmup/UVa490.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa494.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/BeginningAlgorithmContests/exercises/warmup/UVa494.cpp -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/UVa694.cpp: -------------------------------------------------------------------------------- 1 | // UVa694 The Collatz Sequence 2 | // Rujia Liu 3 | #include 4 | int solve(int a, int limit) { 5 | int cnt = 1; 6 | while(a != 1) { 7 | if(a % 2 == 0) a /= 2; 8 | else { 9 | long long tmp = (long long)a * 3 + 1; 10 | if(tmp > limit) break; 11 | a = tmp; 12 | } 13 | cnt++; 14 | } 15 | return cnt; 16 | } 17 | 18 | int main() { 19 | int a, limit, kase = 0; 20 | while(scanf("%d%d", &a, &limit) == 2 && a > 0) { 21 | printf("Case %d: A = %d, limit = %d, number of terms = %d\n", ++kase, a, limit, solve(a, limit)); 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /BeginningAlgorithmContests/exercises/warmup/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 热身代码 4 | 5 | 注意:有些题目并没有在书中出现,但是仍然有一定的启发意义,所以一并放在这里,供读者参考。 6 | 7 | UVa10055 Hashmat the brave warrior 8 | UVa10071 Back to High School Physics 9 | UVa10300 Ecological Premium 10 | UVa458 The Decoder 11 | UVa494 Kindergarten Counting Game 12 | UVa414 Machined Surfaces 13 | UVa490 Rotating Sentences 14 | UVa445 Marvelous Mazes 15 | UVa488 Triangle Wave 16 | UVa489 Hangman Judge 17 | UVa694 The Collatz Sequence 18 | UVa457 Linear Cellular Automata 19 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-1.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | main = do 4 | line <- getLine 5 | let arr = (map read $ words line) :: [Double] 6 | putStrLn . printf "%.3f" $ sum arr / 3 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-10.hs: -------------------------------------------------------------------------------- 1 | import Data.Time.Calendar.OrdinalDate 2 | 3 | main = do 4 | line <- getLine 5 | let year = read line :: Integer 6 | putStrLn $ if (isLeapYear year) then "yes" else "no" 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-2.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | main = do 4 | line <- getLine 5 | let f = read line :: Double 6 | putStrLn . printf "%.3f" $ 5*(f-32)/9 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-3.hs: -------------------------------------------------------------------------------- 1 | main = do 2 | line <- getLine 3 | let n = read line :: Int 4 | print $ n*(n+1) `div` 2 5 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-4.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | main = do 4 | line <- getLine 5 | let n = read line :: Double 6 | rad = n / 180.0 * pi 7 | putStrLn $ printf "%.3f %.3f" (sin rad) (cos rad) 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-5.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | main = do 4 | line <- getLine 5 | let x1:y1:x2:y2:_ = (map read $ words line) :: [Double] 6 | putStrLn $ printf "%.3f" $ sqrt $ (x1-x2)^2+(y1-y2)^2 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-6.hs: -------------------------------------------------------------------------------- 1 | main = do 2 | line <- getLine 3 | let n = read line :: Int 4 | putStrLn $ if (even 1) then "yes" else "no" 5 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-7.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | main = do 4 | line <- getLine 5 | let money = (read line :: Double) * 95.0 6 | putStrLn $ printf "%.2f" $ if money < 300 then money else money * 0.85 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-8.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | main = do 4 | line <- getLine 5 | putStrLn $ printf "%.2f" $ abs (read line :: Double) 6 | 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/ex1-9.hs: -------------------------------------------------------------------------------- 1 | main = do 2 | line <- getLine 3 | let a:b:c:_ = (map read $ words line) :: [Int] 4 | putStrLn $ solve a b c where 5 | solve a b c 6 | | a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a = "yes" 7 | | a+b<=c || a+c<=b || b+c<=a = "not a triangle" 8 | | otherwise = "no" 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/p1-1.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | main = do 4 | line <- getLine 5 | let r:h:_ = (map read $ words line) :: [Double] 6 | putStrLn . printf "Area = %.3f" $ pi*r*r*2+2*pi*r*h 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/p1-2.hs: -------------------------------------------------------------------------------- 1 | main = do 2 | line <- getLine 3 | putStrLn . reverse $ line 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/p1-3.hs: -------------------------------------------------------------------------------- 1 | main = do 2 | line <- getLine 3 | putStrLn . unwords . reverse . words $ line 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/p1-4.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | solve :: Int -> Int -> String 4 | solve n m = 5 | if m `mod` 2 == 1 || a < 0 || b < 0 6 | then "No answer" 7 | else printf "%d %d" a b 8 | where 9 | a = (4*n-m) `div` 2 10 | b = n-a 11 | 12 | main = do 13 | line <- getLine 14 | let n:m:_ = (map read $ words line) :: [Int] 15 | putStrLn $ solve n m 16 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/p1-5.hs: -------------------------------------------------------------------------------- 1 | import Data.List 2 | 3 | main = do 4 | line <- getLine 5 | let a = (sort . map read $ words line) :: [Int] 6 | putStrLn . unwords $ map show a 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch1/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 第一章 Haskell 4 | 5 | 包括5个例题和10道习题代码 6 | 7 | 注意:这些Haskell代码并不受“目前为止书上还没有介绍xx知识点,因此不能在代码中使用”的限制 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/ex2-1.hs: -------------------------------------------------------------------------------- 1 | import qualified Data.Text as T 2 | 3 | main = do 4 | line <- getLine 5 | let n = T.strip . T.pack $ line 6 | print $ T.length n 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/ex2-10.hs: -------------------------------------------------------------------------------- 1 | import Control.Monad 2 | import Text.Printf 3 | import Data.List 4 | 5 | isSolution :: Int -> Bool 6 | isSolution x = (sort big) == "123456789" where 7 | big = (show x) ++ (show $ x*2) ++ (show $ x*3) 8 | 9 | main = do 10 | forM_ (filter isSolution [123..329]) (\i -> do 11 | putStrLn $ printf "%d %d %d" i (i*2) (i*3)) 12 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/ex2-2.hs: -------------------------------------------------------------------------------- 1 | main = do 2 | print [a*100+b*10+c | a <- [1..9], b <- [0..9], c <- [0..9], a^3+b^3+c^3==a*100+b*10+c] 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/ex2-3.hs: -------------------------------------------------------------------------------- 1 | solve :: Int -> Int -> Int -> String 2 | solve a b c = 3 | let s = filter (\x -> x `mod` 3 == a && x `mod` 5 == b && x `mod` 7 == c) [10..100] in 4 | case s of 5 | [] -> "No Answer" 6 | x:_ -> show (head s) 7 | 8 | main = do 9 | line <- getLine 10 | let a:b:c:_ = (map read $ words line) :: [Int] 11 | putStrLn $ solve a b c 12 | 13 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/ex2-4.hs: -------------------------------------------------------------------------------- 1 | import Control.Monad 2 | 3 | main = do 4 | line <- getLine 5 | let n = read line :: Int 6 | forM_ [0..n-1] (\i -> do 7 | putStr $ take i (repeat ' ') 8 | putStrLn $ take (2*(n-i)-1) (repeat '*')) 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/ex2-5.hs: -------------------------------------------------------------------------------- 1 | main = do 2 | line <- getLine 3 | let arr = map read $ words line :: [Int] 4 | let n = head arr 5 | let m = last arr 6 | let a = init . tail $ arr 7 | print $ length $ filter ( abs x > 1e-6) terms 6 | putStrLn $ printf "%.6f" (sum needed :: Double) 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/ex2-8.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | main = do 4 | line <- getLine 5 | let n:m:_ = (map read $ words line) :: [Integer] 6 | let ans = sum [1.0 / realToFrac(i^2) | i <- [n..m]] :: Double 7 | putStrLn $ printf "%.5f" ans 8 | 9 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/ex2-9.hs: -------------------------------------------------------------------------------- 1 | import Text.Printf 2 | 3 | solve :: Int -> Int -> Int -> [Int] 4 | solve _ _ 0 = [] 5 | solve a b c = 6 | q : (solve (a2 `mod` b) b (c-1)) where 7 | a2 = a * 10 8 | q = a2 `div` b + (if c == 1 && (a2 `mod` b) * 10 `div` b >= 5 then 1 else 0) 9 | 10 | printDigits :: [Int] -> IO () 11 | printDigits [] = return () 12 | printDigits (x:xs) = do 13 | putStr $ printf "%d" x 14 | printDigits xs 15 | 16 | main = do 17 | line <- getLine 18 | let a:b:c:_ = (map read $ words line) :: [Int] 19 | putStr $ printf "%d." (a `div` b) 20 | printDigits $ solve (a `mod` b) b c 21 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/p2-1.hs: -------------------------------------------------------------------------------- 1 | main = do 2 | print $ filter issqrt [a*1100+b*11 | a <- [1..9], b <- [0..9]] where 3 | isqrt = round . sqrt . fromIntegral 4 | issqrt x = (isqrt x) * (isqrt x) == x 5 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/p2-2.hs: -------------------------------------------------------------------------------- 1 | cycleLen :: Int -> Int 2 | cycleLen 1 = 0 3 | cycleLen n 4 | | n `mod` 2 == 1 = (cycleLen $ n*3+1) + 1 5 | | otherwise = (cycleLen $ n `div` 2) + 1 6 | 7 | main = do 8 | line <- getLine 9 | let n = read line :: Int 10 | print . cycleLen $ n 11 | 12 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/p2-3.hs: -------------------------------------------------------------------------------- 1 | factorial :: Integer -> Integer 2 | factorial n = foldl1 (*) [1..n] 3 | 4 | main = do 5 | line <- getLine 6 | let n = read line :: Integer 7 | print . (`mod` 10^6) . sum . map factorial $ [1..n] 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/p2-4.hs: -------------------------------------------------------------------------------- 1 | import Data.List 2 | import Text.Printf 3 | 4 | average :: [Int] -> Double 5 | average x = realToFrac (sum x) / genericLength x 6 | 7 | main = do 8 | line <- getLine 9 | let a = (map read $ words line) :: [Int] 10 | putStrLn $ printf "%d %d %.3f" (minimum a) (maximum a) (average a) 11 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 第二章 Haskell 4 | 5 | 包括4个例题和10道习题代码 6 | 7 | 注意:这些Haskell代码并不受“目前为止书上还没有介绍xx知识点,因此不能在代码中使用”的限制 8 | 9 | 注意习题2-7和2-8运行起来有点慢,建议编译后运行 10 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/stat.in: -------------------------------------------------------------------------------- 1 | 8 3 6 5 4 9 1 12 8 6 2 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/ch2/stat.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/haskell/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》Haskell代码 2 | 3 | 刘汝佳 4 | 5 | Haskell是一门很特别的语言,也是笔者最喜欢的语言之一。 6 | 7 | 虽然笔者在工作中完全没有使用Haskell,但平时偶尔会拿它写点小东西 8 | 9 | 笔者对Haskell只是略懂一二,也缺乏实践经验,所以这里的代码难免包含一些土鳖的东西,欢迎拍砖 :) 10 | 11 | 顺便说一句,如果你对学习Haskell有兴趣,推荐阅读《Learn You a Haskell for Great Good!》 12 | 13 | http://learnyouahaskell.com/ 14 | 15 | 这本书很适合初学者阅读,但篇幅比较长,而且有些内容仍然颇有难度。如果你希望快速入门的话,《Haskell Fast & Hard》可能更好: 16 | 17 | https://www.fpcomplete.com/school/haskell-fast-hard 18 | 19 | 关于如何学习Haskell,网上的资料非常多,这里就不赘述了 :) 20 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-1.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | a, b, c = map(int, stdin.readline().strip().split()) 3 | print "%.3lf" % ((a+b+c)/3.0) 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-10.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from calendar import isleap 3 | year, = map(int, stdin.readline().strip().split()) 4 | if isleap(year): print "yes" 5 | else: print "no" 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-2.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | f, = map(float, stdin.readline().strip().split()) 3 | print "%.3lf" % (5*(f-32)/9) 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-3.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | n, = map(int, stdin.readline().strip().split()) 3 | print n*(n+1)/2 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-4.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from math import * 3 | n, = map(int, stdin.readline().strip().split()) 4 | rad = radians(n) 5 | print "%.3lf %.3lf" % (sin(rad), cos(rad)) 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-5.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from math import * 3 | x1, y1, x2, y2 = map(float, stdin.readline().strip().split()) 4 | print "%.3lf" % hypot((x1-x2), (y1-y2)) 5 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-6.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | n, = map(int, stdin.readline().strip().split()) 3 | print ["yes", "no"][n % 2] 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-7.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | n, = map(int, stdin.readline().strip().split()) 3 | money = n * 95 4 | if money >= 300: money *= 0.85 5 | print "%.2lf" % money 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-8.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | x, = map(float, stdin.readline().strip().split()) 3 | print abs(x) 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/ex1-9.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | a, b, c = map(int, stdin.readline().strip().split()) 3 | if a*a + b*b == c*c or a*a + c*c == b*b or b*b + c*c == a*a: print "yes" 4 | elif a + b <= c or a + c <= b or b + c <= a: print "not a triangle" 5 | else: print "no" 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/p1-1.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from math import * 3 | r, h = map(float, stdin.readline().strip().split()) 4 | print "Area = %.3lf" % (pi*r*r*2 + 2*pi*r*h) 5 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/p1-2.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | n = stdin.readline().strip().split()[0] 3 | print '%c%c%c' % (n[2], n[1], n[0]) 4 | 5 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/p1-3.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | a, b = map(int, stdin.readline().strip().split()) 3 | print b, a 4 | 5 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/p1-4.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | n, m = map(int, stdin.readline().strip().split()) 3 | a = (4*n-m)/2 4 | b = n-a 5 | if m % 2 == 1 or a < 0 or b < 0: print "No answer" 6 | else: print a, b 7 | 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/p1-5.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | a = map(int, stdin.readline().strip().split()) 3 | a.sort() 4 | print a[0], a[1], a[2] 5 | 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch1/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 第一章 Python 4 | 5 | 包括5个例题和10道习题代码 6 | 7 | 注意:这些Python代码并不受“目前为止书上还没有介绍xx知识点,因此不能在代码中使用”的限制 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-1.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | print len(stdin.readline().strip()) 3 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-10.py: -------------------------------------------------------------------------------- 1 | for abc in range(123, 329): 2 | big = str(abc) + str(abc*2) + str(abc*3) 3 | if(''.join(sorted(big)) == '123456789'): print abc, abc*2, abc*3 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-2.py: -------------------------------------------------------------------------------- 1 | from itertools import product 2 | sol = [a*100+b*10+c for a,b,c in product(range(1,10), range(10), range(10)) if a**3+b**3+c**3 == a*100+b*10+c] 3 | print '\n'.join(map(str, sol)) 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-3.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | def solve(a, b, c): 4 | for i in range(10, 101): 5 | if i % 3 == a and i % 5 == b and i % 7 == c: 6 | print i 7 | return 8 | print 'No answer' 9 | 10 | a, b, c = map(int, stdin.readline().strip().split()) 11 | solve(a, b, c) 12 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-4.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | n = int(stdin.readline().strip()) 3 | count = n*2-1 4 | for i in range(n): 5 | print ' '*i + '#'*count 6 | count -= 2 7 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-5.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | data = map(int, stdin.readline().strip().split()) 3 | n, m = data[0], data[-1] 4 | data = data[1:-1] 5 | print len(filter(lambda x: x < m, data)) 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-6.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | n = int(stdin.readline().strip()) 3 | print "%.3lf" % sum([1.0/x for x in range(1,n+1)]) 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-7.py: -------------------------------------------------------------------------------- 1 | s = i = 0 2 | while True: 3 | term = 1.0 / (i*2+1) 4 | s += term * ((-1)**i) 5 | if term < 1e-6: break 6 | i += 1 7 | print "%.6lf" % s 8 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-8.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | n, m = map(int, stdin.readline().strip().split()) 3 | print "%.5lf" % sum([1.0/i/i for i in range(n,m+1)]) 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/ex2-9.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from decimal import * 3 | a, b, c = map(int, stdin.readline().strip().split()) 4 | getcontext().prec = c 5 | print Decimal(a) / Decimal(b) 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/p2-1.py: -------------------------------------------------------------------------------- 1 | from itertools import product 2 | from math import * 3 | 4 | def issqrt(n): 5 | s = int(floor(sqrt(n))) 6 | return s*s == n 7 | 8 | aabb = [a*1100+b*11 for a,b in product(range(1,10),range(10))] 9 | print ' '.join(map(str, filter(issqrt, aabb))) 10 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/p2-2.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | 3 | def cycle(n): 4 | if n == 1: return 0 5 | elif n % 2 == 1: return cycle(n*3+1) + 1 6 | else: return cycle(n/2) + 1 7 | 8 | n = int(stdin.readline().strip()) 9 | print cycle(n) 10 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/p2-3.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | from math import * 3 | n = int(stdin.readline().strip()) 4 | print sum(map(factorial, range(1,n+1))) % (10**6) 5 | 6 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/p2-4.py: -------------------------------------------------------------------------------- 1 | from sys import stdin 2 | a = map(int, stdin.readline().strip().split()) 3 | print "%d %d %.3lf" % (min(a), max(a), float(sum(a)) / len(a)) 4 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》代码仓库 2 | 3 | 第二章 Python 4 | 5 | 包括4个例题和10道习题代码 6 | 7 | 注意:这些Python代码并不受“目前为止书上还没有介绍xx知识点,因此不能在代码中使用”的限制 8 | 9 | 注意习题2-7和2-8运行起来有点慢,建议用PyPy运行 :) 10 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/stat.in: -------------------------------------------------------------------------------- 1 | 8 3 6 5 4 9 1 12 8 6 2 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/ch2/stat.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /BeginningAlgorithmContests/python/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典》Python代码 2 | 3 | 刘汝佳 4 | 5 | Python是笔者最喜欢的语言之一,也是工作中用得最多的语言之一 6 | 7 | 虽然《入门经典》并没有介绍Python,但如果你碰巧也喜欢/在学/想学Python,不妨看一看这里的代码 8 | 9 | 这些代码不见得很Pythonic,不过是笔者认为可读性和实用性平衡比较好的实现方式 10 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la2678.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la2678.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la2678_n2.cpp: -------------------------------------------------------------------------------- 1 | // LA2678 Subsequence O(n^2) version 2 | // Rujia Liu 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | const int maxn = 100000 + 10; 8 | int A[maxn], B[maxn]; 9 | int main() { 10 | int n, S; 11 | while(scanf("%d%d", &n, &S) == 2 && n) { 12 | for(int i = 1; i <= n; i++) scanf("%d", &A[i]); 13 | B[0] = 0; 14 | for(int i = 1; i <= n; i++) B[i] = B[i-1] + A[i]; 15 | int ans = n+1; 16 | for(int i = 1; i <= n; i++) 17 | for(int j = i; j <= n; j++) 18 | if(B[j] - B[i-1] >= S) ans = min(ans, j-i+1); 19 | printf("%d\n", ans == n+1 ? 0 : ans); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la2678_n3.cpp: -------------------------------------------------------------------------------- 1 | // LA2678 Subsequence O(n^3) version 2 | // Rujia Liu 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | const int maxn = 100000 + 10; 8 | int A[maxn]; 9 | int main() { 10 | int n, S; 11 | while(scanf("%d%d", &n, &S) == 2 && n) { 12 | for(int i = 1; i <= n; i++) scanf("%d", &A[i]); 13 | int ans = n+1; 14 | for(int i = 1; i <= n; i++) 15 | for(int j = i; j <= n; j++) { 16 | int sum = 0; 17 | for(int k = i; k <= j; k++) sum += A[k]; 18 | if(sum >= S) ans = min(ans, j-i+1); 19 | } 20 | printf("%d\n", ans == n+1 ? 0 : ans); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la2678_nlogn.cpp: -------------------------------------------------------------------------------- 1 | // LA2678 Subsequence O(nlogn) version 2 | // Rujia Liu 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | const int maxn = 100000 + 10; 8 | int A[maxn], B[maxn]; 9 | int main() { 10 | int n, S; 11 | while(scanf("%d%d", &n, &S) == 2 && n) { 12 | for(int i = 1; i <= n; i++) scanf("%d", &A[i]); 13 | B[0] = 0; 14 | for(int i = 1; i <= n; i++) B[i] = B[i-1] + A[i]; 15 | int ans = n+1; 16 | for(int j = 1; j <= n; j++) { 17 | int i = lower_bound(B, B+j, B[j]-S) - B; 18 | if(i > 0) ans = min(ans, j-i+1); 19 | } 20 | printf("%d\n", ans == n+1 ? 0 : ans); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la2965.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la2965.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3029.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la3029.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3177.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la3177.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3401.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la3401.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3695.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la3695.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3708.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la3708.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3882.cpp: -------------------------------------------------------------------------------- 1 | // LA3882 And Then There Was One 2 | // Rujia Liu 3 | #include 4 | const int maxn = 10000 + 2; 5 | int f[maxn]; 6 | 7 | int main() { 8 | int n, k, m; 9 | while(scanf("%d%d%d", &n, &k, &m) == 3 && n) { 10 | f[1] = 0; 11 | for(int i = 2; i <= n; i++) f[i] = (f[i-1] + k) % i; 12 | int ans = (m - k + 1 + f[n]) % n; 13 | if (ans <= 0) ans += n; 14 | printf("%d\n", ans); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3902.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la3902.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3905.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la3905.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3905_int.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la3905_int.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la3971.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la3971.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/la4794.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/la4794.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva10635.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva10635.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva10859.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva10859.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva10881.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva10881.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva10891.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva10891.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva10891_slow.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva10891_slow.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11078.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva11078.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11210.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva11210.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11292.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva11292.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11300.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva11300.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11384.cpp: -------------------------------------------------------------------------------- 1 | // UVa11384 Help is needed for Dexter 2 | // Rujia Liu 3 | #include 4 | int f(int n) { 5 | return n == 1 ? 1 : f(n/2) + 1; 6 | } 7 | 8 | int main() { 9 | int n; 10 | while(scanf("%d", &n) == 1) 11 | printf("%d\n", f(n)); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11462.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva11462.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11464.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva11464.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11520.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva11520.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11549.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva11549.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch1/uva11729.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch1/uva11729.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/la3485.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/la3485.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/la3485_simpson.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/la3485_simpson.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/la3510.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/la3510.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/la3516.cpp: -------------------------------------------------------------------------------- 1 | // LA3516 Exploring Pyramids 2 | // Rujia Liu 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | const int maxn = 300 + 10; 8 | const int MOD = 1000000000; 9 | typedef long long LL; 10 | 11 | char S[maxn]; 12 | int d[maxn][maxn]; 13 | 14 | int dp(int i, int j) { 15 | if(i == j) return 1; 16 | if(S[i] != S[j]) return 0; 17 | int& ans = d[i][j]; 18 | if(ans >= 0) return ans; 19 | ans = 0; 20 | for(int k = i+2; k <= j; k++) if(S[i] == S[k]) 21 | ans = (ans + (LL)dp(i+1,k-1) * (LL)dp(k,j)) % MOD; 22 | return ans; 23 | } 24 | 25 | int main() { 26 | while(scanf("%s", S) == 1) { 27 | memset(d, -1, sizeof(d)); 28 | printf("%d\n", dp(0, strlen(S)-1)); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/la3641.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/la3641.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/la3704.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/la3704.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/la4119.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/la4119.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/la5059.cpp: -------------------------------------------------------------------------------- 1 | // LA5059 Playing With Stones 2 | // Rujia Liu 3 | #include 4 | using namespace std; 5 | 6 | long long SG(long long x){ 7 | return x%2==0 ? x/2 : SG(x/2); 8 | } 9 | 10 | int main() { 11 | int T; 12 | cin >> T; 13 | while (T--){ 14 | int n; 15 | long long a, v = 0; 16 | cin >> n; 17 | for(int i = 0; i < n; i++) { 18 | cin >> a; 19 | v ^= SG(a); 20 | } 21 | if(v) cout << "YES\n"; 22 | else cout << "NO\n"; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/la5059_try.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/la5059_try.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva10253.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva10253.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva10294.cpp: -------------------------------------------------------------------------------- 1 | // UVa10294 Arif in Dhaka (First Love part 2) 2 | // Rujia Liu 3 | #include 4 | typedef long long LL; 5 | 6 | const int maxn = 100; 7 | 8 | int gcd(int a, int b) { 9 | return b == 0 ? a : gcd(b, a%b); 10 | } 11 | 12 | int main() { 13 | int n, t; 14 | while(scanf("%d%d", &n, &t) == 2 && n) { 15 | LL pow[maxn]; 16 | pow[0] = 1; 17 | for(int i = 1; i <= n; i++) pow[i] = pow[i-1] * t; 18 | LL a = 0; 19 | for(int i = 0; i < n; i++) a += pow[gcd(i, n)]; 20 | LL b = 0; 21 | if(n % 2 == 1) b = n * pow[(n+1)/2]; 22 | else b = n/2 * (pow[n/2+1] + pow[n/2]); 23 | printf("%lld %lld\n", a/n, (a+b)/2/n); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva10341.cpp: -------------------------------------------------------------------------------- 1 | // UVa10341 Solve It 2 | // Rujia Liu 3 | #include 4 | #include 5 | #define F(x) (p*exp(-x)+q*sin(x)+r*cos(x)+s*tan(x)+t*(x)*(x)+u) 6 | const double eps = 1e-14; 7 | int main() { 8 | int p, r, q, s, t, u; 9 | while(scanf("%d%d%d%d%d%d", &p, &q, &r, &s, &t, &u) == 6) { 10 | double f0 = F(0), f1 = F(1); 11 | if(f1 > eps || f0 < -eps) printf("No solution\n"); 12 | else { 13 | double x = 0, y = 1, m; 14 | for(int i = 0; i < 100; i++) { 15 | m = x + (y-x)/2; 16 | if(F(m) < 0) y = m; else x = m; 17 | } 18 | printf("%.4lf\n", m); 19 | } 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva10561.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva10561.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva10828.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva10828.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11021.cpp: -------------------------------------------------------------------------------- 1 | // UVa11021 Tribbles 2 | // Rujia Liu 3 | #include 4 | #include 5 | const int maxn = 1000 + 10; 6 | const int maxm = 1000 + 10; 7 | int n, k, m; 8 | double P[maxn], f[maxm]; 9 | int main() { 10 | int T; 11 | scanf("%d", &T); 12 | for(int kase = 1; kase <= T; kase++) { 13 | scanf("%d%d%d", &n, &k, &m); 14 | for(int i = 0; i < n; i++) scanf("%lf", &P[i]); 15 | f[0] = 0; f[1] = P[0]; 16 | for(int i = 2; i <= m; i++) { 17 | f[i] = 0; 18 | for(int j = 0; j < n; j++) f[i] += P[j] * pow(f[i-1], j); 19 | } 20 | printf("Case #%d: %.7lf\n", kase, pow(f[m], k)); 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11077.cpp: -------------------------------------------------------------------------------- 1 | // UVa11077 Find the Permutations 2 | // Rujia Liu 3 | #include 4 | #include 5 | const int maxn = 30; 6 | unsigned long long f[maxn][maxn]; 7 | int main() { 8 | memset(f, 0, sizeof(f)); 9 | f[1][0] = 1; 10 | for(int i = 2; i <= 21; i++) 11 | for(int j = 0; j < i; j++) { 12 | f[i][j] = f[i-1][j]; 13 | if(j > 0) f[i][j] += f[i-1][j-1] * (i-1); 14 | } 15 | int n, k; 16 | while(scanf("%d%d", &n, &k) == 2 && n) 17 | printf("%llu\n", f[n][k]); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11361.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11361.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11401.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11401.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11426.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11426.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11427.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11427.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11538.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11538.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11542.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11542.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11722.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11722.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11754.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11754.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11762.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11762.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11806.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11806.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch2/uva11916.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch2/uva11916.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/dynamic_rmq.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/dynamic_rmq.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/la3026.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/la3026.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/la3135.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/la3135.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/la3644.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/la3644.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/la3938.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/la3938.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/la3942.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/la3942.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/la4329.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/la4329.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/la4670.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/la4670.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/la5031.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/la5031.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/la5031_noremove.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/la5031_noremove.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/ranktree.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/ranktree.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/search_engine.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/search_engine.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/sequence1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/sequence1.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/sequence2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/sequence2.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11019.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11019.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11107.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11107.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11235.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11235.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11468.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11468.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11732.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11732.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11922.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11922.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11991.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11991.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11992.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11992.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11992b.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11992b.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch3/uva11997.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch3/uva11997.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la2218.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la2218.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la2572.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la2572.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la2797.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la2797.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la3218.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la3218.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la3890.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la3890.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la4589.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la4589.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la4728.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la4728.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la4795.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la4795.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la4973.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la4973.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/la4992.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/la4992.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/uva10256.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/uva10256.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/uva10652.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/uva10652.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/uva11168.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/uva11168.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/uva11275.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/uva11275.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/uva11275_area.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/uva11275_area.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/uva11275_barycentric.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/uva11275_barycentric.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/uva11796.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/uva11796.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/uva12296.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/uva12296.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch4/uva12304.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch4/uva12304.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la2238.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la2238.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la2531.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la2531.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la2957.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la2957.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la3126.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la3126.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la3211.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la3211.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la3415.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la3415.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la3523.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la3523.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la3561.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la3561.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la3661.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la3661.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la3661_complex.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la3661_complex.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la3713.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la3713.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la3989.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la3989.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la4043.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la4043.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la4080.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la4080.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la4128.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la4128.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la4128_complex.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la4128_complex.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la4255.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la4255.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la4287.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la4287.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la4287_kosaraju.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la4287_kosaraju.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/la5135.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/la5135.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva10047.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva10047.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva10054.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva10054.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva10537.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva10537.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva10779.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva10779.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva10917.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva10917.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11090.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11090.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11248.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11248.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11248_dinic.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11248_dinic.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11324.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11324.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11354.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11354.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11374.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11374.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11383.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11383.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11383_template.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11383_template.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11419.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11419.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11478.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11478.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11613.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11613.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11624.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11624.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch5/uva11865.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/bookcodes/ch5/uva11865.cpp -------------------------------------------------------------------------------- /TrainingGuide/bookcodes/ch6/la3700.cpp: -------------------------------------------------------------------------------- 1 | // LA3700 Interesting Yang Hui Triangle 2 | // Rujia Liu 3 | #include 4 | int main() { 5 | int kase = 0, n, p; 6 | while(scanf("%d%d", &p, &n) == 2 && p) { 7 | int ans = 1; 8 | while(n > 0) { 9 | ans = ans * (n%p+1) % 10000; 10 | n /= p; 11 | } 12 | printf("Case %d: %04d\n", ++kase, ans); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/BruteForce/Uva10496.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/BruteForce/Uva10496.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/BruteForce/Uva387.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/BruteForce/Uva387.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/DP/Uva10100.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/DP/Uva10100.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/DP/Uva10306.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/DP/Uva10306.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/DP/Uva10700.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/DP/Uva10700.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/DP/Uva11081.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/DP/Uva11081.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/Efficient/Uva10125.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/Efficient/Uva10125.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/Efficient/Uva10391.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/Efficient/Uva10391.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/Efficient/Uva10763.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/Efficient/Uva10763.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/Efficient/Uva10827.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/Efficient/Uva10827.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/Efficient/Uva11054.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/Efficient/Uva11054.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/Efficient/Uva11495.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/Efficient/Uva11495.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/General/Uva10340.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/General/Uva10340.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/General/Uva10382.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/General/Uva10382.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/General/Uva10706.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch1/General/Uva10706.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch1/General/Uva10718.cc: -------------------------------------------------------------------------------- 1 | // UVa10718 Bit Mask 2 | // 陈锋 3 | #include 4 | using namespace std; 5 | 6 | unsigned int n,l,u,ll; 7 | 8 | int main() 9 | { 10 | unsigned int j; 11 | 12 | while (cin>>n>>l>>u) 13 | { 14 | ll = 0; 15 | 16 | for (j = 31; j<32; j--) 17 | { 18 | // ((n的第j+1位为0 或 (l的第j+1位为1 并且 ll小于l)) && (填1小于u)) 19 | if (((n|(1< l) ll=ll; 22 | } 23 | cout< 4 | int main() { 5 | int T, G, L; 6 | scanf("%d", &T); 7 | while(T--) { 8 | scanf("%d%d", &G, &L); 9 | if(L%G) printf("-1\n"); else printf("%d %d\n", G, L); 10 | } 11 | return 0; 12 | } -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Basic Problems/UVa11444.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Basic Problems/UVa11444.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Basic Problems/UVa11526.cpp: -------------------------------------------------------------------------------- 1 | // UVa11526 H(n) 2 | // Rujia Liu 3 | 4 | #include 5 | 6 | long long H(int n){ 7 | if(n <= 0) return 0; 8 | long long res = 0; 9 | unsigned int last; 10 | for(unsigned int i = 1; i <= n; i = last+1){ 11 | last = n/(n/i); 12 | res = (res + n/i*(last-i+1)); 13 | } 14 | return res; 15 | } 16 | 17 | int main() { 18 | int n, T; 19 | scanf("%d", &T); 20 | while(T--) { 21 | scanf("%d", &n); 22 | printf("%lld\n", H(n)); 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Basic Problems/UVa11609.cpp: -------------------------------------------------------------------------------- 1 | // UVa11609 Teams 2 | // Rujia Liu 3 | 4 | #include 5 | const int MOD = 1000000007; 6 | long long pow_mod(int n, int k, int m) { 7 | if(!k) return 1; 8 | long long p = pow_mod(n, k/2, m); 9 | p = p * p % m; 10 | if(k&1) p = p * n % m; 11 | return p; 12 | } 13 | 14 | int main() { 15 | int T, n, k, m, a; 16 | scanf("%d", &T); 17 | for(int i = 1; i <= T; i++) { 18 | scanf("%d", &n); 19 | long long ans = pow_mod(2,n-1,MOD) * n % MOD; 20 | printf("Case #%d: %d\n", i, (int)ans); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Basic Problems/UVa11752.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Basic Problems/UVa11752.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/CombinatorialGames/UVa10165.cc: -------------------------------------------------------------------------------- 1 | // UVa10165 Stone Game 2 | // 陈锋 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int N; 13 | while(scanf("%d", &N) == 1 && N > 0) 14 | { 15 | int ans = 0, tmp; 16 | for(int i = 0; i < N; i++) 17 | { 18 | scanf("%d", &tmp); 19 | ans ^= tmp; 20 | } 21 | 22 | puts(ans == 0 ? "No" : "Yes"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/CombinatorialGames/UVa12293.cc: -------------------------------------------------------------------------------- 1 | // UVa 12293 Box Game 2 | // 陈锋 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | typedef long long int64; 9 | 10 | 11 | // 大盒子里面有n个球,是否有必胜策略? 12 | bool solve(int64 n) 13 | { 14 | return ((n+1)&n) != 0; 15 | 16 | // if(n == 1) return false; 17 | 18 | // for(int i = n/2 + n%2; i < n; i++) 19 | // if(!solve(i)) return true; 20 | // return false; 21 | } 22 | 23 | int main() 24 | { 25 | int64 n; 26 | while(true) 27 | { 28 | scanf("%lld", &n); 29 | if(n == 0) break; 30 | puts(solve(n) ? "Alice" : "Bob"); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Counting/UVa10079.cc: -------------------------------------------------------------------------------- 1 | // UVa10079 Pizza Cutting 2 | // 陈锋 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | long long N; 9 | void runcase() 10 | { 11 | cout<>N; 19 | if(N < 0) break; 20 | runcase(); 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Counting/UVa11137.cpp: -------------------------------------------------------------------------------- 1 | // UVa11137 Ingenuous Cubrency 2 | // Rujia Liu 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | long long d[30][10010]; 8 | int main() { 9 | memset(d, 0, sizeof(d)); 10 | d[0][0] = 1; 11 | for(int i = 1; i <= 25; i++) 12 | for(int j = 0; j <= 10000; j++) { 13 | d[i][j] = d[i-1][j]; 14 | if(j>=i*i*i) d[i][j] += d[i][j-i*i*i]; 15 | } 16 | 17 | int n; 18 | while(cin >> n) { 19 | cout << d[25][n] << endl; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Counting/UVa11137_slow.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Counting/UVa11137_slow.cpp -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Counting/UVa11174.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Counting/UVa11174.cpp -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Counting/UVa11375.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Counting/UVa11375.cpp -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa10104.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa10104.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa10110.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa10110.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa10127.cc: -------------------------------------------------------------------------------- 1 | // UVa10127 Ones 2 | // 陈锋 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | typedef long long longInt; 10 | 11 | longInt n; 12 | 13 | void runcase() 14 | { 15 | longInt i = 1, ans = 1, mod; 16 | while(true) 17 | { 18 | mod = i % n; 19 | if(mod == 0) break; 20 | ans++; 21 | i = mod * 10 + 1; 22 | } 23 | 24 | cout<>n) 29 | { 30 | runcase(); 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa10162.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa10162.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa10325.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa10325.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa10368.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa10368.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa10616.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa10616.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa10990.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa10990.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa11029.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa11029.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa11180.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa11180.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa11287.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa11287.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa11317.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Number Theory/UVa11317.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Number Theory/UVa11718.cpp: -------------------------------------------------------------------------------- 1 | // UVa11718 Fantasy of a Summation 2 | // Rujia Liu 3 | 4 | #include 5 | 6 | int pow_mod(int n, int k, int m) { 7 | if(!k) return 1; 8 | int p = pow_mod(n, k/2, m); 9 | p = p * p % m; 10 | if(k&1) p = p * n % m; 11 | return p; 12 | } 13 | 14 | int main() { 15 | int T, n, k, m, a; 16 | scanf("%d", &T); 17 | for(int i = 1; i <= T; i++) { 18 | scanf("%d%d%d", &n, &k, &m); 19 | long long s = 0; 20 | for(int j = 0; j < n; j++) { scanf("%d", &a); s = (s+a)%m; } 21 | s = s * pow_mod(n,k-1,m) % m; 22 | s = s * (k % m) % m; 23 | printf("Case %d: %d\n", i, s); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Probability/UVa10491.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Probability/UVa10491.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Probability/UVa10759.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Probability/UVa10759.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Probability/UVa11181.cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Probability/UVa11181.cc -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/Probability/UVa11971.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch2/Probability/UVa11971.cpp -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch2/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典——训练指南》代码仓库 2 | 3 | 第二章习题代码 4 | 5 | 注意:有些题目并没有在书中出现,但是仍然有一定的启发意义,所以一并放在这里,供读者参考。 6 | 7 | 基础练习 (Basic Problems) 8 | UVa11388 GCD LCM 刘汝佳 9 | UVa11526 H(n) 刘汝佳 10 | UVa11609 Teams 刘汝佳 11 | 12 | 组合计数 (Counting) 13 | UVa10079 Pizza Cutting 陈锋 14 | UVa10081 Tight words 陈锋 15 | UVa10157 Expressions 陈锋 16 | UVa10497 Sweet Child Makes Trouble 陈锋 17 | Uva10883 Supermean 陈锋 18 | Uva1510 Neon Sign 陈锋 19 | UVa11137 Ingenuous Cubrency 刘汝佳(书上例子,包含时间复杂度不同的两个算法) 20 | UVa11174 Stand in a Line 刘汝佳(书上例子) 21 | UVa11375 Matches 刘汝佳(书上例子) 22 | 23 | 数论 (Number Theory) 24 | UVa11718 Fantasy of a Summation 刘汝佳 25 | UVa11440 Help Mr. Tomisu 刘汝佳 26 | 27 | 概率 (Probability) 28 | UVa11637 Garbage Remembering Exam 刘汝佳 29 | UVa11971 Polygon 刘汝佳 30 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch3/02-MaintainingIntervalData/UVa12299_build.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch3/02-MaintainingIntervalData/UVa12299_build.cpp -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch3/02-MaintainingIntervalData/uva12299.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch3/02-MaintainingIntervalData/uva12299.cpp -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch3/04-BST/UVa10909.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch3/04-BST/UVa10909.cpp -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch3/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典——训练指南》代码仓库 2 | 3 | 第三章习题代码 4 | 5 | 注意:有些题目并没有在书中出现,但是仍然有一定的启发意义,所以一并放在这里,供读者参考。 6 | 7 | 基础数据结构(Fundamental Data Structures) 8 | 9 | UVa11988 Broken Keyboard (a.k.a. Beiju Text) 陈锋 10 | UVa11136 Hoax or what 陈锋 11 | UVa10895 Matrix Transpose 陈锋 12 | UVa11987 Almost Union-Find 陈锋 13 | 14 | 区间信息维护(Maintaining Interval Data) 15 | 16 | LA2191 Potentiometers 陈锋 17 | UVa12299 RMQ with shifts 刘汝佳 18 | LA4730(UVa1455) – Kingdom 陈锋 19 | 20 | 字符串算法(String Algorithms) 21 | UVa11488 Hyper Prefix Sets 陈锋 22 | LA3907(UVa1399) Puzzle 陈锋 23 | UVa11855 Buzzwords 使用Hash实现的版本 陈锋 24 | UVa11855 Buzzwords 使用后缀数组实现的版本 陈锋 25 | 26 | 二叉搜索树(BST) 27 | UVa1264(LA4847) Binary Search Tree 陈锋 28 | UVa10909 Lucky Number 刘汝佳 29 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch4/01-BasicProblems/UVa10566.cc: -------------------------------------------------------------------------------- 1 | // UVa10566 Crossed Ladders 2 | // 陈锋 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | double x, y, c; 11 | inline double F(double u){ return c/sqrt(x*x - u*u) + c/sqrt(y*y - u*u) - 1;} 12 | 13 | int main() 14 | { 15 | while(scanf("%lf%lf%lf",&x,&y,&c) == 3) 16 | { 17 | double R = min(x, y), L = 0, M; 18 | // while(dcmp(L - R)) 19 | for(int i = 0;i<100;i++) 20 | { 21 | M = (L + R) / 2; 22 | double f = F(M); 23 | if(f == 0.0) break; 24 | else if(f > 0) R = M; 25 | else L = M; 26 | } 27 | printf("%.3lf\n", M); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch4/01-BasicProblems/uva11646.cpp: -------------------------------------------------------------------------------- 1 | // UVa11646 Athletics Track 2 | // Rujia Liu 3 | #include 4 | #include 5 | int main() { 6 | int a, b, kase = 1; 7 | char c[10]; 8 | while(scanf("%d%s%d", &a, &c, &b) == 3) { 9 | double R = sqrt(b*b+a*a)/2; 10 | double theta = 2*asin(b/(2*R)); 11 | double p = theta*R + a; 12 | printf("Case %d: %.8f %.8f\n", kase++, 200*a/p, 200*b/p); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch4/02-GeometricComputations2D/uva10674.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch4/02-GeometricComputations2D/uva10674.cpp -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch5/la3486.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sukhoeing/aoapc-book/c158cf4f6651100ad07482ab450663dd4a99f547/TrainingGuide/exercises/ch5/la3486.cpp -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch5/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典——训练指南》代码仓库 2 | 3 | 第五章习题代码 4 | 5 | 注意:有些题目并没有在书中出现,但是仍然有一定的启发意义,所以一并放在这里,供读者参考。 6 | 7 | LA2197 Paint the Roads 陈锋 8 | LA2796 Concert Hall Schedule 陈锋 9 | LA3268 Jamie's Contact Group 陈锋 10 | LA3276 The Great Wall Game 陈锋 11 | LA3353 Optimal Bus Route Design 陈锋 12 | LA3486 Cells 陈锋,刘汝佳 13 | LA3487 Duopoly 陈锋 14 | LA3887 Slim Span 陈锋 15 | LA3972 March of the Penguins 陈锋 16 | LA4288 Cat vs. Dog 陈锋 17 | LA5095 Transportation 陈锋 18 | UVa10269 Adventure of Super Mario 陈锋 19 | UVa10600 ACM Contest and Blackout 陈锋 20 | UVa10603 Fill 陈锋 21 | UVa10765 Doves and Bombs 陈锋 22 | UVa10806 Dijkstra, Dijkstra 陈锋 23 | UVa11082 Matrix Decompressing 陈锋 24 | UVa11294 Wedding 陈锋 25 | UVa11396 Claw Decomposition 陈锋 26 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/ch6/readme.txt: -------------------------------------------------------------------------------- 1 | 《算法竞赛入门经典——训练指南》代码仓库 2 | 3 | 第六章习题代码 4 | 5 | 注意:有些题目并没有在书中出现,但是仍然有一定的启发意义,所以一并放在这里,供读者参考。 6 | 7 | 代码组织与调试(Writing and Debugging Complex Codes) 8 | 9 | LA2727/UVa1024 A Linking Loader 刘汝佳 10 | 11 | 几何专题(Selected Topics in Geometry) 12 | 13 | UVa 1497(LA5719) A Letter to Programmers 陈锋 14 | -------------------------------------------------------------------------------- /TrainingGuide/exercises/readme.txt: -------------------------------------------------------------------------------- 1 | 这里是《算法竞赛入门经典——训练指南》习题相关代码 2 | 3 | 习题较多,因此不一一将这些代码的风格与书上代码统一,甚至语言也不限于C++,不便之处请见谅。 4 | --------------------------------------------------------------------------------