├── .gitignore ├── .vimrc ├── .zshrc ├── Codeforces ├── 148D.cpp ├── 311B.cpp ├── 319C.cpp ├── 321E.cpp ├── 321Edac.cpp ├── 455D.cpp ├── 466B.cpp ├── 489E.cpp ├── 626F.cpp ├── AIM Tech Round 3 (Div. 2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── ASC 46 [Solo] │ ├── A.cpp │ ├── B.cpp │ ├── F.cpp │ ├── G.cpp │ └── J.cpp ├── ASC 47 │ └── G.cpp ├── Canada Cup 2016 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Contest1994 │ └── 1994G.cpp ├── Contest2025 │ └── 2025E.cpp ├── ECPC 2013 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ ├── I.cpp │ ├── K.cpp │ └── L.cpp ├── Educational Codeforces Round 99 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Good Bye 2014 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Good Bye 2016 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Looksery Cup 2015 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── F.cpp │ ├── G.cpp │ └── H.cpp ├── MemSQL Start[c]UP 2.0 - Round 1 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #072 │ ├── A.cpp │ └── B.cpp ├── Round #134 (Both) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ └── F.cpp ├── Round #140 (Both) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ └── F.cpp ├── Round #156 (Both) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ └── G.cpp ├── Round #157 (Both) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ └── G.cpp ├── Round #160 (Both) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ └── F.cpp ├── Round #184 │ └── 184b.cpp ├── Round #192 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #198 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #204 │ ├── b.cpp │ ├── cfa.cpp │ ├── cfe.cpp │ └── rand.cpp ├── Round #206 │ ├── A.cpp │ ├── C补.cpp │ ├── aa.cpp │ └── bb.cpp ├── Round #208 (Div.2) │ ├── a.cpp │ ├── b.cpp │ ├── c.cpp │ ├── d.cpp │ └── e.cpp ├── Round #209 (Div.2) │ ├── C.cpp │ └── D.cpp ├── Round #210 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D(Ryan补).cpp ├── Round #211 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E(mle && wa).cpp ├── Round #212 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C(补).cpp │ ├── C.cpp │ └── D.cpp ├── Round #213 │ ├── 2A.cpp │ ├── 2B.cpp │ ├── A.cpp │ ├── B.cpp │ └── C(补).cpp ├── Round #214 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #215 │ ├── A.cpp │ ├── B.cpp │ └── C(补).cpp ├── Round #216 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #219 │ └── A.cpp ├── Round #220 (Div.2) │ ├── B.cpp │ └── D.cpp ├── Round #221 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #223 │ ├── A.cpp │ ├── C.cpp │ └── D.cpp ├── Round #224 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #230 │ ├── 2a 2Y.cpp │ ├── a.cpp │ ├── b.cpp │ └── c 补2Y.cpp ├── Round #231 │ ├── 2a_after.cpp │ ├── 2b_after.cpp │ ├── 2c_after.cpp │ └── 2d_after.cpp ├── Round #232 │ ├── 1a.cpp │ ├── 1b.cpp │ ├── 1d.cpp │ ├── 2a.cpp │ ├── 2b.cpp │ ├── mb.cpp │ └── md.cpp ├── Round #243 │ ├── A.cpp │ ├── B.cpp │ └── D.cpp ├── Round #246 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #249 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #250 │ ├── A.cpp │ ├── B.cpp │ └── D.cpp ├── Round #253 │ ├── A.cpp │ ├── _B.cpp │ └── _C.cpp ├── Round #265 │ ├── 464A.cpp │ ├── 464B.cpp │ ├── 464C.cpp │ └── 464D.cpp ├── Round #267 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #268 │ ├── A.cpp │ └── B.cpp ├── Round #270 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── F.cpp ├── Round #272 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #273 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #277 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #280 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #281 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #282 │ ├── A.cpp │ └── B.cpp ├── Round #283 │ ├── A.cpp │ ├── B.cpp │ └── C.cpp ├── Round #285 │ ├── A.cpp │ └── B.cpp ├── Round #287 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #295 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #307 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #312 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #346 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── E.cpp │ └── F.cpp ├── Round #354 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.java ├── Round #356 │ ├── 2A.cpp │ ├── 2B.cpp │ ├── A.cpp │ └── B.cpp ├── Round #357 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #358 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #359 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #361 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── E.cpp ├── Round #364 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #365 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Round #368 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round #372 (Div.2) │ ├── A.cpp │ ├── B.cpp │ └── C.cpp ├── Round #394 (Div.2) │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ └── E.cpp ├── Round 969 │ ├── 2006A.cpp │ ├── 2006B.cpp │ └── 2006D.cpp ├── Round973 │ └── 2013E.cpp ├── Round975 │ └── 2018A.cpp └── Round_974 │ ├── 2014E.cpp │ ├── 2014F.cpp │ ├── 2014G.cpp │ └── 2014H.cpp ├── Else ├── Bjtu1003.cpp ├── CC_COINS.cpp ├── CC_MBOARD.cpp ├── CC_SUBLCM.cpp ├── Fzu1753.cpp ├── Hnnu10348.cpp ├── bjtu1060.cpp ├── fzu1752.cpp ├── fzu1894.cpp ├── hiho1071.cpp ├── hiho1075.cpp ├── hiho1076.cpp ├── hit2813.cpp ├── ural1132.cpp └── ural1133.java ├── Final.pdf ├── Hdu ├── 1005.cpp ├── 1166.cpp ├── 1394.cpp ├── 1402.cpp ├── 1536.cpp ├── 1568.cpp ├── 1695.cpp ├── 1698.cpp ├── 1754.cpp ├── 1755.cpp ├── 1850.cpp ├── 1867.cpp ├── 2016 CCPC online │ ├── 5832.cpp │ ├── 5833.cpp │ ├── 5834.cpp │ ├── 5835.cpp │ └── 5842.cpp ├── 2016 Dalian Online │ ├── 1002.cpp │ ├── 1006.cpp │ ├── 1007.cpp │ ├── 1008.cpp │ ├── 1009.cpp │ └── 1010.cpp ├── 2016 Multi-University Training Contest 1 │ ├── 5723.cpp │ ├── 5724.cpp │ ├── 5726.cpp │ ├── 5727.cpp │ ├── 5729.cpp │ ├── 5730.cpp │ └── 5733.cpp ├── 2016 Multi-University Training Contest 10 │ ├── 5857.cpp │ ├── 5857zxs.cpp │ ├── 5858.cpp │ ├── 5860.cpp │ ├── 5861.cpp │ ├── 5862.cpp │ └── 5863.cpp ├── 2016 Multi-University Training Contest 2 │ ├── 5734.cpp │ ├── 5735.cpp │ ├── 5738.cpp │ ├── 5739.cpp │ ├── 5741.cpp │ ├── 5742.cpp │ ├── 5744.cpp │ └── 5745.cpp ├── 2016 Multi-University Training Contest 3 │ ├── 5752.java │ ├── 5753.cpp │ ├── 5754.cpp │ ├── 5755.cpp │ ├── 5758.cpp │ ├── 5760.cpp │ ├── 5761.cpp │ └── 5762.cpp ├── 2016 Multi-University Training Contest 4 │ ├── 5763.cpp │ ├── 5765.cpp │ ├── 5768.java │ ├── 5769.cpp │ ├── 5773.cpp │ ├── 5774.cpp │ └── 5775.cpp ├── 2016 Multi-University Training Contest 5 │ ├── 5781.cpp │ ├── 5782.cpp │ ├── 5783.cpp │ ├── 5784.cpp │ ├── 5785.cpp │ ├── 5787.cpp │ ├── 5788.cpp │ ├── 5790.cpp │ ├── 5791.cpp │ └── 5792.cpp ├── 2016 Multi-University Training Contest 6 │ ├── 5793.cpp │ ├── 5794.cpp │ ├── 5795.cpp │ ├── 5798.cpp │ ├── 5800.cpp │ ├── 5802.cpp │ └── 5803.cpp ├── 2016 Multi-University Training Contest 7 │ ├── 5809.cpp │ ├── 5810.cpp │ ├── 5812.cpp │ ├── 5813.cpp │ ├── 5816.cpp │ ├── 5818.cpp │ ├── 5819.cpp │ └── 5820.cpp ├── 2016 Multi-University Training Contest 8 │ ├── 5821.cpp │ ├── 5823.cpp │ ├── 5826.cpp │ ├── 5828.cpp │ ├── 5829.cpp │ └── 5831.cpp ├── 2016 Multi-University Training Contest 9 │ └── 5845.cpp ├── 2016 Qingdao Online │ ├── 1001.cpp │ ├── 1002.cpp │ ├── 1005.cpp │ ├── 1006.cpp │ ├── 1007.cpp │ ├── 1009.cpp │ ├── 1011.cpp │ └── 1012.cpp ├── 2016 Shenyang Online │ ├── 1003.cpp │ ├── 1004.cpp │ ├── 1007.cpp │ ├── 1009.cpp │ └── 1010.cpp ├── 2089.cpp ├── 2262.cpp ├── 2428.cpp ├── 2461.cpp ├── 2504.cpp ├── 2577.cpp ├── 2795.cpp ├── 2815.cpp ├── 2971.cpp ├── 2979.cpp ├── 3018.cpp ├── 3333.cpp ├── 3826.cpp ├── 3842.cpp ├── 3853.cpp ├── 4035.cpp ├── 4082.cpp ├── 4087.cpp ├── 4089.cpp ├── 4116.cpp ├── 4120.cpp ├── 4336.cpp ├── 4347.cpp ├── 4351.cpp ├── 4352.cpp ├── 4405.cpp ├── 4412.cpp ├── 4414.cpp ├── 4415.cpp ├── 4447.cpp ├── 4449.cpp ├── 4458.cpp ├── 4576.cpp ├── 4651.cpp ├── 4658.cpp ├── 4695.cpp ├── 4712.cpp ├── 4732.cpp ├── 4742(cdq).cpp ├── 4742.cpp ├── 4783.cpp ├── 4805.cpp ├── 4809.cpp ├── 4816.cpp ├── 4865.cpp ├── 4870.cpp ├── 4883.cpp ├── 4885.cpp ├── 4886.cpp ├── 4887.cpp ├── 4890.cpp ├── 4892.cpp ├── 4896.cpp ├── 4904.cpp ├── 4914.cpp ├── 4944.cpp ├── 4947.cpp ├── 4963.cpp ├── 4978.cpp ├── 4989.cpp ├── 4990.cpp ├── 4991.cpp ├── 4992.cpp ├── 5013.cpp ├── 5022.cpp ├── 5028.cpp ├── 5036.cpp ├── 5042.cpp ├── 5072.cpp ├── 5073.cpp ├── 5074.cpp ├── 5078.cpp ├── 5079.cpp ├── 5080.cpp ├── 5086.cpp ├── 5087.cpp ├── 5088.cpp ├── 5097.cpp ├── 5117.cpp ├── 5145.cpp ├── 5146.cpp ├── 5147.cpp ├── 5148.cpp ├── 5154.cpp ├── 5155.cpp ├── 5185.cpp ├── 5194.cpp ├── 5195.cpp └── 5779.cpp ├── Live Archive ├── 3668.cpp ├── 6465.cpp ├── 6466.cpp ├── 6467.cpp ├── 6468.cpp ├── 6469.cpp ├── 6470.cpp ├── 6471.cpp ├── 6472.cpp └── 7157.cpp ├── Poj ├── 1001.cpp ├── 1002.cpp ├── 1005.cpp ├── 1006.cpp ├── 1007.cpp ├── 1008.cpp ├── 1013.cpp ├── 1014.cpp ├── 1015.cpp ├── 1019.cpp ├── 1026.cpp ├── 1039.cpp ├── 1042.cpp ├── 1045.cpp ├── 1046.cpp ├── 1047.java ├── 1050.cpp ├── 1051.cpp ├── 1056.cpp ├── 1061.cpp ├── 1065.cpp ├── 1066.cpp ├── 1067.cpp ├── 1080.cpp ├── 1082.cpp ├── 1083.cpp ├── 1085.cpp ├── 1088.cpp ├── 1089.cpp ├── 1091.cpp ├── 1094.cpp ├── 1095.cpp ├── 1102.cpp ├── 1118.cpp ├── 1125.cpp ├── 1127.cpp ├── 1129.cpp ├── 1131.java ├── 1141.cpp ├── 1142.cpp ├── 1146.cpp ├── 1150.cpp ├── 1151.cpp ├── 1152.cpp ├── 1159.cpp ├── 1160.cpp ├── 1163.cpp ├── 1166.cpp ├── 1180.cpp ├── 1182.cpp ├── 1183.cpp ├── 1185.cpp ├── 1186.cpp ├── 1190.cpp ├── 1201.cpp ├── 1222.cpp ├── 1228.cpp ├── 1256.cpp ├── 1260.cpp ├── 1269.cpp ├── 1274.cpp ├── 1276.cpp ├── 1279.cpp ├── 1285.cpp ├── 1286.cpp ├── 1288.cpp ├── 1292.cpp ├── 1321.cpp ├── 1322.cpp ├── 1328.cpp ├── 1329.cpp ├── 1330.cpp ├── 1351.cpp ├── 1365.cpp ├── 1375.cpp ├── 1408.cpp ├── 1410.cpp ├── 1414.cpp ├── 1422.cpp ├── 1423.cpp ├── 1426.cpp ├── 1432.cpp ├── 1436.cpp ├── 1459.cpp ├── 1466.cpp ├── 1469.cpp ├── 1470.cpp ├── 1472.cpp ├── 1474.cpp ├── 1496.cpp ├── 1509.cpp ├── 1511.cpp ├── 1515.cpp ├── 1517.cpp ├── 1519.cpp ├── 1523.cpp ├── 1556.cpp ├── 1573.cpp ├── 1579.cpp ├── 1595.cpp ├── 1611.cpp ├── 1631.cpp ├── 1635.cpp ├── 1651.cpp ├── 1658.cpp ├── 1661.cpp ├── 1664.cpp ├── 1681.cpp ├── 1686.cpp ├── 1692.cpp ├── 1696.cpp ├── 1702.cpp ├── 1703.cpp ├── 1704.cpp ├── 1707.cpp ├── 1715.cpp ├── 1721.cpp ├── 1734.cpp ├── 1737.java ├── 1742.cpp ├── 1745.cpp ├── 1747.cpp ├── 1753.cpp ├── 1755.cpp ├── 1777.cpp ├── 1781.cpp ├── 1792.cpp ├── 1797.cpp ├── 1811.cpp ├── 1821max.cpp ├── 1821slope.cpp ├── 1830.cpp ├── 1836.cpp ├── 1837.cpp ├── 1840.cpp ├── 1845.cpp ├── 1850.cpp ├── 1852.cpp ├── 1860.cpp ├── 1873.cpp ├── 1905.cpp ├── 1942.cpp ├── 1953.cpp ├── 1976.cpp ├── 1977.cpp ├── 1979.cpp ├── 1995.cpp ├── 1998.cpp ├── 2000.cpp ├── 2007.cpp ├── 2010.cpp ├── 2031.cpp ├── 2033.cpp ├── 2034.cpp ├── 2035.cpp ├── 2036.cpp ├── 2038.cpp ├── 2074.cpp ├── 2079.cpp ├── 2081.cpp ├── 2094.java ├── 2096.cpp ├── 2103.java ├── 2104.cpp ├── 2117.cpp ├── 2142.cpp ├── 2151.cpp ├── 2154.cpp ├── 2155.cpp ├── 2171.cpp ├── 2172.cpp ├── 2173.cpp ├── 2177.cpp ├── 2179.cpp ├── 2181.cpp ├── 2182.cpp ├── 2186.cpp ├── 2191.cpp ├── 2195.cpp ├── 2229.cpp ├── 2231.cpp ├── 2236.cpp ├── 2255.cpp ├── 2262.cpp ├── 2282.cpp ├── 2287.cpp ├── 2299.cpp ├── 2318.cpp ├── 2345.cpp ├── 2348.cpp ├── 2349.cpp ├── 2352.cpp ├── 2356.cpp ├── 2365.cpp ├── 2371.cpp ├── 2376.cpp ├── 2377.cpp ├── 2386.cpp ├── 2388.cpp ├── 2398.cpp ├── 2407.cpp ├── 2409.cpp ├── 2411.cpp ├── 2413.java ├── 2417.cpp ├── 2429.cpp ├── 2431.cpp ├── 2443.cpp ├── 2446.cpp ├── 2447.cpp ├── 2457.cpp ├── 2478.cpp ├── 2479.cpp ├── 2480.cpp ├── 2492.cpp ├── 2513.cpp ├── 2516.cpp ├── 2521.cpp ├── 2524.cpp ├── 2528.cpp ├── 2531.cpp ├── 2540.cpp ├── 2545.java ├── 2549.cpp ├── 2559.cpp ├── 2560.cpp ├── 2583.cpp ├── 2590.cpp ├── 2601.cpp ├── 2602.cpp ├── 2606.cpp ├── 2625.cpp ├── 2632.cpp ├── 2635.cpp ├── 2653.cpp ├── 2663.cpp ├── 2689.cpp ├── 2707.cpp ├── 2718.cpp ├── 2728.cpp ├── 2731.cpp ├── 2732.cpp ├── 2733.cpp ├── 2734.cpp ├── 2735.cpp ├── 2737.cpp ├── 2738.cpp ├── 2762.cpp ├── 2769.cpp ├── 2773.cpp ├── 2774.cpp ├── 2785.cpp ├── 2823.cpp ├── 2826.cpp ├── 2833.cpp ├── 2864.cpp ├── 2887.cpp ├── 2888.cpp ├── 2891.cpp ├── 2917.cpp ├── 2941.cpp ├── 2965.cpp ├── 2975.cpp ├── 2976.cpp ├── 2992.cpp ├── 2993.cpp ├── 2996.cpp ├── 3006.cpp ├── 3020.cpp ├── 3026.cpp ├── 3030.cpp ├── 3041.cpp ├── 3045.cpp ├── 3062.cpp ├── 3069.cpp ├── 3070.cpp ├── 3080.cpp ├── 3090.cpp ├── 3094.cpp ├── 3096.cpp ├── 3101.java ├── 3122.cpp ├── 3126.cpp ├── 3128.cpp ├── 3132.cpp ├── 3169.cpp ├── 3173.cpp ├── 3174.cpp ├── 3176.cpp ├── 3185.cpp ├── 3233.cpp ├── 3243.cpp ├── 3252.cpp ├── 3253.cpp ├── 3255.cpp ├── 3258.cpp ├── 3259.cpp ├── 3264.cpp ├── 3267.cpp ├── 3268.cpp ├── 3270.cpp ├── 3273.cpp ├── 3274.cpp ├── 3278.cpp ├── 3286.cpp ├── 3292.cpp ├── 3295.cpp ├── 3299.cpp ├── 3304.cpp ├── 3310.cpp ├── 3311.cpp ├── 3312.cpp ├── 3314.cpp ├── 3316.cpp ├── 3317.cpp ├── 3318.cpp ├── 3324.java ├── 3348.cpp ├── 3349.cpp ├── 3352.cpp ├── 3358.cpp ├── 3370.cpp ├── 3372.cpp ├── 3378.cpp ├── 3384.cpp ├── 3421.cpp ├── 3422.cpp ├── 3432.cpp ├── 3436.cpp ├── 3440.cpp ├── 3468.cpp ├── 3469.cpp ├── 3471.cpp ├── 3480.cpp ├── 3487.cpp ├── 3508.cpp ├── 3517_O(n).cpp ├── 3517_O(nlgn).cpp ├── 3518.cpp ├── 3519.cpp ├── 3528.cpp ├── 3536.cpp ├── 3537.cpp ├── 3538.cpp ├── 3543.cpp ├── 3544.cpp ├── 3617.cpp ├── 3619.cpp ├── 3624.cpp ├── 3625.cpp ├── 3627.cpp ├── 3632.cpp ├── 3641.cpp ├── 3663.cpp ├── 3664.cpp ├── 3672.cpp ├── 3673.cpp ├── 3708.java ├── 3714.cpp ├── 3723.cpp ├── 3725.cpp ├── 3744.cpp ├── 3749.cpp ├── 3750.cpp ├── 3751.cpp ├── 3752.cpp ├── 3863.cpp ├── 3867.cpp ├── 3869.cpp ├── 3903.cpp ├── 3904.cpp ├── 3910.cpp ├── 3959.cpp ├── 3960.cpp ├── 3962.cpp ├── 3964.cpp ├── 3979.cpp ├── 3983.cpp ├── 3984.cpp ├── 3994.cpp ├── 4011.cpp ├── 4020.cpp ├── 4022.cpp ├── 4031.java ├── 4034.cpp ├── 4038.cpp ├── 4039.cpp ├── 4040.cpp ├── 4042.cpp └── 4043.cpp ├── README.md ├── Sgu ├── 101.cpp ├── 102.cpp ├── 103.cpp ├── 104.cpp ├── 106.cpp ├── 107.cpp ├── 108.cpp ├── 109.cpp ├── 110.cpp ├── 111.java ├── 113.cpp ├── 114.cpp ├── 115.cpp ├── 116.cpp ├── 117.cpp ├── 118.java ├── 119.cpp ├── 120.cpp ├── 121.cpp ├── 122.cpp ├── 123.cpp ├── 124.cpp ├── 125.cpp ├── 126.cpp ├── 127.cpp ├── 133.cpp ├── 134.cpp ├── 135.cpp ├── 139.cpp ├── 140.cpp ├── 142.cpp ├── 143.cpp ├── 144.cpp ├── 148.cpp ├── 149.cpp ├── 154.cpp ├── 172.cpp ├── 174.cpp ├── 178.cpp ├── 181.cpp ├── 186.cpp ├── 188.cpp ├── 190.cpp ├── 198.cpp ├── 199.cpp ├── 222.cpp ├── 231.cpp ├── 261.cpp ├── 276.cpp ├── 299.java ├── 495.cpp └── 546.cpp ├── Spoj ├── ASTDPROB.cpp ├── AU7_5.cpp ├── BFALG.cpp ├── CVXPOLY.cpp ├── MATRIX2.cpp ├── NDIVPHI.java ├── PSTR.cpp ├── RRANGE.cpp ├── STRSEQ.cpp ├── TABLE.cpp ├── TAP2014C.cpp ├── TAP2014E.cpp ├── TAP2014F.cpp ├── TLE.cpp └── UCBINTA.cpp ├── Summary.md ├── T-shirt ├── 51nod月赛#14 │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ └── D.cpp ├── Baidu Astar 2014 │ ├── QR │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── D.cpp │ └── R1A │ │ ├── B.cpp │ │ └── D.cpp ├── Baidu Astar 2015 │ ├── R1B │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ └── F.cpp │ └── R2 │ │ ├── 1001.cpp │ │ ├── 1002.cpp │ │ ├── 1003.cpp │ │ ├── 1004.cpp │ │ └── 1005.cpp ├── Baidu Astar 2016 │ ├── R1A │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ └── F.cpp │ └── R2 │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── D.cpp ├── Google APAC 2016 │ ├── Practice │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── D.cpp │ └── Round A │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── D.cpp ├── Google Code Jam 2014 │ ├── Qualification Round │ │ ├── gcj_a.cpp │ │ ├── gcj_b.cpp │ │ ├── gcj_c.cpp │ │ └── gcj_d.cpp │ ├── Round 1B │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── Round 1C │ │ └── B.cpp │ └── Round 2 │ │ ├── A.cpp │ │ ├── BB.cpp │ │ ├── C.cpp │ │ └── D.cpp ├── Google Code Jam 2015 │ └── Round 2 │ │ ├── A.cpp │ │ ├── Bs.cpp │ │ └── Cs.cpp ├── Google Code Jam 2016 │ ├── R2 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── Cs.cpp │ │ └── Ds.cpp │ └── R3 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── Cs.cpp │ │ └── D.cpp ├── Google Code Jam 2020 │ ├── .DS_Store │ ├── QR │ │ ├── P2.cpp │ │ ├── P3.cpp │ │ └── Vestigium.cpp │ ├── R1B │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── B.py │ │ └── C.cpp │ └── R2 │ │ ├── A.cpp │ │ ├── B-small.cpp │ │ └── C.cpp ├── Google Code Jam 2021 │ ├── .DS_Store │ ├── QR │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C │ │ └── C.cpp │ ├── R1B │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ └── R2 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── D.cpp ├── HackerCup2020 │ ├── QR │ │ ├── A.cpp │ │ └── B.cpp │ └── R1 │ │ ├── A1.cpp │ │ └── B.cpp ├── HackerCup2023 │ ├── R1 │ │ ├── A1.cpp │ │ ├── B1.cpp │ │ ├── C1.cpp │ │ ├── C2.cpp │ │ └── D1.cpp │ ├── R2 │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── D.cpp │ └── R3 │ │ ├── A.cpp │ │ └── D.cpp ├── HackerCup2024 │ ├── Practice │ │ ├── A_Walk_the_Line.cpp │ │ ├── B_Line_by_Line.cpp │ │ ├── C_Fall_in_Line.cpp │ │ ├── D_1_Line_of_Delivery_Part_1.cpp │ │ └── D_2_Line_of_Delivery_Part_2.cpp │ ├── R1 │ │ ├── A_Subsonic_Subway.cpp │ │ ├── B_Prime_Subtractorization.cpp │ │ ├── C_Substantial_Losses.cpp │ │ ├── TLE_E_Wildcard_Submissions.cpp │ │ └── WA_D_Substitution_Cipher.cpp │ └── R2 │ │ ├── A_1_Cottontail_Climb_Part_1.cpp │ │ ├── A_2_Cottontail_Climb_Part_2.cpp │ │ ├── B_WA_Four_in_a_Burrow.cpp │ │ └── C_Bunny_Hopscotch.cpp ├── JiSuanKe 2016 R1 │ ├── R1A │ │ ├── A.cpp │ │ └── Bmid.cpp │ └── R2 │ │ ├── B.cpp │ │ ├── E.cpp │ │ └── F.cpp ├── MS BoP 2015 │ ├── QR │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── R1A │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ └── R2 │ │ ├── A.cpp │ │ ├── C(small).cpp │ │ └── D.cpp ├── MS BoP 2016 │ ├── Sample.txt │ ├── mymac.py │ └── ronnoc@server.py ├── Russian Code Cup 2016 │ └── R1A │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp ├── Yandex 2016 │ ├── E Round 1 │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── D.cpp │ └── E Round 2 │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── E.cpp ├── ipsc 2014 │ ├── A.cpp │ ├── C.cpp │ ├── G1.cpp │ ├── I.cpp │ ├── J1.txt │ ├── J2.cpp │ ├── J2.txt │ └── K1.txt └── ipsc 2016 @Nero@sd0061 │ └── D.cpp ├── Team ├── 2011 Beijing [Hyacinth#61] │ ├── 4082.cpp │ ├── 4087.cpp │ └── 4089.cpp ├── 2012 Hangzhou Online [Hyacinth#60] │ ├── 4412.cpp │ ├── 4414.cpp │ └── 4415.cpp ├── 2014 Anshan [Hyacinth#65] │ ├── 5072.cpp │ ├── 5073.cpp │ ├── 5074.cpp │ ├── 5078.cpp │ ├── 5079.cpp │ └── 5080.cpp ├── ASC 40 [Hyacinth] │ ├── A.cpp │ ├── D.cpp │ ├── E.cpp │ └── H.cpp └── with@Lquartz@shllhs │ ├── 2008 Asia Beijing Online │ ├── B.cpp │ ├── D(爆).cpp │ ├── D.java │ ├── F.cpp │ ├── G.cpp │ └── J.cpp │ ├── 2009 Asia Harbin Regional │ ├── B.cpp │ ├── D.cpp │ ├── J.cpp │ └── K.cpp │ ├── 2009 Asia Wuhan Regional │ ├── B.cpp │ ├── C.cpp │ ├── D.cpp │ ├── G.cpp │ └── H补.cpp │ ├── 2010 Asia Fuzhou Online │ ├── A补.cpp │ ├── D.cpp │ ├── F.cpp │ ├── I补.cpp │ ├── J补.cpp │ └── K.cpp │ ├── 2010 Asia Fuzhou Regional │ ├── B.cpp │ ├── E.cpp │ ├── F.cpp │ ├── H.cpp │ ├── I.cpp │ └── J.cpp │ ├── 2011 Asia Dalian Regional │ ├── D.cpp │ ├── G.cpp │ └── I.cpp │ ├── 2012 Asia Tianjin Regional │ ├── A补.cpp │ ├── B.cpp │ ├── C.cpp │ ├── E.cpp │ ├── F补.cpp │ └── H.cpp │ ├── 2012 NEERC Southern Subregional │ ├── E.cpp │ ├── G.cpp │ ├── H.cpp │ ├── J.cpp │ ├── K.cpp │ └── L.cpp │ ├── 2013 Asia Changsha Regional │ ├── A.cpp │ ├── C.cpp │ ├── H.cpp │ ├── J.cpp │ └── K.cpp │ ├── 2013 Asia Hangzhou Regional │ ├── 1001.cpp │ ├── 1002.cpp │ ├── 1003.cpp │ └── 1009.cpp │ ├── 2013 Asia Nanjing Regional │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── I.cpp │ └── J.cpp │ ├── 2013 NEERC Eastern Subregional │ ├── A.cpp │ ├── B.cpp │ ├── C.cpp │ ├── E.cpp │ ├── F.cpp │ ├── H.cpp │ └── I.cpp │ ├── 2013 NEERC Nothern Subregional │ ├── A.cpp │ ├── B.cpp │ ├── D.cpp │ ├── E.cpp │ ├── F.cpp │ ├── G.cpp │ └── K.cpp │ ├── 2013 ZOJ Monthly March │ ├── A.cpp │ ├── C补.cpp │ ├── b.cpp │ ├── d.cpp │ ├── e.cpp │ ├── f.cpp │ └── h.cpp │ └── 2013 吉林通化邀请赛 │ ├── a.cpp │ ├── c补.cpp │ ├── d.cpp │ ├── e.cpp │ ├── f.cpp │ ├── g.cpp │ └── h.cpp ├── TopCoder ├── Asia 2014 │ ├── SquareDivisor.cpp │ └── SquareVerification.cpp ├── Beijing 2016 │ ├── 248.96:250 1PY.cpp │ ├── 454.54:500 1PY.cpp │ └── :1000 3P3LY.cpp ├── SRM 100-399 │ ├── SRM 181 │ │ └── D2 933.98:950 1Y.cpp │ ├── SRM 216 │ │ └── :500 1Y.cpp │ ├── SRM 223 │ │ └── 468.91:500 1Y.cpp │ ├── SRM 239 │ │ └── D2 998.44:1000 1Y.cpp │ └── SRM 391 │ │ └── 150.19:500 1Y.cpp ├── SRM 400-499 │ ├── SRM 449 │ │ └── 193.76:250 1Y.cpp │ ├── SRM 453.5 │ │ └── TheAlmostLuckyNumbers.cpp │ ├── SRM 462 │ │ └── 101.03:250 4Y.cpp │ ├── SRM 478 │ │ └── 230.29:250 1Y.cpp │ ├── SRM 479 │ │ └── 102.11:250 3Y.cpp │ ├── SRM 488 │ │ ├── 220.69:250 1Y.cpp │ │ └── TheBoredomDivTwo[248.00OF250 1Ydiv2].cpp │ ├── SRM 490 │ │ ├── Hieroglyphs[300.00OF1000 2Ydiv2].cpp │ │ └── Starport[417.95OF500 1Ydiv2].cpp │ ├── SRM 491 │ │ ├── 859.26:1000 1Ydiv2].cpp │ │ ├── 900 LY.cpp │ │ ├── 95.41:250 1Y].cpp │ │ └── :600.00 4Y].cpp │ ├── SRM 492 │ │ ├── TimeTravellingGardener[235.03OF250 1Y].cpp │ │ └── TimeTravellingSalesman[974.19OF1000 1Ydiv2].cpp │ ├── SRM 493 │ │ ├── AmoebaCode[135.00OF450 xY].cpp │ │ ├── CrouchingAmoebas[300.00OF1000 xYdiv2].cpp │ │ └── StonesGame[xOF300 xY].cpp │ ├── SRM 494 │ │ ├── AlternatingLane[150.00OF500 3Y].cpp │ │ └── Painting[141.34OF250 2Y].cpp │ ├── SRM 495 │ │ ├── CarrotBoxes[150.00Of500 -nY].cpp │ │ ├── ColorfulCards[xOF275 1Y].cpp │ │ └── HexagonPuzzle[665.16OF1000 1ydiv2].cpp │ ├── SRM 496 │ │ ├── ColoredStrokes[225.68OF250 1Y].cpp │ │ ├── OneDimensionalBalls[194.87OF500 1Y].cpp │ │ └── PalindromfulString[300.00OF1000 -4Ydiv2].cpp │ ├── SRM 497 │ │ ├── MakeSquare[513.28OF1000 3Ydiv2].cpp │ │ └── PermutationSignature[183.60OF250 xY].cpp │ ├── SRM 498 │ │ ├── FoxSequence[223.03OF250 1Y].cpp │ │ ├── FoxStones[428.31OF450 1Y].cpp │ │ └── NinePuzzle[408.10OF1000 1Ydiv2].cpp │ └── SRM 499 │ │ ├── ColorfulRabbits[241.78OF250 1Y].cpp │ │ ├── PalindromeGame[349.12O1000 2Ydiv2].cpp │ │ └── WhiteSpaceEditing[165.00OF550 5Y].cpp ├── SRM 500-599 │ ├── SRM 500 │ │ └── GeometricProgressions[896.67OF1000 1Ydiv2].cpp │ ├── SRM 508 │ │ └── 356.82:500 1Y.cpp │ ├── SRM 510 │ │ └── 328.90:500 2Y.cpp │ ├── SRM 518 │ │ └── 838.33:1k LY.cpp │ ├── SRM 519 │ │ └── 193.92:250 2Y.cpp │ ├── SRM 520 │ │ └── 207.06:500 1Y.cpp │ ├── SRM 522 │ │ └── 329.22:450 1Y.cpp │ ├── SRM 524 │ │ └── MagicDiamonds[245.37OF250 1Y].cpp │ ├── SRM 525 │ │ ├── DropCoins[273.67OF300 1Y].cpp │ │ └── Rumor[241.07OF500 1RY].cpp │ ├── SRM 526.5 │ │ └── MagicStonesStore[248.65OF250 1Ydiv2].cpp │ ├── SRM 526 │ │ └── DucksAlignment[179.18OF250 1Y].cpp │ ├── SRM 527 │ │ └── P8XGraphBuilder[148.53OF275 1Y].cpp │ ├── SRM 528 │ │ └── Cut[243.85OF250 1Y].cpp │ ├── SRM 529 │ │ └── KingSort[234.70OF250 1Y].cpp │ ├── SRM 530 │ │ └── GogoXCake[228.34OF250 1(2)Y].cpp │ ├── SRM 531 │ │ └── NoRepeatPlaylist[NULLOF300 1Y].cpp │ ├── SRM 532 │ │ └── DengklekMakingChains[189.37OF300 3Y].cpp │ ├── SRM 533 │ │ └── CasketOfStar[184.59OF250 1Y].cpp │ ├── SRM 534 │ │ └── EllysCheckers[207.47OF250 1Y].cpp │ ├── SRM 535 │ │ └── FoxAndGCDLCM[247.24OF250 1Y].cpp │ ├── SRM 536 │ │ └── MergersDivOne[245.75OF250 1Y].cpp │ ├── SRM 537 │ │ └── KingXNewCurrency[204.09OF250 1Y].cpp │ ├── SRM 538 │ │ └── EvenRoute[232.00OF250 1Y].cpp │ ├── SRM 539 │ │ └── Over9000Rocks[75.00OF250 3Y].cpp │ ├── SRM 540 │ │ └── ImportantSequence[119.73OF250 4Y].cpp │ ├── SRM 541 │ │ └── AntsMeet[195.22OF250 2Y].cpp │ ├── SRM 542 │ │ └── PatrolRoute[221.76OF250 1Y].cpp │ ├── SRM 543 │ │ └── EllysXors[238.79OF250 1Y].cpp │ ├── SRM 544 │ │ └── ElectionFraudDiv1[184.71OF275 2Y].cpp │ ├── SRM 545 │ │ └── StrIIRec[170.1OF275 1Y].cpp │ ├── SRM 546 │ │ └── KleofasTail[141.65OF250 2Y].cpp │ ├── SRM 547 │ │ └── Pillars[156.56OF250 3Y].cpp │ ├── SRM 548 │ │ └── KingdomAndTrees[236.05OF250 1Y].cpp │ ├── SRM 549 │ │ └── PointyWizardHats[NULLOF250 1Y].cpp │ ├── SRM 550 │ │ └── RotatingBot[132.15OF300 2Y].cpp │ ├── SRM 551 │ │ └── ColorfulChocolates[181.59OF250 1Y].cpp │ ├── SRM 552 │ │ └── FoxPaintingBalls[154.37OF250 1Y].cpp │ ├── SRM 553 │ │ └── Suminator[160.25OF250 2Y].cpp │ ├── SRM 554 │ │ └── TheBrickTowerEasyDivOne[180.33OF250 2Y].cpp │ ├── SRM 555 │ │ └── CuttingBitString[209.77OF255 1Y].cpp │ ├── SRM 556 │ │ └── XorTravelingSalesman[236.51OF250 1Y].cpp │ ├── SRM 557 │ │ └── FoxAndMountainEasy[147.09OF250 3Y].cpp │ ├── SRM 558 │ │ └── Stamp[85.12OF275 1Y].cpp │ ├── SRM 559 │ │ └── HyperKnight[135.25OF250 1Y].cpp │ ├── SRM 560 │ │ └── TomekPhone[241.39OF250 1Y].cpp │ ├── SRM 561 │ │ └── ICPCBalloons[-75.00OF250 2Y].cpp │ ├── SRM 562 │ │ └── PastingPaintingDivOne[145.92OF250 1Y].cpp │ ├── SRM 563 │ │ └── FoxAndHandle[210.84OF300 1Y].cpp │ ├── SRM 564 │ │ └── KnightCircuit2[121.96OF250 5Y].cpp │ ├── SRM 565 │ │ └── MonstersValley[229.55OF250 1Y].cpp │ ├── SRM 566 │ │ └── PenguinSledding[188.72OF250 1Y].cpp │ ├── SRM 567 │ │ └── TheSquareRootDilemma[230.94OF250 1Y].cpp │ ├── SRM 568 │ │ └── BallsSeparating[232.30OF250 1Y].cpp │ ├── SRM 569 │ │ └── TheDevice[140.69OF250 3Y].cpp │ ├── SRM 570 │ │ └── RobotHerb[228.14OF250 1Y].cpp │ ├── SRM 571 │ │ └── FoxAndMp3[175.75OF250 2Y].cpp │ ├── SRM 572 │ │ └── NewArenaPassword[152.30OF250 1Y].cpp │ ├── SRM 573 │ │ └── TeamContest[165.18OF250 2Y].cpp │ ├── SRM 574 │ │ └── TheNumberGame[243.58OF275 1Y].cpp │ ├── SRM 575 │ │ ├── TheNumberGameDivOne[191.40OF250 1Y].cpp │ │ └── TheSwapsDivOne[158.71OF250 1Y].cpp │ ├── SRM 576 │ │ └── ArcadeManao[256 1Y].cpp │ ├── SRM 577 │ │ ├── EllysChessboard[0OF500 1Y].cpp │ │ └── EllysRoomAssignmentsDiv1[122.81OF250 1Y].cpp │ ├── SRM 578 │ │ ├── GooseInZooDivOne[149.36OF250 2Y].cpp │ │ └── WolfInZooDivOne[221.35OF500 -5Y].cpp │ ├── SRM 579 │ │ ├── TravellingPurchasingMan[135.00OF450 4Y].cpp │ │ └── UndoHistory[105.58OF250 2Y].cpp │ ├── SRM 590 │ │ └── FoxAndChess[186.52OF250 2Y].cpp │ ├── SRM 591 │ │ └── 245.22:275 1Y.cpp │ ├── SRM 595 │ │ └── LittleElephantAndIntervalsDiv1[247.49OF250 1Y].cpp │ ├── SRM 596 │ │ └── IncrementAndDoubling[205.31OF250 2Y].cpp │ └── SRM 599 │ │ ├── BigFatInteger[203.73OF250 1Y].cpp │ │ └── FindPolygons[补OF500 3Y].cpp ├── SRM 600-699 │ ├── SRM 600 │ │ ├── ORSolitaire[236.26OF250 1Y].cpp │ │ └── PalindromeMatrix[180.00OF600 1Y].cpp │ ├── SRM 601 │ │ └── WinterAndPresents[234.06OF250 1Y].cpp │ ├── SRM 602 │ │ └── TypoCoderDiv1[171.47OF250 1Y].cpp │ ├── SRM 603 │ │ └── 250 LY.cpp │ ├── SRM 605 │ │ └── AlienAndHamburgers.cpp │ ├── SRM 606 │ │ ├── EllysNumberGuessing[242.58OF250 1Y].cpp │ │ └── EllysPairing[135.00OF450 28Y].cpp │ ├── SRM 607 │ │ └── PalindromicSubstringsDiv1[222.35OF250 1Y].cpp │ ├── SRM 609 │ │ ├── MagicalStringDiv1[246.14OF250 1Y].cpp │ │ └── PackingBallsDiv1[383.74OF250 1Y].cpp │ ├── SRM 610 │ │ ├── AlbertoTheAviator[334.29OF550 1Y].cpp │ │ └── TheMatrix[226.50OF250 1Y].cpp │ ├── SRM 611 │ │ └── LCMSet[75.OF250 2Y].cpp │ ├── SRM 612 │ │ ├── EmoticonsDiv1[211.04OF250 2Y].cpp │ │ └── SpecialCells[301.63OF450 1Y].cpp │ ├── SRM 613 │ │ ├── RandomGCD[205.86OF500 1Y].cpp │ │ └── TaroFriends[245.32OF250 1Y].cpp │ ├── SRM 614 │ │ └── MinimumSquare[218.85OF250 1Y].cpp │ ├── SRM 615 │ │ └── AmebaDiv1[186.02OF250 1Y].cpp │ ├── SRM 616 │ │ └── WakingUp[151.65OF250 2Y].cpp │ ├── SRM 617 │ │ └── MyLongCake[243.22OF250 1Y].cpp │ ├── SRM 618 │ │ └── Family[232.89OF250 1Y].cpp │ ├── SRM 619 │ │ └── SplitStoneGame[130.64OF250 2Y].cpp │ ├── SRM 620 │ │ ├── PairGame[75.0OF250 1P2Y].cpp │ │ └── PerfectSquare[240OF800 1P3Y].cpp │ ├── SRM 621 │ │ ├── RadioRange[247.41OF275 1PY].cpp │ │ └── TreesAnalysis[334.82OF500 1PY].cpp │ ├── SRM 622 │ │ └── BuildingRoutes[173.65OF250 1Y].cpp │ ├── SRM 623 │ │ ├── CatchTheBeat[328.58OF450 1Y].cpp │ │ └── UniformBoard[254.58OF300 1P1Y].cpp │ ├── SRM 624 │ │ ├── BuildingHeights[243.39OF250 1Y].cpp │ │ └── DrivingPlans[135.00OF450 5Y].cpp │ ├── SRM 625 │ │ ├── Div2$AddMultiply.cpp │ │ ├── Div2$ConundrumReloaded.cpp │ │ ├── Div2$IncrementingSequence[2Y].cpp │ │ └── PalindromePermutations[186.05OF250 2Y].cpp │ ├── SRM 626 │ │ ├── FixedDiceGameDiv1[217.14OF250 1PY].cpp │ │ └── NegativeGraphDiv1[395.73OF600 1P1Y].cpp │ ├── SRM 627 │ │ ├── GraphInversions[306.73OF500].cpp │ │ └── HappyLetterDiv1[237.47OF250].cpp │ ├── SRM 628 │ │ ├── CircuitsConstruction[_OF500 0P1Y].cpp │ │ └── DivisorsPower[164.71OF250 1PY].cpp │ ├── SRM 629 │ │ ├── CandyDrawing.cpp │ │ └── RectangleCovering.cpp │ ├── SRM 632 │ │ ├── CandyCupRunningCompetition.cpp │ │ └── PotentialArithmeticSequence.cpp │ ├── SRM 633 │ │ └── PeriodicJumping.cpp │ ├── SRM 634 │ │ └── ShoppingSurveyDiv1[229.04OF250 1PY].cpp │ ├── SRM 635 │ │ ├── ColourHolic.cpp │ │ ├── SimilarRatingGraph.cpp │ │ └── StoryFromTCO.cpp │ ├── SRM 636 │ │ └── ChocolateDividingEasy.cpp │ ├── SRM 639 │ │ └── AliceGame.cpp │ ├── SRM 641 │ │ ├── ShufflingCardsDiv1.cpp │ │ └── TrianglesContainOrigin.cpp │ ├── SRM 650 │ │ └── 234.72:250 1Y.cpp │ ├── SRM 651 │ │ └── 235.87:250 1Y.cpp │ ├── SRM 663 │ │ └── 251.92:550 1PY.cpp │ ├── SRM 668 │ │ └── 270.89:450 Y.cpp │ ├── SRM 669 │ │ └── 179.03:500 LY.cpp │ ├── SRM 670 │ │ └── 167.55:450 Y.cpp │ ├── SRM 671 │ │ └── 218.58:500 Y.cpp │ ├── SRM 672 │ │ └── 202.31:500 LY.cpp │ ├── SRM 673 │ │ └── 180.00:600 Y.cpp │ ├── SRM 675 │ │ └── 214.18:500 LY.cpp │ ├── SRM 676 │ │ └── 288.19:450 Y.cpp │ ├── SRM 677 │ │ └── 262.29:500 1PY.cpp │ ├── SRM 678 │ │ ├── 213.40:250 1PY.cpp │ │ └── 276.87:500 1PY.cpp │ ├── SRM 679 │ │ └── 231.25:250 1PY.cpp │ ├── SRM 680 │ │ ├── 215.58:450 1PY.cpp │ │ └── 227.70:250 1PY.cpp │ ├── SRM 681 │ │ └── 900 LY.cpp │ ├── SRM 683 │ │ ├── 246.91:250 1PY.cpp │ │ └── 310.14:500 1PY.cpp │ ├── SRM 684 │ │ └── 227.07:250 1PY.cpp │ ├── SRM 685 │ │ └── 223.81:250 1PY.cpp │ ├── SRM 687 │ │ ├── 180.53:250 1PY.cpp │ │ └── 314.44:500 1PY.cpp │ ├── SRM 689 │ │ ├── 224.27:250 1PY.cpp │ │ └── 328.36:500 1PY.cpp │ ├── SRM 691 │ │ └── 500 LY.cpp │ ├── SRM 692 │ │ ├── 106.31:250 2Y.cpp │ │ ├── 185.36:500 1Y.cpp │ │ └── 409.74:900 LY.cpp │ ├── SRM 693 │ │ ├── 1000 LY.cpp │ │ ├── 250 1PLY.cpp │ │ └── 600 LY.cpp │ ├── SRM 694 │ │ ├── 233.67:250 1PY.cpp │ │ ├── 299.37:500 1PY.cpp │ │ └── 900 LY.cpp │ └── SRM 695 │ │ ├── 300 1PLY.cpp │ │ └── 500 0PLY.cpp ├── TCHS │ ├── TCHS SRM 1 │ │ ├── SpeedRadar.cpp │ │ ├── SymbolFrequency.cpp │ │ └── TroytownKeeper.cpp │ ├── TCHS SRM 2 │ │ ├── ApocalypseSomeday.cpp │ │ ├── FountainOfLife.cpp │ │ └── Wizarding.cpp │ └── TCHS SRM 3 │ │ ├── BestDecomposition.cpp │ │ ├── BestSeller.cpp │ │ └── KidsWordGame.cpp ├── TCO │ ├── TCO 13 R2C │ │ ├── 182.35:250 2Y.cpp │ │ └── 214.42:550 1Y.cpp │ ├── TCO 14 R2C │ │ └── :900 1P1Y.cpp │ ├── TCO 16 R2B │ │ ├── 133.49:300 1PY.cpp │ │ └── :500 0PLY.cpp │ ├── TCO 16 R2C │ │ ├── 186.83:250 1PY.cpp │ │ ├── 380.59:800 1PY.cpp │ │ └── 600 LY.cpp │ └── TCO 17 R1B │ │ ├── 244.61 of 250 1PY.cpp │ │ ├── 437.98 of 500 1PY.cpp │ │ └── 828.11 of 1000 1PY.cpp └── list.txt ├── USACO ├── 1.2 │ ├── 1.2.2.cpp │ ├── 1.2.3.cpp │ └── 1.2.4.cpp ├── 1.3 │ ├── 1.3.2.cpp │ ├── 1.3.3.cpp │ ├── 1.3.5.cpp │ └── 1.3.6.cpp ├── 1.4 │ ├── 1.4.2.cpp │ ├── 1.4.3.cpp │ ├── 1.4.4.cpp │ └── 1.4.5.cpp └── 1.5 │ ├── 1.5.2.cpp │ ├── 1.5.3.cpp │ ├── 1.5.4.cpp │ └── 1.5.5.cpp ├── Uva ├── 100 - The 3n + 1 problem.cpp ├── 10000 - Longest Paths.cpp ├── 10003 - Cutting Sticks.cpp ├── 10004 - Bicoloring.cpp ├── 10006 - Carmichael Numbers.cpp ├── 10008 - What's Cryptanalysis.cpp ├── 10010 - Where's Waldorf.cpp ├── 10013 - Super long sums.cpp ├── 10014 - Simple calculations.cpp ├── 10018 - Reverse and Add.cpp ├── 10019 - Funny Encryption Method.cpp ├── 10025 - The n = k problem.cpp ├── 10026 - Shoemaker's Problem.cpp ├── 10033 - Interpreter.cpp ├── 10034 - Freckles.cpp ├── 10035 - Primary Arithmetic.cpp ├── 10036 - Divisibility.cpp ├── 10038 - Jolly Jumpers.cpp ├── 10041 - Vito's Family.cpp ├── 10048 - Audiophobia.cpp ├── 10049 - Self-describing Sequence.cpp ├── 10050 - Hartals.cpp ├── 10055 - Hashmat the Brave Warrior.cpp ├── 10066 - The Twin Towers.cpp ├── 10071 - Back to High School Physics.cpp ├── 10079 - Pizza Cutting.cpp ├── 10082 - WERTYU.cpp ├── 10093 - An Easy Problem!.cpp ├── 10098 - Generating Fast(STL).cpp ├── 10098 - Generating Fast.cpp ├── 10099 - The Tourist Guide.cpp ├── 101 - The Blocks Problem.cpp ├── 10106 - Product.cpp ├── 10107 - What is the Median.cpp ├── 10110 - Light, more light.cpp ├── 10112 - Myacm Triangles.cpp ├── 10115 - Automatic Editing.cpp ├── 10127 - Ones.cpp ├── 10130 - SuperSale.cpp ├── 10131 - Is Bigger Smarter.cpp ├── 10137 - The Trip.cpp ├── 10142 - Australian Voting.cpp ├── 10147 - Highways.cpp ├── 10161 - Ant on a Chessboard.cpp ├── 10170 - The Hotel with Infinite Rooms.cpp ├── 10177 - Sqr Rects Cubes Boxes.cpp ├── 10180 - Rope Crisis in Ropeland!.cpp ├── 10189 - Minesweeper.cpp ├── 10192 - Vacation.cpp ├── 10196 - Check The Check.cpp ├── 102 - Ecological Bin Packing.cpp ├── 10222 - Decode the Mad man.cpp ├── 10235 - Simply Emirp.cpp ├── 10250 - The Other Two Trees.cpp ├── 10252 - Common Permutation.cpp ├── 10260 - Soundex.cpp ├── 10267 - Graphical Editor.cpp ├── 10281 - Average Speed.cpp ├── 10285 - Longest Run on a Snowboard.cpp ├── 10298 - Power Strings.cpp ├── 103 - Stacking Boxes.cpp ├── 10300 - Ecological Premium.cpp ├── 10302 - Summation of Polynomials.cpp ├── 10305 - Ordering Tasks.cpp ├── 10310 - Dog and Gopher.cpp ├── 10324 - Zeros and Ones.cpp ├── 10327 - Flip Sort.cpp ├── 10338 - Mischievous Children.cpp ├── 10340 - All in All.cpp ├── 10341 - Solve It.cpp ├── 10344 - 23 out of 5.cpp ├── 10346 - Peter's Smokes.cpp ├── 10361 - Automatic Poetry.cpp ├── 10363 - Tic Tac Toe.cpp ├── 10369 - Arctic Network.cpp ├── 10375 - Choose and divide.cpp ├── 10382 - Watering Grass.cpp ├── 10392 - Factoring Large Numbers.cpp ├── 10405 - Longest Common Subsequence.cpp ├── 10420 - List of Conquests.cpp ├── 10424 - Love Calculator.cpp ├── 10427 - Naughty Sleepy Boys.cpp ├── 10450 - World Cup Noise.cpp ├── 10465 - Homer Simpson.cpp ├── 10469 - To Carry or not to Carry.cpp ├── 10474 - Where is the Marble.cpp ├── 10496 - Collecting Beepers.cpp ├── 10499 - The Land of Justice.cpp ├── 105 - The Skyline Problem.cpp ├── 10509 - R U Kidding Mr. Feynman.cpp ├── 10515 - Powers Et Al..cpp ├── 10530 - Guessing Game.cpp ├── 10533 - Digit Primes.cpp ├── 10534 - Wavio Sequence.cpp ├── 10550 - Combination Lock.cpp ├── 10585 - Center of symmetry.cpp ├── 10591 - Happy Number.cpp ├── 10608 - Friends.cpp ├── 10642 - Can You Solve It.cpp ├── 10656 - Maximum Sum (II).cpp ├── 10666 - The Eurocup is Here!.cpp ├── 10689 - Yet another Number Sequence.cpp ├── 10696 - f91.cpp ├── 10700 - Camel trading.cpp ├── 10714 - Ants.cpp ├── 10719 - Quotient Polynomial.cpp ├── 10763 - Foreign Exchange.cpp ├── 10773 - Back to Intermediate Math.cpp ├── 10783 - Odd Sum.cpp ├── 10784 - Diagonal.cpp ├── 10785 - The Mad Numerologist.cpp ├── 10790 - How Many Points of Intersection.cpp ├── 108 - Maximum Sum.cpp ├── 10807 - Prim.cpp ├── 10812 - Beat the Spread!.cpp ├── 10815 - Andy's First Dictionary.cpp ├── 10878 - Decode the tape.cpp ├── 10879 - Code Refactoring.cpp ├── 10881 - Piotr's Ants.cpp ├── 10895 - Matrix Transpose.cpp ├── 10905 - Children's Game.cpp ├── 10916 - Factstone Benchmark.cpp ├── 10921 - Find the Telephone.cpp ├── 10922 - 2 the 9s.cpp ├── 10924 - Prime Words.cpp ├── 10929 - You can say 11.cpp ├── 10931 - Parity.cpp ├── 10935 - Throwing cards away I.cpp ├── 10940 - Throwing cards away II.cpp ├── 10943 - How do you add.cpp ├── 10945 - Mother bear.cpp ├── 10954 - Add All.cpp ├── 10970 - Big Chocolate.cpp ├── 10994 - Simple Addition.cpp ├── 11039 - Building designing.cpp ├── 11042 - Complex, difficult and complicated.cpp ├── 11044 - Searching for Nessy.cpp ├── 11057 - Exact Sum.cpp ├── 11059 - Maximum Product.cpp ├── 11085 - Back to the 8-Queens.cpp ├── 111 - History Grading.cpp ├── 11100 - The Trip, 2007.cpp ├── 11130 - Billiard bounces.cpp ├── 11137 - Ingenuous Cubrency.cpp ├── 11151 - Longest Palindrome.cpp ├── 11172 - Relational Operator.cpp ├── 11185 - Ternary.cpp ├── 11192 - Group Reverse.cpp ├── 11202 - The least possible effort.cpp ├── 11218 - KTV.cpp ├── 11231 - Black and white painting.cpp ├── 11247 - Income Tax.cpp ├── 11292 - Dragon of Loowater.cpp ├── 11296 - Counting Solutions to an Integral Equation.cpp ├── 113 - Power of Cryptography.cpp ├── 11300 - Spreading the Wealth.cpp ├── 11313 - Gourmet Games.cpp ├── 11321 - Sort! Sort!! and Sort!!!.cpp ├── 11332 - Summing Digits.cpp ├── 11340 - Newspaper.cpp ├── 11344 - The Huge One.cpp ├── 11362 - Phone List.cpp ├── 11364 - Parking.cpp ├── 11371 - Number Theory for Newbies.cpp ├── 11384 - Help is needed for Dexter.cpp ├── 11388 - GCD LCM.cpp ├── 11389 - The Bus Driver Problem.cpp ├── 11417 - GCD.cpp ├── 11428 - Cubes.cpp ├── 11456 - Trainsorting.cpp ├── 11461 - Square Numbers.cpp ├── 11462 - Age Sort.cpp ├── 11464 - Even Parity.cpp ├── 11498 - Division of Nlogonia.cpp ├── 11526 - H(n).cpp ├── 11530 - SMS Typing.cpp ├── 11538 - Chess Queen.cpp ├── 11541 - Decoding.cpp ├── 11547 - Automatic Answer.cpp ├── 11559 - Event Planning.cpp ├── 11584 - Partitioning by Palindromes.cpp ├── 116 - Unidirectional TSP.cpp ├── 1160 - X-Plosives.cpp ├── 11614 - Etruscan Warriors Never Play Chess.cpp ├── 11631 - Dark roads.cpp ├── 11636 - Hello World!.cpp ├── 11689 - Soda Surpler.cpp ├── 11703 - sqrt log sin.cpp ├── 11713 - Abstract Names.cpp ├── 11723 - Numbering Roads.cpp ├── 11727 - Cost Cutting.cpp ├── 11729 - Commando War.cpp ├── 11733 - Airports.cpp ├── 11764 - Jumping Mario.cpp ├── 11790 - Murcia's Skyline.cpp ├── 11799 - Horror Dash.cpp ├── 11805 - Bafana Bafana.cpp ├── 11827 - Maximum GCD.cpp ├── 11875 - Brick Game.cpp ├── 11877 - The Coco-Cola Store.cpp ├── 11879 - Multiple of 17.cpp ├── 11888 - Abnormal 89's.cpp ├── 11889 - Benefit.cpp ├── 11900 - Boiled Eggs.cpp ├── 11934 - Magic Formula.cpp ├── 11942 - Lumberjack Sequencing.cpp ├── 11947 - Cancer or Scorpio.cpp ├── 11968 - In The Airport.cpp ├── 11970 - Lucky Numbers.cpp ├── 11984 - A Change in Thermal Unit.cpp ├── 11991 - Easy Problem from Rujia Liu.cpp ├── 11995 - I Can Guess the Data Structure.cpp ├── 12015 - Google is Feeling Lucky.cpp ├── 12019 - Doom's Day Algorithm.cpp ├── 1210 - Sum of Consecutive Prime Numbers.cpp ├── 12289 - One-Two-Three.cpp ├── 1329 - Corporative Network.cpp ├── 1339 - Ancient Cipher.cpp ├── 136 - Ugly Numbers打表法.cpp ├── 136 - Ugly Numbers的打表程序.cpp ├── 1368 - DNA Consensus String.cpp ├── 1388 - Graveyard.cpp ├── 146 - ID Codes.cpp ├── 147 - Dollars.cpp ├── 151 - Power Crisis.cpp ├── 152 - Tree's a Crowd.cpp ├── 1587 - Box.cpp ├── 160 - Factors and Factorials.cpp ├── 167 - The Sultan's Successors.cpp ├── 193 - Graph Coloring.cpp ├── 208 - Firetruck.cpp ├── 216 - Getting in Line.cpp ├── 231 - Testing the CATCHER.cpp ├── 255 - Correct Move.cpp ├── 264 - Count on Cantor.cpp ├── 272 - TEX Quotes.cpp ├── 278 - Chess.cpp ├── 294 - Divisors.cpp ├── 299 - Train Swapping.cpp ├── 305 - Joseph.cpp ├── 311 - Packets.cpp ├── 340 - Master-Mind Hints.cpp ├── 369 - Combinations.cpp ├── 371 - Ackermann Functions.cpp ├── 374 - Big Mod.cpp ├── 375 - Inscribed Circles and Isosceles Triangles.cpp ├── 382 - Perfection.cpp ├── 392 - Polynomial Showdown.cpp ├── 401 - Palindromes.cpp ├── 406 - Prime Cuts.cpp ├── 408 - Uniform Generator.cpp ├── 409 - Excuses, Excuses!.cpp ├── 412 - Pi.cpp ├── 413 - Up and Down Sequences.cpp ├── 414 - Machined Surfaces.cpp ├── 417 - Word Index.cpp ├── 422 - Word-Search Wonder.cpp ├── 423 - MPI Maelstrom.cpp ├── 424 - Integer Inquiry.cpp ├── 439 - Knight Moves.cpp ├── 440 - Eeny Meeny Moo.cpp ├── 441 - Lotto.cpp ├── 443 - Humble Numbers.cpp ├── 445 - Marvelous Mazes.cpp ├── 455 - Periodic Strings.cpp ├── 457 - Linear Cellular Automata.cpp ├── 458 - The Decoder.cpp ├── 459 - Graph Connectivity.cpp ├── 465 - Overflow.cpp ├── 474 - Heads Tails Probability.cpp ├── 481 - What Goes Up.cpp ├── 483 - Word Scramble.cpp ├── 488 - Triangle Wave.cpp ├── 489 - Hangman Judge.cpp ├── 490 - Rotating Sentences.cpp ├── 494 - Kindergarten Counting Game.cpp ├── 495 - Fibonacci Freeze.cpp ├── 499 - What's The Frequency, Kenneth.cpp ├── 514 - Rails.cpp ├── 524 - Prime Ring Problem.cpp ├── 530 - Binomial Showdown.cpp ├── 531 - Compromise.cpp ├── 532 - Dungeon Master.cpp ├── 534 - Frogger.cpp ├── 537 - Artificial Intelligence.cpp ├── 541 - Error Correction.cpp ├── 543 - Goldbach's Conjecture.cpp ├── 545 - Heads.cpp ├── 567 - Risk.cpp ├── 568 - Just the Facts.cpp ├── 572 - Oil Deposits.cpp ├── 573 - The Snail.cpp ├── 575 - Skew Binary.cpp ├── 579 - ClockHands.cpp ├── 591 - Box of Bricks.cpp ├── 621 - Secret Research.cpp ├── 623 - 500!.cpp ├── 624 - CD.cpp ├── 640 - Self Numbers.cpp ├── 641 - Do the Untwist.cpp ├── 642 - Word Amalgamation.cpp ├── 644 - Immediate Decodability.cpp ├── 673 - Parentheses Balance.cpp ├── 674 - Coin Change.cpp ├── 686 - Goldbach's Conjecture (II).cpp ├── 694 - The Collatz Sequence.cpp ├── 696 - How Many Knights.cpp ├── 701 - The Archeologists' Dilemma.cpp ├── 706 - LCD Display.cpp ├── 713 - Adding Reversed Numbers.cpp ├── 729 - The Hamming Distance Problem.cpp ├── 750 - 8 Queens Chess Problem.cpp ├── 757 - Gone Fishing.cpp ├── 793 - Network Connections.cpp ├── 821 - Page Hopping.cpp ├── 834 - Continued Fractions.cpp ├── 847 - A Multiplication Game.cpp ├── 880 - Cantor Fractions.cpp ├── 900 - Brick Wall Patterns.cpp ├── 913 - Joana and the Odd Numbers.cpp ├── 962 - Taxicab Numbers.cpp └── 974 - Kaprekar Numbers.cpp ├── Zoj ├── 1576.cpp ├── 2107.cpp ├── 2337.java ├── 2340.cpp ├── 2562.cpp ├── 2674.cpp ├── 2860.cpp ├── 3329.cpp ├── 3421.cpp ├── 3605.cpp ├── 3728.cpp ├── 3732.cpp ├── 3733.cpp ├── 3768.cpp ├── 3772.cpp ├── 3774(any big prime).cpp ├── 3774.cpp └── 3825.java ├── _Template ├── Data Structure.md ├── Data Structure │ ├── BIT.cpp │ ├── HLD.cpp │ ├── SA.cpp │ ├── SAM.cpp │ ├── SGT.cpp │ ├── kDT.cpp │ ├── kmp.cpp │ ├── treap.cpp │ └── tree_divide_conquer.cpp ├── Graph Theory │ ├── GeneralGraphMatch.cpp │ ├── MaxFlow.cpp │ ├── MinCostFlow.cpp │ ├── bcc_edge.cpp │ ├── bcc_node.cpp │ └── minimum_directed_tree.cpp ├── Math.md ├── Math │ ├── BigNum.cpp │ ├── FFT.cpp │ ├── FWT.cpp │ ├── Gaussian_elimination.cpp │ ├── Matrix.cpp │ ├── NTT.cpp │ ├── Partition.cpp │ ├── Polya.cpp │ ├── Polynomial_interpolation.cpp │ ├── Simplex.cpp │ ├── Simpson.cpp │ ├── det_mod.cpp │ ├── fraction.cpp │ ├── sqrtBigInteger.java │ ├── 无标号树计数.cpp │ └── 直线下格点统计.cpp ├── Number Theory.md ├── Number Theory │ ├── BSGS.cpp │ ├── CRT.cpp │ ├── Millar&rho.cpp │ ├── Pell.java │ ├── eulerPhi.cpp │ ├── extGcd.cpp │ ├── modInv.cpp │ ├── moebius.cpp │ ├── primeSieve.cpp │ ├── 二次剩余.cpp │ ├── 二次模方程.cpp │ ├── 线性递推求mod后最小.cpp │ └── 阶乘模分解.cpp ├── Tp~ Computational geometry.md ├── Tp~ Else.md ├── Tp~ Game Theory.md ├── Tp~ Tips.md └── template.cpp ├── merge_poj list.txt └── setup.sh /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | **/.cph 3 | *.bin 4 | .vscode -------------------------------------------------------------------------------- /Codeforces/ECPC 2013/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | freopen("ghanophobia.in","r",stdin); 5 | int T; 6 | scanf("%d",&T); 7 | for(int CA=1;CA<=T;CA++){ 8 | int a,b; 9 | scanf("%d:%d",&a,&b); 10 | a++; 11 | b+=6; 12 | if(a==b){ 13 | b+=b-6; 14 | a++; 15 | } 16 | printf("Case %d: ",CA); 17 | if(a>b)printf("YES\n"); 18 | else if(a 2 | using namespace std; 3 | #define MP make_pair 4 | #define PB push_back 5 | #define OP begin() 6 | #define ED end() 7 | #define BB second 8 | #define AA first 9 | #define SZ size() 10 | typedef pair PII; 11 | int main(){ 12 | freopen("cubes.in","r",stdin); 13 | int i,j,T; 14 | scanf("%d",&T); 15 | for(int CA=1;CA<=T;CA++){ 16 | int vis[105],n,a[105]; 17 | scanf("%d",&n); 18 | for(i=0;iL; 21 | for(i=1;i<=n;i++)L.PB(MP(vis[i],-i)); 22 | sort(L.OP,L.ED); 23 | reverse(L.OP,L.ED); 24 | sort(a,a+n); 25 | for(i=0;i 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | #define NAME "" 15 | #define UsingFile 0 16 | 17 | int main(){ 18 | if(UsingFile)freopen(NAME".in","r",stdin); 19 | if(UsingFile)freopen(NAME".out","w",stdout); 20 | int i,j,k,_T; 21 | int n; 22 | while(~scanf("%d",&n)){ 23 | int a[1111]; 24 | for(i=1;i<=n;i++)a[i]=i; 25 | for(i=n-1;i>=1;i--)swap(a[i],a[i+1]); 26 | for(i=1;i<=n;i++)printf("%d ",a[i]); 27 | printf("\n"); 28 | } 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Codeforces/Round #140 (Both)/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | #define NAME "" 15 | #define VER 1 16 | 17 | int main(){ 18 | if(!VER)freopen(NAME".in","r",stdin); 19 | if(!VER)freopen(NAME".out","w",stdout); 20 | int i,j,k,_T; 21 | int x[3],y[3]; 22 | for(i=0;i<3;i++)cin>>x[i]>>y[i]; 23 | LL px=x[1]-x[0],py=y[1]-y[0]; 24 | LL qx=x[2]-x[1],qy=y[2]-y[1]; 25 | LL f=px*qy-py*qx; 26 | if(f==0)puts("TOWARDS"); 27 | else if(f<0)puts("RIGHT"); 28 | else puts("LEFT"); 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Codeforces/Round #198/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | using namespace std; 23 | vectorL; 24 | vector::iterator iter; 25 | int main() { 26 | int n, i, x; 27 | cin >> n; 28 | for (i = 1; i <= n; i++) { 29 | cin >> x; 30 | iter = lower_bound (L.begin(), L.end() , x); 31 | if(iter!=L.end())*iter = x; 32 | else L.push_back(x); 33 | } 34 | cout << L.size() << endl; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Codeforces/Round #198/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | using namespace std; 23 | 24 | int main(){ 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /Codeforces/Round #246/D.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Codeforces/Round #246/D.cpp -------------------------------------------------------------------------------- /Codeforces/Round #267 (Div.2)/C.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Codeforces/Round #267 (Div.2)/C.cpp -------------------------------------------------------------------------------- /Codeforces/Round #270/A.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Codeforces/Round #270/A.cpp -------------------------------------------------------------------------------- /Codeforces/Round #280 (Div.2)/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | 15 | int main(){ 16 | int i,j,k,_T; 17 | int n; 18 | while(~scanf("%d",&n)){ 19 | int id=1; 20 | while(n>=id*(1+id)/2){ 21 | n-=id*(1+id)/2; 22 | id++; 23 | } 24 | id--; 25 | printf("%d\n",id); 26 | } 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Codeforces/Round #281 (Div.2)/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | 15 | int main(){ 16 | int i,j,k,_T; 17 | int n; 18 | while(~scanf("%d",&n)){ 19 | if(n&1)printf("black\n"); 20 | else printf("white\n1 2\n"); 21 | } 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Codeforces/Round #346 (Div.2)/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | const LL MOD = 1000000007; 15 | const double PI = acos(-1.); 16 | const double eps = 1e-9; 17 | int main(){ 18 | int i,j,k,_T; 19 | while(cin>>i>>j>>k){ 20 | int x=((j+k)%i+i)%i; 21 | if(!x)x+=i; 22 | cout< 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | const LL MOD = 1000000007; 15 | const double PI = acos(-1.); 16 | const double eps = 1e-9; 17 | int main(){ 18 | int i,j,k,_T; 19 | cin>>i; 20 | cout<<(i-4)/2<<"\n"; 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Codeforces/Round #354 (Div.2)/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | const LL MOD = 1000000007; 15 | const double PI = acos(-1.); 16 | const double eps = 1e-9; 17 | int main(){ 18 | int i,j,k,_T; 19 | int n; 20 | while(~scanf("%d",&n)){ 21 | int le=-1,re=-1; 22 | for(i=1;i<=n;i++){ 23 | scanf("%d",&j); 24 | if(j==1)le=i; 25 | if(j==n)re=i; 26 | } 27 | int ret=0; 28 | if(le1)cmax(ret,le-1); 31 | if(re>1)cmax(ret,re-1); 32 | cout< 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | const LL MOD = 1000000007; 15 | const double PI = acos(-1.); 16 | const double eps = 1e-9; 17 | int main(){ 18 | int i,j,k,_T; 19 | int w[5]; 20 | for(i=0;i<5;i++)scanf("%d",&w[i]); 21 | int sum=0; 22 | for(i=0;i<5;i++)sum+=w[i]; 23 | int ans=sum; 24 | for(i=0;i<5;i++) 25 | for(j=i+1;j<5;j++)if(w[i]==w[j]){ 26 | cmin(ans,sum-w[i]*2); 27 | for(k=j+1;k<5;k++)if(w[j]==w[k]){ 28 | cmin(ans,sum-w[i]*3); 29 | } 30 | 31 | } 32 | cout< 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | const LL MOD = 1000000007; 15 | const double PI = acos(-1.); 16 | const double eps = 1e-9; 17 | int main(){ 18 | int i,j,k,_T; 19 | int a,n,t[111]; 20 | while(~scanf("%d%d",&n,&a)){ 21 | for(i=1;i<=n;i++)scanf("%d",&t[i]); 22 | int ans=0; 23 | for(i=0;i0&&a-i>=1)sum+=t[a-i],what++; 28 | if(sum==what)ans+=sum; 29 | } 30 | cout< 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | const LL MOD = 1000000007; 15 | const double PI = acos(-1.); 16 | const double eps = 1e-9; 17 | int main(){ 18 | int i,j,k,_T; 19 | int n; 20 | while(cin>>n){ 21 | int flag=0; 22 | while(n--){ 23 | string s;int x,y; 24 | cin>>s>>x>>y; 25 | if(x>=2400&&y>x)flag=1; 26 | } 27 | if(flag)cout<<"YES\n";else cout<<"NO\n"; 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Codeforces/Round #357 (Div.2)/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | const LL MOD = 1000000007; 15 | const double PI = acos(-1.); 16 | const double eps = 1e-9; 17 | int main(){ 18 | int i,j,k,_T; 19 | int n; 20 | while(cin>>n){ 21 | int flag=0; 22 | for(i=0;i<=n;i+=1234567){ 23 | for(j=i;j<=n;j+=123456){ 24 | if((n-j)%1234==0)flag=1; 25 | } 26 | } 27 | if(flag)cout<<"YES\n"; 28 | else cout<<"NO\n"; 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Else/CC_SUBLCM.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Else/CC_SUBLCM.cpp -------------------------------------------------------------------------------- /Final.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Final.pdf -------------------------------------------------------------------------------- /Hdu/1695.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Hdu/1695.cpp -------------------------------------------------------------------------------- /Hdu/1850.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int m; 5 | while ( cin>>m ) { 6 | if ( !m ) 7 | break; 8 | int i,a[110]; 9 | for ( i=1; i<=m; i++ ) 10 | cin>>a[i]; 11 | int tp=0; 12 | for ( i=1; i<=m; i++ ) 13 | tp=tp xor a[i]; 14 | int res=0; 15 | if ( tp>0 ) 16 | for ( i=1; i<=m; i++ ) 17 | if ( ( a[i] xor tp )< a[i] ) 18 | res++; 19 | cout< 2 | #include 3 | int min(int a,int b){ 4 | if(a>b)return b;return a; 5 | } 6 | int dp[110][2]; 7 | int main(){ 8 | int t; 9 | scanf("%d",&t); 10 | while(t--){ 11 | char s[110]; 12 | scanf("%s",s); 13 | int len=strlen(s); 14 | int i; 15 | dp[0][0]=0;dp[0][1]=1; 16 | for(int j=0;j='a'&&s[j]<='z'){ 19 | dp[i][0]=min(dp[j][0]+1,dp[j][1]+2); 20 | dp[i][1]=min(dp[j][0]+2,dp[j][1]+2); 21 | } 22 | else { 23 | dp[i][0]=min(dp[j][0]+2,dp[j][1]+2); 24 | dp[i][1]=min(dp[j][1]+1,dp[j][0]+2); 25 | } 26 | } 27 | printf("%d\n",min(dp[len][0],dp[len][1]+1)); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Hdu/2815.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Hdu/2815.cpp -------------------------------------------------------------------------------- /Hdu/2979.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Hdu/2979.cpp -------------------------------------------------------------------------------- /Hdu/3826.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define LL long long 4 | int main(){ 5 | int k,z; 6 | scanf("%d",&z); 7 | for(k=1;k<=z;k++){ 8 | LL i,n; 9 | int flag=1; 10 | scanf("%I64d",&n); 11 | printf("Case %d: ",k); 12 | if(n==1){ 13 | printf("Yes\n"); 14 | continue; 15 | } 16 | for(i=1;i*i*i<=n;i++){ 17 | if(n%i==0){ 18 | n/=i; 19 | if(n%i==0&&i!=1){ 20 | flag=0; 21 | break; 22 | } 23 | } 24 | if(flag){ 25 | double p=sqrt((double)n); 26 | if(floor(p+0.5)==p)flag=0; 27 | if(!flag)break; 28 | } 29 | } 30 | if(flag)printf("Yes\n"); 31 | else printf("No\n"); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Hdu/4347.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Hdu/4347.cpp -------------------------------------------------------------------------------- /Hdu/4870.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Hdu/4870.cpp -------------------------------------------------------------------------------- /Hdu/5028.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Hdu/5028.cpp -------------------------------------------------------------------------------- /Hdu/5146.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define MP make_pair 4 | #define PB push_back 5 | #define AA first 6 | #define BB second 7 | #define OP begin() 8 | #define ED end() 9 | #define SZ size() 10 | #define cmin(x,y) x=min(x,y) 11 | #define cmax(x,y) x=max(x,y) 12 | #define NAME "" 13 | 14 | int w[1005]; 15 | int main(){ 16 | int i,j,k,_T; 17 | scanf("%d",&_T); 18 | while(_T--){ 19 | int n; 20 | scanf("%d",&n); 21 | int s[3]; 22 | s[0]=s[1]=0; 23 | for(i=0;i 2 | #include 3 | #define PI acos(-1) 4 | int main(){ 5 | int T,t; 6 | scanf("%d",&T); 7 | for(t=1;t<=T;t++){ 8 | double x,y; 9 | scanf("%lf%lf",&x,&y); 10 | double r=sqrt(x*x+y*y); 11 | double S=PI*r*r/2; 12 | int res=S/50; 13 | if(res*50 2 | #include 3 | int dp[40][40][40]; 4 | int back(int x,int y,int z){ 5 | x%=23,y%=28,z%=33; 6 | int &tp=dp[x][y][z]; 7 | if(tp!=-1)return tp; 8 | return tp=1+back(x+1,y+1,z+1); 9 | } 10 | int main(){ 11 | memset(dp,-1,sizeof(dp)); 12 | dp[0][0][0]=0; 13 | int x,y,z,w,T=0; 14 | while(scanf("%d%d%d%d",&x,&y,&z,&w)!=EOF){ 15 | if(x==-1&&y==-1&&z==-1&&w==-1)break; 16 | if(x<0)x+=((-x)/23+1)*23; 17 | if(y<0)y+=((-y)/28+1)*28; 18 | if(z<0)z+=((-z)/33+1)*33; 19 | int res=23*28*33-back(x,y,z)-w; 20 | if(res<=0)res+=23*28*33; 21 | printf("Case %d: the next triple peak occurs in %d days.\n",++T,res); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Poj/1008.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | char haab[30][10]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"}; 6 | char tzol[30][10]={ "imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"}; 7 | int main(){ 8 | int t; 9 | for(scanf("%d",&t),printf("%d\n",t);t;t--){ 10 | char s[30]; 11 | int d,y; 12 | scanf("%d. %s %d",&d,s,&y);getchar(); 13 | int mm=0; 14 | while(strcmp(haab[mm],s)!=0)mm++; 15 | int DD=365*y+mm*20+d; 16 | int Y=DD/260; 17 | int X=DD%260; 18 | printf("%d %s %d\n",X%13+1,tzol[X%20],Y); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Poj/1014.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define REP(i,n) for(i=0;i<=n;i++) 4 | using namespace std; 5 | int main(){ 6 | int q,w,e,r,t,y; 7 | int Q,W,E,R,T,Y; 8 | int TT=0; 9 | while(cin>>q>>w>>e>>r>>t>>y){ 10 | if(!q&&!w&&!e&&!r&&!t&&!y)break; 11 | q%=8;w%=8;e%=8;r%=8;t%=8;y%=8; 12 | int tot=1*q+2*w+3*e+4*r+5*t+6*y; 13 | int flag=0; 14 | REP(Q,q)REP(W,w)REP(E,e)REP(R,r)REP(T,t)REP(Y,y){ 15 | int TOT=1*Q+2*W+3*E+4*R+5*T+6*Y; 16 | if(TOT*2==tot)flag=1; 17 | } 18 | printf("Collection #%d:\n",++TT); 19 | if(flag)printf("Can be divided.\n\n"); 20 | else printf("Can't be divided.\n\n"); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Poj/1015.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1015.cpp -------------------------------------------------------------------------------- /Poj/1039.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1039.cpp -------------------------------------------------------------------------------- /Poj/1046.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | double pow2(double x){return x*x;} 5 | int main() { 6 | int OFFL=0; 7 | #ifndef ONLINE_JUDGE 8 | OFFL=1; 9 | #endif 10 | int rgb[22][4]; 11 | int i,j; 12 | for(i=1;i<=16;i++)for(j=1;j<=3;j++)scanf("%d",&rgb[i][j]); 13 | int r,g,b; 14 | while(scanf("%d%d%d",&r,&g,&b)!=EOF){ 15 | if(r==-1&&g==-1&&b==-1)break; 16 | double dis=99999; 17 | int to=-1; 18 | for(i=1;i<=16;i++){ 19 | double s=sqrt(pow2(rgb[i][1]-r)+pow2(rgb[i][2]-g)+pow2(rgb[i][3]-b)); 20 | if(s 2 | #include 3 | #include 4 | using namespace std; 5 | #define N 105 6 | int map[N][N]; 7 | int dp[N][N][N]; 8 | int main(){ 9 | int n; 10 | while(scanf("%d",&n)!=EOF){ 11 | int i,j,k,l; 12 | for(i=1;i<=n;i++)for(j=1;j<=n;j++)scanf("%d",&map[i][j]); 13 | memset(dp,0,sizeof(dp)); 14 | int ans=0; 15 | for(i=1;i<=n;i++)for(j=1;j<=n;j++) 16 | dp[i][i][j]=dp[i][i][j-1]+map[i][j]; 17 | for(l=1;l 2 | #include 3 | #include 4 | using namespace std; 5 | const double FF=((sqrt(5)+1)/2); 6 | int main(){ 7 | int a,b; 8 | while(scanf("%d%d",&a,&b)!=EOF){ 9 | if(a 2 | #include 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int OFFL=0; 8 | #ifndef ONLINE_JUDGE 9 | OFFL=1; 10 | #endif 11 | int T; 12 | for ( cin>>T; T--; ) 13 | { 14 | int n; 15 | cin>>n; 16 | int x[1010],y[1010],i,j; 17 | for ( i=1; i<=n; i++ ) 18 | cin>>x[i]>>y[i]; 19 | int h[210]; 20 | for ( i=1; i<=200; i++ ) 21 | h[i]=0; 22 | for ( i=1; i<=n; i++ ) 23 | { 24 | int l=min( ( x[i]+1 )/2,( y[i]+1 )/2 ); 25 | int r=max( ( x[i]+1 )/2,( y[i]+1 )/2 ); 26 | for ( j=l; j<=r; j++ ) 27 | h[j]++; 28 | } 29 | int ans=0; 30 | for ( i=1; i<=200; i++ ) 31 | ans=max( ans,h[i] ); 32 | cout< 2 | #include 3 | int count(int y){ 4 | int res=0,tp=y; 5 | while(y){ 6 | res+=y%10;y/=10; 7 | } 8 | return res; 9 | } 10 | bool Smith(int x){ 11 | int left=count(x); 12 | int i,right=0; 13 | int tp=x; 14 | for(i=2;i*i<=tp;i++){ 15 | while(x%i==0){ 16 | right+=count(i); 17 | x/=i; 18 | } 19 | } 20 | if(!right)return 0; 21 | if(x-1)right+=count(x); 22 | return left==right; 23 | } 24 | int main(){ 25 | int n; 26 | while(scanf("%d",&n)!=EOF&&n){ 27 | while(n++){ 28 | if(Smith(n)){ 29 | printf("%d\n",n); 30 | break; 31 | } 32 | } 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Poj/1152.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int f(char x){ 5 | if(x>='0'&&x<='9')return x-'0'; 6 | if(x>='A'&&x<='Z')return x-'A'+10; 7 | if(x>='a'&&x<='z')return x-'a'+36; 8 | return 0; 9 | } 10 | char s[40000]; 11 | int main(){ 12 | while(scanf("%s",s)!=EOF){ 13 | int len=strlen(s),i,j; 14 | int res=2; 15 | for(i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | char l[5010],r[5010]; 6 | unsigned short dp[2][5010]; 7 | int main(){ 8 | int len; 9 | while(scanf("%d",&len)!=EOF){ 10 | int i,j; 11 | scanf("%s",l); 12 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | int map[110][110],dp[110][110]; 7 | int main() 8 | { 9 | int OFFL=0; 10 | #ifndef ONLINE_JUDGE 11 | OFFL=1; 12 | #endif 13 | int n; 14 | while ( scanf( "%d",&n )!=EOF ) 15 | { 16 | int i,j; 17 | for ( i=1; i<=n; i++ ) 18 | for ( j=1; j<=i; j++ ) 19 | scanf( "%d",&map[i][j] ); 20 | memset( dp,0,sizeof( dp ) ); 21 | for ( i=1; i<=n; i++ ) 22 | for ( j=1; j<=i; j++ ) 23 | dp[i][j]=max( dp[i-1][j-1],dp[i-1][j] )+map[i][j]; 24 | int ans=0; 25 | for(i=1;i<=n;i++)ans=max(ans,dp[n][i]); 26 | printf("%d\n",ans); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Poj/1228.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1228.cpp -------------------------------------------------------------------------------- /Poj/1256.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | bool cmp(const char x,const char y){ 6 | if(x-y=='A'-'a')return 1; 7 | if(y-x=='A'-'a')return 0; 8 | char xx=x,yy=y; 9 | if(xx>='a')xx-='a'; 10 | if(xx>='A')xx-='A'; 11 | if(yy>='a')yy-='a'; 12 | if(yy>='A')yy-='A'; 13 | return xx",s); 26 | sort(s,s+len,cmp); 27 | // printf("%s\n",s); 28 | do{ 29 | puts(s); 30 | }while(next_permutation(s,s+len,cmp)); 31 | } 32 | return 0;} 33 | -------------------------------------------------------------------------------- /Poj/1279.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1279.cpp -------------------------------------------------------------------------------- /Poj/1286.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1286.cpp -------------------------------------------------------------------------------- /Poj/1292.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1292.cpp -------------------------------------------------------------------------------- /Poj/1329.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1329.cpp -------------------------------------------------------------------------------- /Poj/1408.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1408.cpp -------------------------------------------------------------------------------- /Poj/1410.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1410.cpp -------------------------------------------------------------------------------- /Poj/1474.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1474.cpp -------------------------------------------------------------------------------- /Poj/1496.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1496.cpp -------------------------------------------------------------------------------- /Poj/1517.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | double e=2.5; 4 | printf("n e\n"); 5 | printf("- -----------\n"); 6 | printf("0 1\n"); 7 | printf("1 2\n"); 8 | printf("2 2.5\n"); 9 | double t=2; 10 | for(int i=3;i<10;i++){ 11 | t*=i; 12 | e+=1/t; 13 | printf("%d %.9lf\n",i,e); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Poj/1519.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int f (int x) { 3 | if (x < 10) return x; 4 | int tot = 0; 5 | while (x) { 6 | tot += x % 10; 7 | x /= 10; 8 | } 9 | return f (tot); 10 | } 11 | char s[100010]; 12 | int main() { 13 | for (; scanf ("%s", s) != EOF;) { 14 | if(s[0]=='0')break; 15 | int n = 0; 16 | for (int i = 0; s[i] != 0; i++) n += s[i] - '0'; 17 | printf ("%d\n", f (n)); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Poj/1523.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1523.cpp -------------------------------------------------------------------------------- /Poj/1556.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1556.cpp -------------------------------------------------------------------------------- /Poj/1631.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | vectorL; 6 | vector::iterator it; 7 | int main(){ 8 | int T; 9 | for(scanf("%d",&T);T;T--){ 10 | L.clear(); 11 | int n; 12 | scanf("%d",&n); 13 | int i,x; 14 | for(i=1;i<=n;i++){ 15 | scanf("%d",&x); 16 | it=lower_bound(L.begin(),L.end(),x); 17 | if(it==L.end())L.push_back(x); 18 | else *it=x; 19 | } 20 | printf("%d\n",L.size()); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Poj/1658.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int q,w,e,r; 5 | int main() { 6 | int OFFL=0; 7 | #ifndef ONLINE_JUDGE 8 | OFFL=1; 9 | #endif 10 | int T; 11 | cin>>T; 12 | while(T--){ 13 | cin>>q>>w>>e>>r; 14 | if(w-q==e-w&&w-q==r-e){ 15 | printf("%d %d %d %d %d\n",q,w,e,r,r+r-e); 16 | } 17 | else printf("%d %d %d %d %d\n",q,w,e,r,(int)(r*((double)r/e))); 18 | } 19 | return 0;} 20 | -------------------------------------------------------------------------------- /Poj/1661.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1661.cpp -------------------------------------------------------------------------------- /Poj/1664.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | long long dp[11][11]; 3 | //dp[i][j]=dp[i][j-1]+dp[i-j][j]; 4 | int main(){ 5 | int i,j; 6 | for(i=0;i<=10;i++){ 7 | dp[i][1]=1; 8 | for(j=2;j<=10;j++){ 9 | dp[i][j]=dp[i][j-1]; 10 | if(i>=j)dp[i][j]+=dp[i-j][j]; 11 | } 12 | } 13 | int t; 14 | scanf("%d",&t); 15 | while(t--){ 16 | int a,b; 17 | scanf("%d%d",&a,&b); 18 | printf("%I64d\n",dp[a][b]); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Poj/1704.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1704.cpp -------------------------------------------------------------------------------- /Poj/1755.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1755.cpp -------------------------------------------------------------------------------- /Poj/1777.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1777.cpp -------------------------------------------------------------------------------- /Poj/1830.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1830.cpp -------------------------------------------------------------------------------- /Poj/1845.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1845.cpp -------------------------------------------------------------------------------- /Poj/1850.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1850.cpp -------------------------------------------------------------------------------- /Poj/1852.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() { 5 | int T; 6 | scanf ("%d", &T); 7 | while (T--) { 8 | int L,n; 9 | scanf("%d%d",&L,&n); 10 | int x,r1=0,r2=0; 11 | for(int i=1;i<=n;i++){ 12 | scanf("%d",&x); 13 | r1=max(r1,min(x,L-x)); 14 | r2=max(r2,max(x,L-x)); 15 | } 16 | printf("%d %d\n",r1,r2); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Poj/1873.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/1873.cpp -------------------------------------------------------------------------------- /Poj/1995.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int main() { 5 | int T; 6 | scanf("%d",&T); 7 | while(T--){ 8 | long long ans=0,mod; 9 | int n; 10 | cin>>mod>>n; 11 | int i; 12 | for(i=1;i<=n;++i){ 13 | long long a,b; 14 | cin>>a>>b; 15 | long long add=1; 16 | while(b){ 17 | if(b&1){add*=a;add%=mod;} 18 | a*=a;a%=mod; 19 | b/=2; 20 | } 21 | ans+=add; 22 | } 23 | ans%=mod; 24 | cout< 2 | int p1[10010],p2[10010]; 3 | int main(){ 4 | int i,j; 5 | p1[0]=0;p2[0]=0; 6 | int at=0,now=0; 7 | while(1){ 8 | ++now; 9 | for(i=1;i<=now;i++){ 10 | p1[++at]=now; 11 | p2[at]=p2[at-1]+now; 12 | if(at>10000)break; 13 | } 14 | if(at>10000)break; 15 | } 16 | while(scanf("%d",&i)!=EOF&&i)printf("%d %d\n",i,p2[i]); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Poj/2074.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2074.cpp -------------------------------------------------------------------------------- /Poj/2079.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2079.cpp -------------------------------------------------------------------------------- /Poj/2117.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2117.cpp -------------------------------------------------------------------------------- /Poj/2182.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | int a[9010],n; 5 | listL; 6 | list::iterator iter; 7 | listres; 8 | int main(){ 9 | while(scanf("%d",&n)!=EOF){ 10 | int i; 11 | for(i=1;i=1;i--){ 15 | iter=L.begin(); 16 | while(a[i]--)iter++; 17 | res.push_front(*iter); 18 | L.erase(iter); 19 | } 20 | res.push_front(*L.begin()); 21 | iter=res.begin(); 22 | while(iter!=res.end()){ 23 | printf("%d\n",*iter); 24 | iter++; 25 | } 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Poj/2186.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2186.cpp -------------------------------------------------------------------------------- /Poj/2191.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2191.cpp -------------------------------------------------------------------------------- /Poj/2195.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2195.cpp -------------------------------------------------------------------------------- /Poj/2255.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char P[33], I[33]; 4 | void tree (int pl, int pr, int il, int ir) { 5 | char root = P[pl]; 6 | int i, Iroot, bk; 7 | for (i = il; i <= ir; i++) if (I[i] == root) Iroot = i; 8 | bk = pl + Iroot - il; 9 | if (bk > pl && Iroot > il) 10 | tree (pl + 1, bk, il, Iroot - 1); 11 | if (bk < pr && Iroot < ir) 12 | tree (bk + 1, pr, Iroot + 1, ir); 13 | printf ("%c", root); 14 | } 15 | int main() { 16 | while (scanf ("%s%s", P, I) != EOF) { 17 | int i, len = strlen (P), root; 18 | tree (0, len - 1, 0, len - 1); 19 | printf ("\n"); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Poj/2262.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int isp[1000010]; 3 | int p[90000]; 4 | int main(){ 5 | int i,j; 6 | isp[1]=0; 7 | for(i=2;i<=1000000;i++)isp[i]=-1; 8 | for(i=2;i<=1000000;i++){ 9 | if(isp[i]==-1){ 10 | isp[i]=1; 11 | for(j=2;j*i<=1000000;j++)isp[i*j]=0; 12 | } 13 | } 14 | int q=0; 15 | for(i=1;i<=1000000;i++)if(isp[i])p[++q]=i; 16 | int n; 17 | while(scanf("%d",&n)!=EOF&&n){ 18 | for(i=1;i<=q;i++)if(isp[n-p[i]])break; 19 | printf("%d = %d + %d\n",n,p[i],n-p[i]); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Poj/2352.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int LB(int x){return x&(-x);} 3 | #define N 32001 4 | int tree[32010]; 5 | void add(int w,int d){ 6 | for(;w<=N;w+=LB(w))tree[w]+=d; 7 | } 8 | int get_sum(int w){ 9 | int res=0; 10 | for(;w>0;w-=LB(w))res+=tree[w]; 11 | return res; 12 | } 13 | int star[15010]; 14 | int main(){ 15 | int n; 16 | scanf("%d",&n); 17 | int i; 18 | for(i=1;i<=32000+1;i++)tree[i]=0; 19 | for(i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | vectorL; 6 | int main(){ 7 | int n; 8 | while(scanf("%d",&n)!=EOF){ 9 | int i,x; 10 | L.clear(); 11 | for(i=0;i 2 | #define ULL unsigned long long 3 | int main(){ 4 | int n; 5 | while(scanf("%d",&n)!=EOF&&n){ 6 | int i,tp=n; 7 | ULL res=n; 8 | for(i=2;i<=n;i++){ 9 | while(n%i==0){ 10 | res*=(i-1); 11 | res/=i; 12 | while(n%i==0)n/=i; 13 | } 14 | } 15 | printf("%I64u\n",res); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Poj/2409.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2409.cpp -------------------------------------------------------------------------------- /Poj/2447.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2447.cpp -------------------------------------------------------------------------------- /Poj/2479.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2479.cpp -------------------------------------------------------------------------------- /Poj/2516.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2516.cpp -------------------------------------------------------------------------------- /Poj/2540.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2540.cpp -------------------------------------------------------------------------------- /Poj/2762.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2762.cpp -------------------------------------------------------------------------------- /Poj/2826.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2826.cpp -------------------------------------------------------------------------------- /Poj/2888.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/2888.cpp -------------------------------------------------------------------------------- /Poj/2941.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int a[1010][1010]; 6 | int main(){ 7 | int n=0; 8 | for(;scanf("%d",&n)!=EOF;){ 9 | if(!n)break; 10 | int i,j; 11 | int flag=1; 12 | for(i=1;i<=n;i++)for(j=1;j<=n;j++)scanf("%d",&a[i][j]); 13 | for(i=1;i<=n;i++)for(j=i+1;j<=n;j++){ 14 | int l=a[i][j]+a[j][i]; 15 | int r=a[i][i]+a[j][j]; 16 | if(l!=r)flag=0; 17 | } 18 | if(flag)printf("homogeneous\n"); 19 | else printf("not homogeneous\n"); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Poj/2975.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int m; 5 | while ( cin>>m ) { 6 | if ( !m ) 7 | break; 8 | int i,a[110]; 9 | for ( i=1; i<=m; i++ ) 10 | cin>>a[i]; 11 | int tp=0; 12 | for ( i=1; i<=m; i++ ) 13 | tp=tp xor a[i]; 14 | int res=0; 15 | if ( tp>0 ) 16 | for ( i=1; i<=m; i++ ) 17 | if ( ( a[i] xor tp )< a[i] ) 18 | res++; 19 | cout< 2 | int isp[1000010]; 3 | void make_prime() 4 | { 5 | int i,j; 6 | isp[1]=0; 7 | for ( i=2; i<=1000000; i++ ) 8 | isp[i]=1; 9 | for ( i=2; i<=1000000; i++ ) 10 | if ( isp[i] ) 11 | for ( j=2; j*i<=1000000; j++ ) 12 | isp[i*j]=0; 13 | } 14 | int main() 15 | { 16 | make_prime(); 17 | int a,d,n; 18 | while ( scanf( "%d%d%d",&a,&d,&n )!=EOF ) 19 | { 20 | if ( !a&&!d&&!n ) 21 | break; 22 | while ( n-- ){ 23 | while ( !isp[a] ) 24 | a+=d;a+=d;}a-=d; 25 | printf( "%d\n",a ); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Poj/3020.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/3020.cpp -------------------------------------------------------------------------------- /Poj/3030.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int T; 5 | cin>>T; 6 | while(T--){ 7 | int r,e,c; 8 | cin>>r>>e>>c; 9 | if(e-r>c)cout<<"advertise\n"; 10 | else if(e-r==c)cout<<"does not matter\n"; 11 | else cout<<"do not advertise\n"; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Poj/3069.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int main() { 6 | int l, n; 7 | while ( cin >> l >> n ) { 8 | if ( l == -1 && n == -1 ) break; 9 | vector >L; 10 | int i, j, x; 11 | for ( i = 1; i <= n; i++ ) { 12 | cin >> x; 13 | L.push_back ( make_pair ( x + l, x - l ) ); 14 | } 15 | sort ( L.begin(), L.end() ); 16 | int last = L[0].second - 1, ans = 0; 17 | for ( i = 0; i < L.size(); i++ ) { 18 | if ( L[i].second > last ) { 19 | for ( j = i; j < L.size(); j++ ) 20 | if ( L[j].first - l > L[i].first ) break; 21 | last = L[--j].first-l; 22 | ans++; 23 | // cout << last << " >> "; 24 | } 25 | } 26 | // cout << endl; 27 | cout << ans << endl; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Poj/3094.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int f(char x){ 4 | if(x<='z'&&x>='a')x+='A'-'a'; 5 | if(x==' ')return 0; 6 | return x-'A'+1; 7 | } 8 | int main(){ 9 | char s[1010]; 10 | while(gets(s)!=NULL){ 11 | if(strcmp(s,"#")==0)break; 12 | long long res=0; 13 | for(int i=1;i<=strlen(s);++i){ 14 | res+=i*f(s[i-1]); 15 | } 16 | printf("%lld\n",res); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Poj/3096.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | vector >L; 7 | int main(){ 8 | char s[100]; 9 | while(scanf("%s",s)!=EOF) 10 | { 11 | if(strcmp(s,"*")==0)break; 12 | int len=strlen(s); 13 | int flag=0; 14 | for(int i=1;i 2 | #include 3 | #include 4 | using namespace std; 5 | int dp[444][444],mp[444][444]; 6 | int main(){ 7 | int n,j,i; 8 | while(scanf("%d",&n)!=EOF){ 9 | memset(dp,0,sizeof(dp)); 10 | for(i=1;i<=n;i++)for(j=1;j<=i;j++) 11 | scanf("%d",&mp[i][j]); 12 | int ans=0; 13 | for(i=1;i<=n;i++)for(j=1;j<=i;j++){ 14 | dp[i][j]=mp[i][j]; 15 | if(i>1)dp[i][j]=mp[i][j]+dp[i-1][j-1]; 16 | if(j 2 | #include 3 | #include 4 | using namespace std; 5 | priority_queue,greater >L; 6 | int main(){ 7 | int n; 8 | while(scanf("%d",&n)!=EOF){ 9 | while(!L.empty())L.pop(); 10 | int i,x,y; 11 | long long res=0; 12 | for(i=1;i<=n;i++){ 13 | scanf("%d",&x); 14 | L.push(x); 15 | } 16 | while(L.size()>1){ 17 | x=L.top();L.pop(); 18 | y=L.top();L.pop(); 19 | res+=x+y; 20 | L.push(x+y); 21 | } 22 | printf("%I64d\n",res); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Poj/3259.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/3259.cpp -------------------------------------------------------------------------------- /Poj/3278.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | int dp[100010]; 6 | int main() { 7 | int OFFL=0; 8 | #ifndef ONLINE_JUDGE 9 | OFFL=1; 10 | #endif 11 | int n,k; 12 | while(cin>>n>>k){ 13 | memset(dp,-1,sizeof(dp)); 14 | queue >S; 15 | S.push(make_pair(n,0)); 16 | while(!S.empty()&&dp[k]==-1){ 17 | int x=S.front().first; 18 | int t=S.front().second; 19 | S.pop(); 20 | if(x<0||x>100000)continue; 21 | int flag=0; 22 | if(dp[x]==-1)flag=1,dp[x]=t; 23 | else if(dp[x]>t)flag=1,dp[x]=t; 24 | if(!flag)continue; 25 | S.push(make_pair(x+1,t+1)); 26 | S.push(make_pair(x-1,t+1)); 27 | S.push(make_pair(x*2,t+1)); 28 | } 29 | cout< 2 | using namespace std; 3 | int main() { 4 | int OFFL=0; 5 | #ifndef ONLINE_JUDGE 6 | OFFL=1; 7 | #endif 8 | int n,t; 9 | cin>>t; 10 | while(t--){ 11 | cin>>n; 12 | int ans=0,mx=0; 13 | while(n--){ 14 | int x; 15 | cin>>x; 16 | ans =ans xor x; 17 | mx=max(mx,x); 18 | } 19 | if(ans&&mx>1)cout<<"John\n"; 20 | else if(!ans&&mx<=1)cout<<"John\n"; 21 | else cout<<"Brother\n"; 22 | } 23 | return 0;} 24 | -------------------------------------------------------------------------------- /Poj/3528.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Poj/3528.cpp -------------------------------------------------------------------------------- /Poj/3617.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char sl[2010]; 4 | char sr[2010]; 5 | char s[10]; 6 | char ans[2010]; 7 | char *r,*l; 8 | int main() { 9 | int OFFL=0; 10 | #ifndef ONLINE_JUDGE 11 | OFFL=1; 12 | #endif 13 | int n; 14 | for(;~scanf("%d%*c",&n);){ 15 | int i; 16 | for(i=0;i 2 | int main() { 3 | int OFFL=0; 4 | #ifndef ONLINE_JUDGE 5 | OFFL=1; 6 | #endif 7 | int y,m,d,p,q,r; 8 | int t; 9 | scanf("%d",&t); 10 | while(t--){ 11 | scanf("%4d/%2d/%2d-%2d:%2d:%2d",&y,&m,&d,&p,&q,&r); 12 | char c='a'; 13 | if(p>12)c='p',p-=12; 14 | if(p==12)c='p'; 15 | if(p==0)p+=12; 16 | printf("%02d/%02d/%04d-%02d:%02d:%02d%cm\n",m,d,y,p,q,r,c); 17 | } 18 | return 0;} 19 | -------------------------------------------------------------------------------- /Poj/3752.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int dx[]= {0,1,0,-1}; 4 | int dy[]= {1,0,-1,0}; 5 | char map[1010][1010]; 6 | int main() 7 | { 8 | int m,n; 9 | while ( scanf( "%d%d",&n,&m )!=EOF ) 10 | { 11 | int i,j; 12 | for ( i=1; i<=n; i++ ) 13 | for ( j=1; j<=m; j++ ) 14 | map[i][j]=0; 15 | int tot=0; 16 | int p=0,x=1,y=1; 17 | while ( totn||xx<1||yy>m||yy<1||map[xx][yy] ) 22 | p++; 23 | p%=4; 24 | x+=dx[p],y+=dy[p]; 25 | tot++; 26 | } 27 | for ( i=1; i<=n; i++ ) 28 | { 29 | for ( j=1; j<=m; j++ ) 30 | printf( " %c",map[i][j] ); 31 | printf( "\n" ); 32 | } 33 | } 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Poj/3863.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | #define LL long long 5 | LL n,m; 6 | LL u[2222],d[2222]; 7 | int main(){ 8 | // freopen("business.in","r",stdin); 9 | // freopen("business.out","w",stdout); 10 | while(cin>>n>>m){ 11 | int i; 12 | LL ret=-1; 13 | for(i=1;i<=m;i++){ 14 | cin>>u[i]>>d[i]; 15 | LL tot=n*u[i]; 16 | LL p=tot/(u[i]+d[i]); 17 | tot-=p*(u[i]+d[i]); 18 | if(p>0&&tot==0)tot+=u[i]+d[i]; 19 | if(ret==-1&&tot>0)ret=tot; 20 | else if(tot>0)ret=min(ret,tot); 21 | } 22 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | #define LL long long 6 | int main(){ 7 | // freopen("headshot.in","r",stdin); 8 | // freopen("headshot.out","w",stdout); 9 | char s[111]; 10 | while(scanf("%s",s)!=EOF){ 11 | int len=strlen(s); 12 | int i; 13 | int tot0=0; 14 | int tot00=0; 15 | for(i=0;irotb*shoa){printf("ROTATE\n");} 22 | else if(rota*shob 2 | #include 3 | #include 4 | using namespace std; 5 | int main(){ 6 | char s[10]; 7 | while(scanf("%s",s)!=EOF){ 8 | int q=s[0]-'0',w=s[2]-'0',e=s[4]-'0',r=s[6]-'0'; 9 | int gcd=__gcd(w,r); 10 | q*=r/gcd; 11 | e*=w/gcd; 12 | w*=r/gcd;r=w; 13 | int x,y=w; 14 | if(s[3]=='+')x=q+e; 15 | else x=q-e; 16 | if(x){ 17 | gcd=__gcd(abs(x),abs(y)); 18 | x/=gcd,y/=gcd; 19 | if(y>1)cout< 2 | int gcd(int a,int b){ 3 | if(a 2 | using namespace std; 3 | int main() { 4 | int n, i; 5 | while (cin >> n) { 6 | if (n < 9) cout << 0 << endl; 7 | else if (n == 9) cout << 8 << endl; 8 | else { 9 | cout << 72; 10 | for (i = 11; i <= n; i++) cout << 0; 11 | cout << endl; 12 | } 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Sgu/111.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.math.*; 4 | 5 | public class Solution { 6 | public static void main(String args[]) { 7 | Scanner cin = new Scanner(new BufferedInputStream(System.in)); 8 | while(cin.hasNext()){ 9 | BigInteger l,r,mid,aim,ans; 10 | BigInteger z,x,c; 11 | aim=cin.nextBigInteger(); 12 | r=aim; 13 | l=BigInteger.valueOf(0); 14 | ans=r; 15 | while(r.compareTo(l)>0){ 16 | z=r.subtract(l); 17 | if(z.compareTo(BigInteger.ONE)<=0){ 18 | x=r.multiply(r); 19 | if(x.compareTo(aim)<=0) 20 | ans=r; 21 | else ans=l; 22 | break; 23 | } 24 | mid=(l.add(r)).shiftRight(1); 25 | x=mid.multiply(mid); 26 | if(x.compareTo(aim)<=0)l=mid; 27 | else r=mid; 28 | } 29 | System.out.println(ans); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Sgu/113.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | bool solve(int n){ 5 | int i,tp=n; 6 | vectorL; 7 | for(i=2;i*i<=tp;i++){ 8 | while(n%i==0){L.push_back(i);n/=i;} 9 | } 10 | if(n>1)L.push_back(n); 11 | // cout<>T; 20 | while(T--){ 21 | int n; 22 | cin>>n; 23 | string s=solve(n) ?"Yes":"No"; 24 | cout<< s < 2 | using namespace std; 3 | int yue[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 4 | int main() { 5 | #ifndef ONLINE_JUDGE 6 | #endif 7 | int n,m; 8 | while(cin>>n>>m){ 9 | int i,tot=0; 10 | for(i=1;i12||n>yue[m]){ 12 | cout<<"Impossible"< 2 | int a[20][10010]; 3 | int main(){ 4 | int n,m,k; 5 | while(scanf("%d%d%d",&n,&m,&k)!=EOF){ 6 | int i,j; 7 | for(i=1;i<=n;i++){ 8 | scanf("%d",&a[1][i]); 9 | a[1][i]%=k; 10 | for(j=2;j<=14;j++){ 11 | a[j][i]=a[j-1][i]*a[j-1][i]; 12 | a[j][i]%=k; 13 | } 14 | } 15 | int res=0; 16 | int plus[20]; 17 | for(i=1;i<=14;i++){ 18 | if(m%2==1)plus[i]=1; 19 | else plus[i]=0; 20 | m/=2; 21 | } 22 | for(i=1;i<=n;i++){ 23 | int x=1; 24 | for(j=1;j<=14;j++)if(plus[j]){ 25 | x*=a[j][i]; 26 | x%=k; 27 | } 28 | if(x==0)res++; 29 | } 30 | printf("%d\n",res); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Sgu/119.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | setG[10010]; 5 | set::iterator iter; 6 | int main(){ 7 | int n,a,b,x,y; 8 | while(scanf("%d%d%d",&n,&a,&b)!=EOF){ 9 | int i; 10 | for(i=0;i<=n;i++)G[i].clear(); 11 | x=0,y=0; 12 | a%=n;b%=n; 13 | while(1){ 14 | if(G[x].find(y)==G[x].end())G[x].insert(y); 15 | else break; 16 | x+=a;y+=b; 17 | x%=n;y%=n; 18 | } 19 | long long tot=0; 20 | for(i=0;i 2 | unsigned long long F[50],S[50]; 3 | int main(){ 4 | F[0]=0;F[1]=1;S[0]=0;S[1]=1; 5 | int i; 6 | for(i=2;i<41;i++)F[i]=F[i-1]+F[i-2]; 7 | for(i=2;i<41;i++)S[i]=S[i-1]+F[i]; 8 | int n; 9 | while(scanf("%d",&n)!=EOF)printf("%I64u\n",S[n]); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Sgu/124.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Sgu/124.cpp -------------------------------------------------------------------------------- /Sgu/126.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int find(int a,int b){ 4 | if(!a||!b)return 0; 5 | if(a>b)return 1+find(a-b,b+b); 6 | else return 1+find(b-a,a+a); 7 | } 8 | int main(){ 9 | int a,b; 10 | while(cin>>a>>b){ 11 | int tot=a+b; 12 | int gcd=tot&(-tot); 13 | if(a%(tot/gcd)||b%(tot/gcd))cout<<-1< 2 | #include 3 | #include 4 | using namespace std; 5 | int main() { 6 | #ifndef ONLINE_JUDGE 7 | #endif 8 | int i,n,m,x; 9 | cin>>n>>m; 10 | vectorL; 11 | for(i=1;i<=m;i++){ 12 | cin>>x; 13 | if(x>999&&x<8000||x>8999)L.push_back(x); 14 | } 15 | sort(L.begin(),L.end()); 16 | int tot[10]; 17 | for(i=1;i<=7;i++)tot[i]=0; 18 | for(i=0;i 2 | #include 3 | using namespace std; 4 | int main() { 5 | #ifndef ONLINE_JUDGE 6 | #endif 7 | int n; 8 | scanf( "%d",&n ); 9 | int res=1; 10 | res+= ( n&1 )? ( n+1 )/2*n : n/2*( n+1 ) ; 11 | printf( "%d\n",res ); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Sgu/144.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int x,y; 4 | double z; 5 | while(~scanf("%d%d%lf",&x,&y,&z)){ 6 | double l=(y-x)*60; 7 | //y=x+_ z; 8 | double ans=1-((l-z)*(l-z))/(l*l); 9 | printf("%.8lf\n",ans); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Sgu/154.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int count(int x){ 4 | int res=0; 5 | while(x){ 6 | res+=x/5; 7 | x/=5; 8 | } 9 | return res; 10 | } 11 | int Bfind(int l,int r,int aim){ 12 | // cout<=aim)return Bfind(l,mid,aim); 21 | else return Bfind(mid+1,r,aim); 22 | } 23 | int main() { 24 | int n; 25 | cin>>n; 26 | int ans=Bfind(1,500000000,n); 27 | if(ans!=-1)cout< 2 | using namespace std; 3 | long long A[22][22]; 4 | int main(){ 5 | int i,j,t; 6 | for(i=0;i<=10;i++){ 7 | A[i][0]=1; 8 | for(j=1,t=i;j<=i;j++,t--) 9 | A[i][j]=A[i][j-1]*t; 10 | } 11 | int n,k; 12 | while(cin>>n>>k){ 13 | if(k<=n)cout<<(A[n][k]*A[n][k]/A[k][k])< 2 | #include 3 | const int MXN=1000000; 4 | bool isp[MXN+10]; 5 | int main(){ 6 | long long i,j,sn=sqrt(MXN); 7 | for(i=3,isp[2]=1;i<=MXN;i++)isp[i]=i%2; 8 | for(i=3;i<=sn;i++)if(isp[i])for(j=i*i;j<=MXN;j+=2*i)isp[j]=0; 9 | int n; 10 | while(~scanf("%d",&n)){ 11 | int tot=0; 12 | for(i=3;i+2<=n;i+=2)if(isp[i]&&isp[i+2])tot++; 13 | printf("%d\n",tot); 14 | for(i=3;i+2<=n;i+=2)if(isp[i]&&isp[i+2])printf("2 %d\n",i); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Sgu/276.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int s,p; 5 | while(cin>>s>>p){ 6 | int t=p-s; 7 | if(t<=0)cout<<"0\n"; 8 | else if(t<300)cout<<"1\n"; 9 | else if(t<900)cout<<"2\n"; 10 | else if(t<1800)cout<<"3\n"; 11 | else cout<<"4\n"; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Spoj/TABLE.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Spoj/TABLE.cpp -------------------------------------------------------------------------------- /T-shirt/51nod月赛#14/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | const LL MOD = 1000000007; 15 | const double PI = acos(-1.); 16 | const double eps = 1e-9; 17 | int main(){ 18 | int i,j,k,_T; 19 | int n,m; 20 | scanf("%d",&_T); 21 | while(_T--){ 22 | scanf("%d%d",&n,&m); 23 | int cnt=0; 24 | for(int i=0;i 2 | using namespace std; 3 | typedef long long LL; 4 | typedef pair PII; 5 | #define MP make_pair 6 | #define PB push_back 7 | #define AA first 8 | #define BB second 9 | #define OP begin() 10 | #define ED end() 11 | #define SZ size() 12 | #define cmin(x,y) x=min(x,y) 13 | #define cmax(x,y) x=max(x,y) 14 | const LL MOD = 1000000007; 15 | const double PI = acos(-1.); 16 | const double eps = 1e-9; 17 | int main(){ 18 | int i,j,k,_T; 19 | int p,a,b; 20 | scanf("%d%d%d",&p,&a,&b); 21 | if(b>p)printf("-1\n"); 22 | else if(p>=a+b)printf("%d\n",p); 23 | else printf("%d\n",a+b); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /T-shirt/ipsc 2014/J1.txt: -------------------------------------------------------------------------------- 1 | good 2 | good 3 | good 4 | good 5 | bad 6 | good 7 | bad 8 | good 9 | bad 10 | bad 11 | good -------------------------------------------------------------------------------- /T-shirt/ipsc 2014/J2.txt: -------------------------------------------------------------------------------- 1 | good good good good bad good good bad good ones bad bad good bad good -------------------------------------------------------------------------------- /Team/with@Lquartz@shllhs/2009 Asia Harbin Regional/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | //Lquartz 6 | #include 7 | using namespace std; 8 | #define N 101000 9 | #define INF (1 << 10) 10 | int n, m, t; 11 | int pre[N], x[N], a[N], dp[N]; 12 | 13 | int main() { 14 | while (scanf ("%d", &n) != EOF && n) { 15 | memset (x, 0, sizeof (x)); 16 | for (int i = 1; i<= n; i++) { 17 | scanf ("%d", &a[i]); 18 | pre[i] = x[a[i]]; 19 | x[a[i]] = i; 20 | } 21 | memset (dp, 0, sizeof (dp)); 22 | for (int i = n; i > 0; i--) { 23 | dp[i-1] = max (dp[i], dp[i-1]); 24 | if (pre[i] != 0) 25 | dp[pre[i]] = max (dp[pre[i]], dp[i] + (a[i] == 999 ? 3 : 1)); 26 | } 27 | int dmax = 0; 28 | printf ("%d\n", dp[0]); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Team/with@Lquartz@shllhs/2009 Asia Harbin Regional/K.cpp: -------------------------------------------------------------------------------- 1 | //kybconnor 2 | #include 3 | #include 4 | int main() { 5 | char s[1111]; 6 | while (gets (s) !=NULL) { 7 | int len=strlen (s); 8 | int i; 9 | int tot=0; 10 | for (i=0; i='A'&&s[i]<='Z') 11 | tot+=s[i]-'A'+1; 12 | if (tot<=100) printf ("%d\n",tot); 13 | else printf ("INVALID\n"); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Team/with@Lquartz@shllhs/2009 Asia Wuhan Regional/C.cpp: -------------------------------------------------------------------------------- 1 | //kybconnor 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | #define PB push_back 7 | int p[55],L[55],v[55]; 8 | bool isr[1111]; 9 | int main() { 10 | int n,D; 11 | int CASE=0; 12 | while (~scanf ("%d%d",&n,&D)) { 13 | if (n==0&&D==0) break; 14 | int i,j; 15 | for (i=1; i<=n; i++) scanf ("%d%d%d",&p[i],&L[i],&v[i]); 16 | for (i=0; i 3 | #include 4 | #include 5 | #define eps 1e-7 6 | using namespace std; 7 | int main() { 8 | int t,i,j; 9 | double x,y,p,q; 10 | scanf ("%d",&t); 11 | while (t--) { 12 | scanf ("%lf%lf%lf%lf",&x,&y,&p,&q); 13 | double a = q* (p*x+p*y) + (1.0-q) *x; 14 | double b = q*y+ (1.0-q) * (p*x+p*y); 15 | if (a>b+eps) printf ("tiger "); 16 | else printf ("wolf "); 17 | printf ("%.4lf\n",max (a,b)); 18 | } 19 | return 0; 20 | } s 21 | -------------------------------------------------------------------------------- /Team/with@Lquartz@shllhs/2012 NEERC Southern Subregional/J.cpp: -------------------------------------------------------------------------------- 1 | //Lquartz 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int n, a, b; 8 | int main() { 9 | while (scanf ("%d%d%d", &n, &a, &b) != EOF) { 10 | int m = min (n*a, n*b); 11 | for (int i = 1; i <= m; i++) { 12 | int t = i / a + i / b; 13 | if (t >= n) { 14 | int ans = i; 15 | if (i % a != 0) { 16 | ans = i / a * a + a; 17 | t = i / b + ans / a; 18 | } else if (i % b != 0) { 19 | ans = i / b * b + b; 20 | t = i / a + ans / b; 21 | } 22 | printf ("%d %d\n", t, ans); 23 | break; 24 | } 25 | } 26 | 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Team/with@Lquartz@shllhs/2013 Asia Hangzhou Regional/1003.cpp: -------------------------------------------------------------------------------- 1 | //kybconnor 2 | #include 3 | #include 4 | int mx[33][33]; 5 | int n; 6 | int a[33][33]; 7 | int main(){ 8 | int i,j; 9 | while(~scanf("%d",&n)){ 10 | if(n==0)break; 11 | for(i=1;i<=n;i++)for(j=1;j<=n;j++)scanf("%d",&a[i][j]); 12 | for(i=1;i<=n;i++)for(j=1;j<=n;j++)scanf("%d",&mx[i][j]); 13 | int tot[10]; 14 | memset(tot,0,sizeof tot); 15 | for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(a[i][j]==mx[i][j])tot[0]++; 16 | for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(a[i][j]==mx[j][n-i+1])tot[1]++; 17 | for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(a[i][j]==mx[n-j+1][i])tot[2]++; 18 | for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(a[i][j]==mx[n-i+1][n-j+1])tot[3]++; 19 | int res=0; 20 | for(i=0;i<4;i++)if(tot[i]>res)res=tot[i]; 21 | printf("%d\n",res); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Team/with@Lquartz@shllhs/2013 NEERC Eastern Subregional/B.cpp: -------------------------------------------------------------------------------- 1 | //kybconnor 2 | #include 3 | int a[11111],n,k; 4 | int main(){ 5 | while(~scanf("%d%d",&n,&k)){ 6 | int i; 7 | for(i=1;i<=n;i++)scanf("%d",&a[i]); 8 | int big=0,sml=0; 9 | for(i=1;i<=n;i++){ 10 | if(a[i]>=k)big+=a[i]-k; 11 | else sml+=k-a[i]; 12 | } 13 | printf("%d %d\n",big,sml); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Team/with@Lquartz@shllhs/2013 NEERC Eastern Subregional/F.cpp: -------------------------------------------------------------------------------- 1 | //kybconnor 2 | #include 3 | int x[111111]; 4 | int main(){ 5 | int n,k,p; 6 | while(~scanf("%d%d%d",&n,&k,&p)){ 7 | int i; 8 | for(i=1;i<=n-k;i++)x[i]=1; 9 | int now=2,cnt=0; 10 | //1-(cnt)/(i-1)>=p/100 11 | //100(i-1)-100cnt>=(i-1)*p 12 | while(i<=n){ 13 | if(100*(i-1)-100*cnt>=(i-1)*p)x[i]=now,cnt++; 14 | else cnt=1,x[i]=++now; 15 | i++; 16 | } 17 | long long ans=0; 18 | for(i=1;i<=n;i++)ans+=x[i]; 19 | printf("%I64d\n",ans); 20 | printf("%d",x[1]); 21 | for(i=2;i<=n;i++)printf(" %d",x[i]); 22 | printf("\n"); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Team/with@Lquartz@shllhs/2013 ZOJ Monthly March/h.cpp: -------------------------------------------------------------------------------- 1 | //kybconnor shllhs 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | char s[11111]; 7 | int main() { 8 | int i,j; 9 | int n,k; 10 | double w; 11 | while (cin>>n>>w>>k) { 12 | n+=2; 13 | w*=100; 14 | int W; 15 | sprintf (s,"%.0lf", w); 16 | sscanf (s,"%d",&W); //n W k 17 | int num = n/k; 18 | int tot= (n-num) *W; 19 | int per= (tot+1) /2; 20 | printf ("%d.%02d\n",per/100,per%100); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Team/with@Lquartz@shllhs/2013 吉林通化邀请赛/a.cpp: -------------------------------------------------------------------------------- 1 | //shllhs 2 | #include 3 | #include 4 | #include 5 | #include 6 | #define eps 1e-8 7 | using namespace std; 8 | int main() { 9 | int t; 10 | scanf ("%d", &t); 11 | while (t--) { 12 | double a, b = 0.0; 13 | for (int i = 1; i <= 12; i++) { 14 | scanf ("%lf", &a); 15 | b += a; 16 | } 17 | b /= 12.00; 18 | int bb = (int) b; 19 | if (fabs (bb - b) < eps) { 20 | printf ("$%d\n", bb); 21 | } else { 22 | int x = (int) (b * 100.0 + 0.5); 23 | if ( ( (int) (b * 10.0 + 0.5)) * 10 - (int) (b * 100.0 + 0.5) == 0) { 24 | printf ("$%.1lf\n", (double) x / 100.0); 25 | } else { 26 | printf ("$%.2lf\n", (double) x / 100.0); 27 | } 28 | } 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /TopCoder/SRM 400-499/SRM 490/Hieroglyphs[300.00OF1000 2Ydiv2].cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/TopCoder/SRM 400-499/SRM 490/Hieroglyphs[300.00OF1000 2Ydiv2].cpp -------------------------------------------------------------------------------- /TopCoder/SRM 600-699/SRM 612/SpecialCells[301.63OF450 1Y].cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/TopCoder/SRM 600-699/SRM 612/SpecialCells[301.63OF450 1Y].cpp -------------------------------------------------------------------------------- /TopCoder/SRM 600-699/SRM 625/Div2$ConundrumReloaded.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/TopCoder/SRM 600-699/SRM 625/Div2$ConundrumReloaded.cpp -------------------------------------------------------------------------------- /TopCoder/TCHS/TCHS SRM 3/BestDecomposition.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/TopCoder/TCHS/TCHS SRM 3/BestDecomposition.cpp -------------------------------------------------------------------------------- /USACO/1.2/1.2.4.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ID: kybconn1 3 | PROG: namenum 4 | LANG: C++ 5 | */ 6 | #include 7 | #include 8 | #include 9 | using namesapce std; 10 | struct stg{ 11 | char s[15]; 12 | 13 | }tp; 14 | vectordic; 15 | vector::iterator iter; 16 | int main(){ 17 | freopen("namenum.in","r",stdin); 18 | freopen("namenum.out","w",stdout); 19 | int a,b; 20 | while(scanf("%d%d",&a,&b)!=EOF) 21 | printf("%d\n",a+b); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /USACO/1.3/1.3.2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ID: kybconn1 3 | PROG: milk 4 | LANG: C++ 5 | */ 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | struct milk{ 11 | int p,n; 12 | bool operator<(const milk &tp)const{return pL; 15 | int main(){ 16 | freopen("milk.in","r",stdin); 17 | freopen("milk.out","w",stdout); 18 | int n,m; 19 | while(scanf("%d%d",&n,&m)!=EOF){ 20 | L.clear(); 21 | int i; 22 | long long res=0; 23 | for(i=1;i<=m;i++){ 24 | scanf("%d%d",&tp.p,&tp.n); 25 | L.push_back(tp); 26 | } 27 | sort(L.begin(),L.end()); 28 | for(i=0;i=L[i].n){ 30 | n-=L[i].n; 31 | res+=L[i].n*L[i].p; 32 | } 33 | else { 34 | res+=L[i].p*n; 35 | n=0; 36 | } 37 | } 38 | printf("%lld\n",res); 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /USACO/1.5/1.5.2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ID: kybconn1 3 | PROG: numtri 4 | LANG: C++ 5 | */ 6 | #include 7 | using namespace std; 8 | int a[1005][1005]; 9 | int dp[1005][1005]; 10 | #define cmax(x,y) x=max(x,y) 11 | int main() { 12 | freopen( "numtri.in", "r", stdin ); 13 | freopen( "numtri.out", "w", stdout ); 14 | int i,j,n; 15 | while ( ~scanf( "%d",&n ) ) { 16 | for ( i=1; i<=n; i++ )for ( j=1; j<=i; j++ )scanf( "%d",&a[i][j] ); 17 | memset( dp,0,sizeof dp ); 18 | int ans=0; 19 | for ( i=1; i<=n; i++ ) { 20 | dp[i][1]=dp[i-1][1]+a[i][1]; 21 | for ( j=2; j 2 | long long f(long long x) { 3 | long long count=1,p=x; 4 | while(p!=1) { 5 | if(p%2==1) {p=(3*p+1)/2; count+=2;} 6 | else {p/=2; count++;} 7 | } 8 | return count; 9 | } 10 | long long max(long long a,long long b) { 11 | if(a>b)return a; 12 | else return b; 13 | } 14 | int main() { 15 | long long a,b; 16 | while(scanf("%lld%lld",&a,&b)!=EOF) { 17 | long long maax=-1,i; 18 | for(i=a+b-max(a,b); i<=max(a,b); i++) { 19 | maax=max(maax,f(i)); 20 | } 21 | printf("%lld %lld %lld\n",a,b,maax); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Uva/10003 - Cutting Sticks.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/10003 - Cutting Sticks.cpp -------------------------------------------------------------------------------- /Uva/10018 - Reverse and Add.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/10018 - Reverse and Add.cpp -------------------------------------------------------------------------------- /Uva/10025 - The n = k problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int f(int x){return x*(x+1)/2;} 4 | int main(){ 5 | long long n; 6 | int t; 7 | scanf("%d",&t); 8 | while(t--){ 9 | scanf("%lld",&n); 10 | if(n<0)n=-n; 11 | int min; 12 | min=(int)( (sqrt(1.0+8*n)) / 2 ); 13 | while(f(min) 2 | #include 3 | int abs(int y){if(y>0)return y;return -y;} 4 | int cmp(const void *a,const void *b) 5 | { 6 | int *p=(int *)a; 7 | int *q=(int *)b; 8 | return *p-*q; 9 | } 10 | int main() 11 | { 12 | int a[600]; 13 | int n,k,z; 14 | scanf("%d",&z); 15 | for(k=1;k<=z;k++){ 16 | scanf("%d",&n); 17 | int i; 18 | for(i=1;i<=n;i++)scanf("%d",&a[i]); 19 | qsort(&a[1],n,sizeof(int),cmp); 20 | int s=(n+1)/2; 21 | int res=0; 22 | for(i=1;i<=n;i++)res+=abs(a[s]-a[i]); 23 | printf("%d\n",res); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Uva/10049 - Self-describing Sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[6800010]; 3 | int main() 4 | { 5 | int i,j; 6 | dp[1]=1;dp[2]=2; 7 | j=2; 8 | int s=1; 9 | for(i=3;i<=6800000;i++) 10 | { 11 | if(s 2 | int main() 3 | { 4 | int k,z; 5 | scanf("%d",&z); 6 | for(k=1;k<=z;k++) 7 | { 8 | bool date[4000]; 9 | int d,p; 10 | scanf("%d%d",&d,&p); 11 | // printf("%d %d\n",d,p); 12 | int i,j; 13 | for(i=0;i<4000;i++)date[i]=0; 14 | int a[110]; 15 | for(i=1;i<=p;i++)scanf("%d",&a[i]); 16 | for(i=1;i<=p;i++) 17 | { 18 | for(j=1;j*a[i]<=4000;j++)date[j*a[i]]=1; 19 | } 20 | for(i=1;i<=d;i++)if(i%7==6||i%7==0)date[i]=0; 21 | // printf("\n"); 22 | // for(i=1;i<=d;i++){printf("%d ",date[i]);if(i%7==0)printf("\n");} 23 | int sum=0; 24 | for(i=1;i<=d;i++)sum+=date[i]; 25 | printf("%d\n",sum); 26 | } 27 | // return main(); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Uva/10055 - Hashmat the Brave Warrior.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | long long a,b; 5 | while(scanf("%lld%lld",&a,&b)!=EOF) 6 | { 7 | if(b>=a)printf("%lld\n",b-a); 8 | else printf("%lld\n",a-b); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Uva/10066 - The Twin Towers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[110][110]; 3 | int max(int a,int b){ 4 | if(a>b)return a; 5 | return b; 6 | } 7 | int main(){ 8 | int pa,pb; 9 | int a[110],b[110]; 10 | int z=0; 11 | while(scanf("%d%d",&pa,&pb)!=EOF){ 12 | if(pa==0&&pb==0)return 0; 13 | int i,j; 14 | for(i=1;i<=pa;i++)scanf("%d",&a[i]); 15 | for(i=1;i<=pb;i++)scanf("%d",&b[i]); 16 | for(i=0;i<=pa;i++)dp[i][0]=0; 17 | for(i=0;i<=pb;i++)dp[0][i]=0; 18 | for(i=1;i<=pa;i++)for(j=1;j<=pb;j++){ 19 | if(a[i]==b[j])dp[i][j]=dp[i-1][j-1]+1; 20 | else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); 21 | } 22 | printf("Twin Towers #%d\n",++z); 23 | printf("Number of Tiles : %d\n\n",dp[pa][pb]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Uva/10071 - Back to High School Physics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int v,t; 5 | while(scanf("%d%d",&v,&t)!=EOF) 6 | { 7 | printf("%d\n",2*v*t); 8 | } 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Uva/10079 - Pizza Cutting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | long long b; 5 | while(scanf("%lld",&b)!=EOF) 6 | { 7 | if(b<0)break; 8 | unsigned long long a=b; 9 | printf("%llu\n",(a+1)*a/2+1); 10 | } 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Uva/10093 - An Easy Problem!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int f(char x){ 5 | if(x>='0'&&x<='9')return x-'0'; 6 | if(x>='A'&&x<='Z')return x-'A'+10; 7 | if(x>='a'&&x<='z')return x-'a'+36; 8 | return 0; 9 | } 10 | int main(){ 11 | char s[1010]; 12 | while(scanf("%s",s)!=EOF){ 13 | int len=strlen(s),i,j; 14 | int res=2; 15 | for(i=0;i 2 | #include 3 | #include 4 | int main(){ 5 | char s[110]; 6 | int t; 7 | scanf("%d",&t); 8 | while(t--){ 9 | scanf("%s",s); 10 | int len=strlen(s); 11 | std::sort(s,s+len); 12 | do{ 13 | printf("%s\n",s); 14 | }while(std::next_permutation(s,s+len)); 15 | printf("\n"); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Uva/10106 - Product.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define ENTER printf("\n") 4 | char a[1010],b[1010]; 5 | int x[1010],o[1010],y[1010]; 6 | int lena,lenb; 7 | int main(){ 8 | while(scanf("%s%s",a,b)!=EOF){ 9 | lena=strlen(a); 10 | lenb=strlen(b); 11 | int i,j; 12 | for(i=0;i=1;i--)printf("%d",o[i]);ENTER; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Uva/10107 - What is the Median.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | std::vector q; 5 | int main(){ 6 | q.clear(); 7 | int x; 8 | while(scanf("%d",&x)!=EOF){ 9 | q.push_back(x); 10 | sort(q.begin(),q.end()); 11 | int len=q.size(); 12 | if(len%2==1)printf("%d\n",q[len/2]); 13 | else printf("%d\n",(q[len/2]+q[len/2-1])/2); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Uva/10110 - Light, more light.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | long long n; 6 | while(scanf("%lld",&n)==1) 7 | { 8 | if(n==0)break; 9 | if (floor(sqrt(n))==ceil(sqrt(n)))printf("yes\n"); 10 | else printf("no\n"); 11 | } 12 | return 0;} 13 | -------------------------------------------------------------------------------- /Uva/10127 - Ones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | while(scanf("%d",&n)==1) 6 | { 7 | long long k=1,ws=1; 8 | while(k%n) 9 | { 10 | k%=n; 11 | k*=10;k+=1; 12 | k%=n; 13 | ws++; 14 | } 15 | printf("%d\n",ws); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Uva/10130 - SuperSale.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/10130 - SuperSale.cpp -------------------------------------------------------------------------------- /Uva/10161 - Ant on a Chessboard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | while(scanf("%d",&n)!=EOF) 6 | { 7 | if(n==0)break; 8 | int i; 9 | for(i=1;i*i 2 | int main() 3 | { 4 | long long s,d; 5 | while(scanf("%lld%lld",&s,&d)!=EOF) 6 | { 7 | long long i;i=0; 8 | while(1) 9 | { 10 | if( (i+1)*i/2+(i+1)*s >=(double)d)break; 11 | i++; 12 | } 13 | printf("%lld\n",s+i); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Uva/10177 - Sqr Rects Cubes Boxes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[110][10]; 3 | int main(){ 4 | int n; 5 | while(scanf("%d",&n)!=EOF){ 6 | long long s2,r2,s3,r3,s4,r4; 7 | long long z=(n+1)*n/2; 8 | s2=0;r2=z*z; 9 | s3=0;r3=r2*z; 10 | s4=0;r4=r3*z; 11 | int i; 12 | for(i=1;i<=n;i++){ 13 | s2+=i*i; 14 | s3+=i*i*i; 15 | s4+=i*i*i*i; 16 | } 17 | r4-=s4;r3-=s3;r2-=s2; 18 | printf("%lld %lld %lld %lld %lld %lld\n",s2,r2,s3,r3,s4,r4); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Uva/10192 - Vacation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int dp[110][110]; 4 | int main() 5 | { 6 | int count=1; 7 | char a[110],b[110]; 8 | while(gets(a)) 9 | { 10 | if(a[0]=='#')break; 11 | gets(b); 12 | int j,i,sa=strlen(a),sb=strlen(b); 13 | for(i=0;i<=110;i++)dp[0][i]=0; 14 | for(i=0;i<=110;i++)dp[i][0]=0; 15 | for(i=1;i<=sa;i++)for(j=1;j<=sb;j++) 16 | { 17 | if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1; 18 | else if(dp[i-1][j]>=dp[i][j-1])dp[i][j]=dp[i-1][j]; 19 | else dp[i][j]=dp[i][j-1]; 20 | } 21 | printf("Case #%d: you can visit at most %d cities.\n",count++,dp[sa][sb]); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Uva/10222 - Decode the Mad man.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char s[]="?czaqsdfyghjbvui?w?etx??r?"; 4 | char f(char x){ 5 | if(x>='A'&&x<='Z')return s[x-'A']; 6 | if(x>='a'&&x<='z')return s[x-'a']; 7 | if(x=='[')return 'o'; 8 | if(x==']')return 'p'; 9 | if(x==';')return 'k'; 10 | if(x=='\'')return 'l'; 11 | if(x==',')return 'n'; 12 | if(x=='.')return 'm'; 13 | if(x=='?')return ','; 14 | if(x=='\\')return '['; 15 | return x; 16 | } 17 | int main(){ 18 | char s[1010]; 19 | while(gets(s)!=NULL){ 20 | int i,len=strlen(s); 21 | for(i=0;i 2 | int dp[1000010]; 3 | int isp[1000010]; 4 | int f(int x){ 5 | int i; 6 | int res=0; 7 | while(x>0){ 8 | res*=10; 9 | res+=x%10; 10 | x/=10; 11 | } 12 | return res; 13 | } 14 | int is_prime(int x){ 15 | int i; 16 | for(i=2;i*i<=x;i++){ 17 | if(x%i==0)return 0; 18 | } 19 | return 1; 20 | } 21 | int main(){ 22 | /* int i; 23 | for(i=2;i<=1000000;i++)isp[i]=is_prime(i); 24 | for(i=2;i<=1000000;i++){ 25 | if(isp[i]){ 26 | if(isp[f(i)])dp[i]=2; 27 | else dp[i]=1; 28 | } 29 | else dp[i]=0; 30 | }*/ 31 | int n; 32 | while(scanf("%d",&n)!=EOF){ 33 | if(is_prime(n)&&is_prime(f(n))&&f(n)!=n)printf("%d is emirp.\n",n); 34 | else if(is_prime(n))printf("%d is prime.\n",n); 35 | else printf("%d is not prime.\n",n); 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Uva/10250 - The Other Two Trees.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | double x1,y1,x2,y2; 4 | while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF){ 5 | double x0=(x1+x2)/2,y0=(y1+y2)/2; 6 | double px=x1-x0,py=y1-y0; 7 | double qx=py,qy=-px; 8 | printf("%lf %lf %lf %lf\n",x0+qx,y0+qy,x0-qx,y0-qy); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Uva/10252 - Common Permutation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | char a[10010],b[10010]; 5 | int main(){ 6 | while(gets(a)!=NULL){ 7 | gets(b); 8 | int la=strlen(a); 9 | int lb=strlen(b); 10 | int i; 11 | int xa[30],xb[30]; 12 | memset(xa,0,sizeof(xa)); 13 | memset(xb,0,sizeof(xb)); 14 | for(i=0;i='a'&&a[i]<='z')xa[a[i]-'a']++; 15 | for(i=0;i='a'&&b[i]<='z')xb[b[i]-'a']++; 16 | for(i=0;i<26;i++){ 17 | int l=std::min(xa[i],xb[i]); 18 | for(int j=1;j<=l;j++)printf("%c",'a'+i); 19 | } 20 | printf("\n"); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Uva/10260 - Soundex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int f(char a) 4 | { 5 | if(a=='B'||a=='F'||a=='P'||a=='V')return 1; 6 | if(a=='C'||a=='G'||a=='J'||a=='K'||a=='Q'||a=='S'||a=='X'||a=='Z')return 2; 7 | if(a=='D'||a=='T')return 3; 8 | if(a=='L')return 4; 9 | if(a=='M'||a=='N')return 5; 10 | if(a=='R')return 6; 11 | return 0; 12 | } 13 | int main() 14 | { 15 | char a[100]; 16 | while(scanf("%s",a)!=EOF) 17 | { 18 | int i; 19 | int len=strlen(a); 20 | for(i=0;i=1&&f(a[i-1])==f(a[i])) || !f(a[i]) )continue; 23 | printf("%d",f(a[i])); 24 | } 25 | printf("\n"); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Uva/10298 - Power Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char s[1000010]; 4 | int main() 5 | { 6 | while(scanf("%s",s)!=EOF){ 7 | int i,j,res=0; 8 | int len=strlen(s); 9 | if(len==1)break; 10 | for(i=1;i<=len;i++){ 11 | int flag=1; 12 | if(len%i!=0)continue; 13 | for(j=i;j 2 | void op(); 3 | int main() 4 | { 5 | int s; 6 | scanf("%d",&s); 7 | int i; 8 | for(i=1;i<=s;i++)op(); 9 | return 0; 10 | } 11 | void op() 12 | { 13 | int i,n,a,b,c; 14 | long long sum=0; 15 | scanf("%d",&n); 16 | for(i=1;i<=n;i++) 17 | { 18 | scanf("%d%d%d",&a,&b,&c); 19 | sum+=a*c; 20 | } 21 | printf("%lld\n",sum); 22 | } 23 | -------------------------------------------------------------------------------- /Uva/10302 - Summation of Polynomials.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | long long dp[50010]; 3 | int main() 4 | { 5 | long long i;dp[1]=1; 6 | for(i=2;i<=50000;i++)dp[i]=dp[i-1]+i*i*i; 7 | int n; 8 | while(scanf("%d",&n)==1) 9 | { 10 | printf("%lld\n",dp[n]); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Uva/10305 - Ordering Tasks.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/10305 - Ordering Tasks.cpp -------------------------------------------------------------------------------- /Uva/10324 - Zeros and Ones.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char s[1000010]; 4 | int re[1000010]; 5 | int main() 6 | { 7 | int c=1; 8 | while(gets(s)) 9 | { 10 | int n,i,len=strlen(s); 11 | if(len==0)break; 12 | printf("Case %d:\n",c); 13 | scanf("%d",&n); 14 | c++; 15 | for(i=0;ib){t=a;a=b;b=t;} 26 | int flag=1; 27 | for(j=a;j 2 | int main() 3 | { 4 | int n; 5 | while(scanf("%d",&n)!=EOF) 6 | { 7 | int a[1010],i,j,t,res=0; 8 | for(i=1;i<=n;i++)scanf("%d",&a[i]); 9 | for(j=1;j<=n;j++) 10 | { 11 | for(i=1;i<=n-1;i++) 12 | { 13 | if(a[i]>a[i+1]) 14 | { 15 | t=a[i];a[i]=a[i+1];a[i+1]=t;res++; 16 | } 17 | } 18 | } 19 | printf("Minimum exchange operations : %d\n",res); 20 | } 21 | return 0; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Uva/10338 - Mischievous Children.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int cmp(const void *_a,const void *_b) 5 | { 6 | char *a=(char *)_a; 7 | char *b=(char *)_b; 8 | return *a-*b; 9 | } 10 | unsigned long long jc[30]; 11 | int main() 12 | { 13 | int z,k; 14 | int i; 15 | jc[0]=1; 16 | for(i=1;i<=26;i++)jc[i]=jc[i-1]*i; 17 | scanf("%d",&z); 18 | for(k=1;k<=z;k++) 19 | { 20 | char s[100]; 21 | scanf("%s",s); 22 | qsort(s,strlen(s),sizeof(char),cmp); 23 | int len=strlen(s),p=1; 24 | unsigned long long res=jc[len]; 25 | for(i=0;i 2 | #include 3 | int main() 4 | { 5 | // freopen("in.txt","r",stdin); 6 | char a[1000000],b[1000000]; 7 | while(scanf("%s%s",a,b)!=EOF) 8 | { 9 | int la=strlen(a),lb=strlen(b); 10 | int i=0,j; 11 | for(j=0;j 2 | int f(int x,int y) 3 | { 4 | if(x 2 | #include 3 | double max(double a,double b) 4 | { 5 | if(a>b)return a; 6 | return b; 7 | } 8 | double min(double a,double b) 9 | { 10 | return a+b-max(a,b); 11 | } 12 | int main() 13 | { 14 | double r,s,p,q; 15 | while(scanf("%lf%lf%lf%lf",&p,&q,&r,&s)==4) 16 | { 17 | long double res,zi=0; 18 | double i; 19 | s=min(s,r-s); 20 | q=min(q,p-q); 21 | 22 | res=0; 23 | for(i=min(p,r)+1;i<=max(p,r);i++)res+=log(i); 24 | if(p>r)zi+=res;else zi-=res; 25 | 26 | res=0; 27 | for(i=min(r-s,p-q)+1;i<=max(r-s,p-q);i++)res+=log(i); 28 | if(r-s>p-q)zi+=res;else zi-=res; 29 | 30 | res=0; 31 | for(i=min(s,q)+1;i<=max(s,q);i++)res+=log(i); 32 | if(s>q)zi+=res;else zi-=res; 33 | 34 | printf("%.5lf\n",exp(zi)); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Uva/10392 - Factoring Large Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define LL long long 3 | int isp[1000010]; 4 | LL prime[80000],ptp; 5 | int f(LL x,int l){ 6 | // printf("%lld %d\n",x,l); 7 | if(x==1)return 0; 8 | int i; 9 | for(i=l;i<=ptp;i++)if(x%prime[i]==0){ 10 | printf(" %d\n",prime[i]); 11 | return 1+f(x/prime[i],i); 12 | } 13 | printf(" %lld\n",x); 14 | return 1; 15 | } 16 | int main(){ 17 | LL i,j; 18 | for(i=1;i<=1000000;i++)isp[i]=1; 19 | for(i=2;i<=500000;i++){ 20 | for(j=2;i*j<=1000000;j++)isp[i*j]=0; 21 | } 22 | ptp=0; 23 | for(i=2;i<=1000000;i++)if(isp[i])prime[++ptp]=i; 24 | LL n; 25 | // printf("%lld!\n",ptp); 26 | while(scanf("%lld",&n)!=EOF&&n>=0){ 27 | f(n,1); 28 | printf("\n"); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Uva/10405 - Longest Common Subsequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int dp[1010][1010]; 4 | int max(int a,int b) 5 | { 6 | if(a>b)return a; 7 | return b; 8 | } 9 | int main() 10 | { 11 | char a[1010],b[1010]; 12 | while(gets(a)) 13 | { 14 | gets(b); 15 | int m=strlen(a),n=strlen(b); 16 | int i,j; 17 | for(i=0;i<=m;i++)for(j=1;j<=n;j++)dp[i][j]=0; 18 | for(i=1;i<=m;i++) 19 | { 20 | for(j=1;j<=n;j++) 21 | { 22 | int z=i-1,x=j-1; 23 | if(a[z]==b[x]) 24 | { 25 | dp[i][j]=dp[z][x]+1; 26 | } 27 | else dp[i][j]=max(dp[z][j],dp[i][x]); 28 | } 29 | } 30 | printf("%d\n",dp[m][n]); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Uva/10424 - Love Calculator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int g(int a) 6 | { 7 | if(a<10)return a; 8 | else return g(a%10+a/10); 9 | } 10 | int f(char *a) 11 | { 12 | int len=strlen(a); 13 | int i,sum=0; 14 | for(i=0;i='a')a[i]+='A'-'a'; 15 | for(i=0;i='A')sum+=a[i]-'A'+1; 16 | return g(sum); 17 | } 18 | int main() 19 | { 20 | char a[100],b[100]; 21 | while(gets(a)) 22 | { 23 | gets(b); 24 | int la=strlen(a),lb=strlen(b); 25 | int i; 26 | int sua=f(a),sub=f(b); 27 | //printf("%d %d\n",sua,sub); 28 | double pre=(double)sua/sub; 29 | if(pre>1)pre=1/pre; 30 | pre*=100; 31 | printf("%.2lf %%\n",pre); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Uva/10427 - Naughty Sleepy Boys.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int ten(int i) 3 | { 4 | int j;int res=1; 5 | for(j=2;j<=i;j++)res*=10; 6 | return res; 7 | } 8 | int f(int num,int k) 9 | { 10 | int i,temp; 11 | for(i=1;i<=k;i++) 12 | { 13 | temp=num%10; 14 | num/=10; 15 | } 16 | return temp; 17 | } 18 | int main() 19 | { 20 | int n; 21 | while(scanf("%d",&n)==1) 22 | { 23 | int num=0; 24 | int k=1,i; 25 | for(i=1;i<=10;i++) 26 | { 27 | if(n>ten(i)*i*9)n-=ten(i)*i*9; 28 | else break; 29 | } 30 | int ws=i; 31 | n+=ws-1; 32 | num=n/ws+ten(ws)-1; 33 | k+=n%ws;k=ws-k+1; 34 | // printf("%d\t%d\t%d\t%d\n",num,n,ws,k); 35 | printf("%d\n",f(num,k)); 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Uva/10465 - Homer Simpson.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/10465 - Homer Simpson.cpp -------------------------------------------------------------------------------- /Uva/10474 - Where is the Marble.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int k[10010]; 3 | int res[10010]; 4 | int main() 5 | { 6 | int n,q; 7 | int c=1; 8 | while(scanf("%d%d",&n,&q)!=EOF) 9 | { 10 | if(n==0 && q==0)break; 11 | int i,j,t; 12 | for(i=1;i<=10000;i++)k[i]=0; 13 | for(i=1;i<=n;i++) 14 | { 15 | scanf("%d",&t); 16 | k[t]++; 17 | } 18 | res[1]=1; 19 | for(i=2;i<=10001;i++) 20 | { 21 | res[i]=res[i-1]+k[i-1]; 22 | } 23 | printf("CASE# %d:\n",c);c++; 24 | for(i=1;i<=q;i++) 25 | { 26 | scanf("%d",&t); 27 | if(res[t]==res[t+1])printf("%d not found\n",t); 28 | else printf("%d found at %d\n",t,res[t]); 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Uva/10499 - The Land of Justice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | long long n; 6 | while(scanf("%lld",&n)==1) 7 | { 8 | if(n<0)break; 9 | if(n==1){printf("0%%\n");continue;} 10 | printf("%lld%%\n",n*25); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Uva/105 - The Skyline Problem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/105 - The Skyline Problem.cpp -------------------------------------------------------------------------------- /Uva/10509 - R U Kidding Mr. Feynman.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | double n; 5 | while(scanf("%lf",&n)==1) 6 | { 7 | if(n==0)break; 8 | double i; 9 | for(i=0;;i++) 10 | { 11 | if(i*i*i>n)break; 12 | } 13 | i--; 14 | double s=i+(n-i*i*i)/(3*i*i); 15 | printf("%.4lf\n",s); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Uva/10530 - Guessing Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | bool a[11]; 4 | char ro[100]="right on"; 5 | char th[100]="too high"; 6 | char tl[100]="too low"; 7 | void check(char *x,int k) 8 | { 9 | int i; 10 | if(strcmp(tl,x)==0) 11 | { 12 | for(i=1;i<=k;i++)a[i]=0; 13 | } 14 | if(strcmp(th,x)==0) 15 | { 16 | for(i=k;i<=10;i++)a[i]=0; 17 | } 18 | } 19 | int main() 20 | { 21 | char x[100]; 22 | 23 | int k,i; 24 | while(scanf("%d",&k)!=EOF&&k) 25 | { 26 | for(i=1;i<=10;i++)a[i]=1; 27 | getchar(); 28 | gets(x); 29 | while(strcmp(x,ro)!=0) 30 | { 31 | check(x,k); 32 | scanf("%d",&k);getchar(); 33 | gets(x); 34 | check(x,k); 35 | } 36 | if(a[k])printf("Stan may be honest\n");else printf("Stan is dishonest\n"); 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Uva/10533 - Digit Primes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX 1000000 +10 3 | int sum[MAX]; 4 | int isp[100]; 5 | int is_prime(int x){ 6 | int i; 7 | if(x==1)return 0; 8 | for(i=2;i*i<=x;i++)if(x%i==0)return 0; 9 | return 1; 10 | } 11 | int check(int x){ 12 | int a=0; 13 | int y=x; 14 | while(y){ 15 | a+=y%10;y/=10; 16 | } 17 | if(isp[a])return is_prime(x); 18 | return 0; 19 | } 20 | int main(){ 21 | int i; 22 | for(i=1;i<=60;i++)isp[i]=is_prime(i); 23 | sum[0]=0; 24 | for(i=1;i<1000000;i++)sum[i]=sum[i-1]+check(i); 25 | int t,n,m; 26 | scanf("%d",&t); 27 | while(t--){ 28 | scanf("%d%d",&n,&m); 29 | printf("%d\n",sum[m]-sum[n-1]); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Uva/10534 - Wavio Sequence.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/10534 - Wavio Sequence.cpp -------------------------------------------------------------------------------- /Uva/10550 - Combination Lock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int f(int a,int b) 3 | { 4 | int s=b-a; 5 | if(a>b)s=40-a+b; 6 | return s*9; 7 | } 8 | int g(int a,int b) 9 | { 10 | int s=a-b; 11 | if(a 2 | int h(int x) 3 | { 4 | int i,a[20],sum=0; 5 | for(i=1;i<=10;i++) 6 | { 7 | a[i]=x%10; 8 | sum+=a[i]*a[i]; 9 | x/=10; 10 | } 11 | return sum; 12 | } 13 | int main() 14 | { 15 | int dp[800]; 16 | bool dd[800]; 17 | int i; 18 | for(i=1;i<=730;i++){dd[i]=0;} 19 | for(i=1;i<=730;i++) 20 | { 21 | int q=i; 22 | if(h(i) 2 | int a[100010]; 3 | int f(int x,int y) 4 | { 5 | return a[x+y]+x; 6 | } 7 | int main() 8 | { 9 | a[0]=0;int i; 10 | for(i=1;i<=100000;i++)a[i]=a[i-1]+i; 11 | int x1,x2,y1,y2;int z,x; 12 | scanf("%d",&z); 13 | for(x=1;x<=z;x++) 14 | { 15 | scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 16 | printf("Case %d: %d\n",x,f(x2,y2)-f(x1,y1)); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Uva/10656 - Maximum Sum (II).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | while(scanf("%d",&n)!=EOF && n) 6 | { 7 | int a[1010],j=1,b[1010],i; 8 | for(i=1;i<=1000;i++)b[i]=0; 9 | for(i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]!=0)b[j++]=a[i];} 10 | printf("%d",b[1]); 11 | for(i=2;i<=j-1;i++) 12 | { 13 | printf(" %d",b[i]); 14 | } 15 | printf("\n"); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Uva/10666 - The Eurocup is Here!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | long long pow(long long k) 3 | { 4 | long long res=1; 5 | for(int i=1;i<=k;i++)res*=2; 6 | return res; 7 | } 8 | int main() 9 | { 10 | int z,x; 11 | scanf("%d",&z); 12 | for(x=1;x<=z;x++) 13 | { 14 | long long n,s; 15 | scanf("%lld%lld",&n,&s); 16 | long long k=0,r=s,count=0; 17 | while(s%2==0 && ++count<=n) 18 | { 19 | s/=2;k++; 20 | } 21 | long long max=1+pow(n)-pow(k); 22 | long long min=1;s=r; 23 | while(1) 24 | { 25 | if(n==0)break; 26 | --n; 27 | if(s>=pow(n)){min++;s-=pow(n);} 28 | } 29 | printf("%lld %lld\n",min,max); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Uva/10696 - f91.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[110]; 3 | int f(int n) 4 | { 5 | if(n<=100)return f(f(n+11)); 6 | return n-10; 7 | } 8 | int main() 9 | { 10 | int n; 11 | int i; 12 | for(i=1;i<=100;i++)dp[i]=f(i); 13 | while(scanf("%d",&n)==1) 14 | { 15 | if(n==0)break; 16 | int out; 17 | if(n>=101)out=n-10; 18 | else out=dp[n]; 19 | printf("f91(%d) = %d\n",n,out); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Uva/10714 - Ants.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int a[100010]; 4 | int max(int a,int b){ 5 | if(a>b)return a; 6 | return b; 7 | } 8 | int min(int a,int b){ 9 | if(a>b)return b; 10 | return a; 11 | } 12 | int main(){ 13 | int k,z; 14 | scanf("%d",&z); 15 | for(k=1;k<=z;k++){ 16 | int i,n,L; 17 | scanf("%d%d",&L,&n); 18 | int resa=0,resb=0; 19 | for(i=1;i<=n;i++){ 20 | scanf("%d",&a[i]); 21 | resa=max( resa,max(a[i],L-a[i]) ); 22 | resb=max( resb,min(a[i],L-a[i]) ); 23 | } 24 | printf("%d %d\n",resb,resa); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Uva/10719 - Quotient Polynomial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int t[10010]; 3 | int a[10010]; 4 | int q[10010]; 5 | int main(){ 6 | int k; 7 | int g=0; 8 | while(scanf("%d%*c",&k)!=EOF){ 9 | if(g)printf("\n"); 10 | int i; 11 | char c; 12 | for(i=0;;i++){ 13 | scanf("%d%c",&t[i],&c); 14 | if(c=='\n')break; 15 | } 16 | int n=i; 17 | for(i=0;i<=n;i++)a[i]=t[n-i]; 18 | for(i=n;i>=0;i--){ 19 | q[i]=a[i]; 20 | if(i)a[i-1]+=k*q[i]; 21 | } 22 | printf("q(x):"); 23 | for(i=n;i>0;i--)printf(" %d",q[i]); 24 | printf("\n"); 25 | printf("r = %d\n",q[0]); 26 | printf("\n"); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Uva/10763 - Foreign Exchange.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/10763 - Foreign Exchange.cpp -------------------------------------------------------------------------------- /Uva/10773 - Back to Intermediate Math.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int x,z; 6 | scanf("%d",&z); 7 | for(x=1;x<=z;x++) 8 | { 9 | double d,v,u; 10 | scanf("%lf%lf%lf",&d,&v,&u); 11 | printf("Case %d: ",x); 12 | double tax,tin; 13 | tin=d/u; 14 | if(u>v) 15 | { 16 | double vv=sqrt(u*u-v*v); 17 | tax=d/vv; 18 | if(tax>tin)printf("%.3lf\n",tax-tin); 19 | else printf("can't determine\n"); 20 | } 21 | else printf("can't determine\n"); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Uva/10783 - Odd Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int z,x; 5 | scanf("%d",&z); 6 | for(x=1;x<=z;x++) 7 | { 8 | int i,a,b,temp; 9 | scanf("%d%d",&a,&b); 10 | if(a>b){temp=a;a=b;b=temp;} 11 | printf("Case %d: ",x); 12 | int sum=0; 13 | for(i=a;i<=b;i++) 14 | { 15 | if(i%2==1)sum+=i; 16 | } 17 | printf("%d\n",sum); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Uva/10784 - Diagonal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define LL long long 4 | int main(){ 5 | LL n; 6 | int z=0; 7 | while(scanf("%lld",&n)!=EOF&&n){ 8 | LL res=(3+sqrt(8*n+9))/2; 9 | while(res*(res-1)/2-res 2 | #define LL long long 3 | LL C2(LL x){ 4 | return x*(x-1)/2; 5 | } 6 | int main(){ 7 | LL a,b; 8 | int t=0; 9 | while(scanf("%lld%lld",&a,&b)!=EOF){ 10 | if(a==0&&b==0)break; 11 | printf("Case %d: ",++t); 12 | printf("%I64d\n",C2(a)*C2(b)); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Uva/10812 - Beat the Spread!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int k,z; 5 | scanf("%d",&z); 6 | for(k=1;k<=z;k++) 7 | { 8 | long long a,b; 9 | scanf("%lld%lld",&a,&b); 10 | if(a 2 | int main(){ 3 | char s[110]; 4 | int p[8]={6,5,4,3,0,2,1,0},i; 5 | while(gets(s)!=NULL){ 6 | if(s[0]=='|'){ 7 | int b=0; 8 | for(i=0;i<8;i++)b|=(s[2+i]=='o')<<(p[i]); 9 | printf("%c",b); 10 | } 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Uva/10879 - Code Refactoring.cpp: -------------------------------------------------------------------------------- 1 | #include //Case #1: 120 = 12 * 10 = 6 * 20 2 | void op(); 3 | int main() 4 | { 5 | int x,i; 6 | scanf("%d",&x); 7 | for(i=1;i<=x;i++){printf("Case #%d: ",i);op();} 8 | return 0;} 9 | void op() 10 | { 11 | int x; 12 | scanf("%d",&x); 13 | int q,w,e,r; 14 | int i,m=0,flag=0; 15 | for(i=2;2*i<=x;i++) 16 | { 17 | if(flag&&x%i==0){e=i;r=x/i;break;} 18 | else if(x%i==0){q=i;w=x/i;flag=1;} 19 | } 20 | printf("%d = %d * %d = %d * %d\n",x,q,w,e,r); 21 | } 22 | -------------------------------------------------------------------------------- /Uva/10895 - Matrix Transpose.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/10895 - Matrix Transpose.cpp -------------------------------------------------------------------------------- /Uva/10916 - Factstone Benchmark.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int dp[2200]; 4 | int f[2200]; 5 | int main(){ 6 | int i,j; 7 | f[1959]=2; 8 | for(i=1960;i<=2160;i++){ 9 | if(i%10!=0)f[i]=f[i-1],dp[i]=dp[i-1]; 10 | else { 11 | f[i]=2*f[i-1]; 12 | double res=0; 13 | double max=f[i]*log(2); 14 | for(j=1;res<=max;j++)res+=log(j); 15 | j--;j--; 16 | dp[i]=j; 17 | } 18 | } 19 | int n; 20 | while(scanf("%d",&n)!=EOF&&n)printf("%d\n",dp[n]); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Uva/10921 - Find the Telephone.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char map[30]="22233344455566677778889999"; 4 | int main() 5 | { 6 | char a[50]; 7 | while(gets(a)) 8 | { 9 | int i; 10 | int len=strlen(a); 11 | for(i=0;i='A' && a[i]<='Z')a[i]=map[a[i]-'A']; 14 | } 15 | puts(a); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Uva/10922 - 2 the 9s.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int sum(char *s) 4 | { 5 | int res=0; 6 | int len=strlen(s); 7 | int i; 8 | for(i=0;i 2 | #include 3 | int f(char x){ 4 | if(x>='a'&&x<='z')return x-'a'+1; 5 | if(x>='A'&&x<='Z') return x-'A'+27; 6 | return 0; 7 | } 8 | int is_prime(int x){ 9 | int i; 10 | for(i=2;i*i<=x;i++)if(x%i==0)return 0; 11 | return 1; 12 | } 13 | int main(){ 14 | char s[1010]; 15 | while(gets(s)!=NULL){ 16 | int sum=0; 17 | for(int i=0;i 2 | #include 3 | bool is_11(char *s) 4 | { 5 | int sum=0,len=strlen(s); 6 | int i; 7 | int k[2]={1,-1}; 8 | for(i=len-1;i>=0;i--) 9 | { 10 | sum+=k[(len-i)%2]*(s[i]-'0'); 11 | } 12 | if(sum%11==0)return 1; 13 | return 0; 14 | } 15 | int main() 16 | { 17 | char s[1010]; 18 | while(scanf("%s",s)!=EOF) 19 | { 20 | int len=strlen(s); 21 | if(len==1 && s[0]=='0')break; 22 | if(is_11(s))printf("%s is a multiple of 11.\n",s); 23 | else printf("%s is not a multiple of 11.\n",s); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Uva/10931 - Parity.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | while(scanf("%d",&n)==1 && n!=0) 6 | { 7 | int m=n; 8 | int a[40]; 9 | int i,weizhi=1; 10 | for(i=1;i<40;i++)a[i]=0; 11 | int sum=0; 12 | while(1) 13 | { 14 | if(m==0)break; 15 | if(m%2==0)a[weizhi++]=0; 16 | else {a[weizhi++]=1;m-=1;sum++;} 17 | m/=2; 18 | } 19 | weizhi--; 20 | printf("The parity of "); 21 | for(i=weizhi;i>=1;i--)printf("%d",a[i]); 22 | printf(" is %d (mod 2).\n",sum); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Uva/10935 - Throwing cards away I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int len; 3 | int main() 4 | { 5 | int n; 6 | while(scanf("%d",&n)==1&&n) 7 | { 8 | int a[200],i,top=1,down=n,fi=1; 9 | for(i=1;i<=n;i++)a[i]=i; 10 | printf("Discarded cards:"); 11 | for(i=1;;i++) 12 | { 13 | if(down==top)break; 14 | if(fi)fi=0;else printf(","); 15 | printf(" %d",a[top]); 16 | top++; 17 | a[down+1]=a[top]; 18 | top++; 19 | down++; 20 | } 21 | printf("\nRemaining card: %d\n",a[top]); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Uva/10940 - Throwing cards away II.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int b[500001]; 3 | int f(int bi,int i) 4 | { 5 | if(bi<=i-2)return bi+2; 6 | else if(bi==i-1)return 2; 7 | } 8 | int main() 9 | { 10 | int i,j,n; 11 | b[1]=1;b[2]=2; 12 | for(i=3;i<=500000;i++) 13 | { 14 | b[i]=f(b[i-1],i); 15 | //printf("b[%d]=%d\n",i,b[i]); 16 | } 17 | while(scanf("%d",&n)==1 && n!=0) 18 | { 19 | printf("%d\n",b[n]); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Uva/10943 - How do you add.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/10943 - How do you add.cpp -------------------------------------------------------------------------------- /Uva/10945 - Mother bear.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char done[]="DONE"; 4 | int can(char x){ 5 | if(x>='A'&&x<='Z')return 1; 6 | if(x>='a'&&x<='z')return 1; 7 | if(x=='\0')return 1; 8 | return 0; 9 | } 10 | char f(char x){ 11 | if(x>='a'&&x<='z')return x-'a'+'A'; 12 | return x; 13 | } 14 | int main(){ 15 | char s[1010]; 16 | while(gets(s)!=NULL){ 17 | if(strcmp(s,done)==0)break; 18 | int i=0,j=strlen(s)-1,len=strlen(s),flag=1; 19 | while(!can(s[i]))i++; 20 | while(!can(s[j]))j--; 21 | while(i 2 | int min(int a,int b) 3 | {if(a>b)return b;return a;} 4 | int main() 5 | { 6 | int dp[310][310]; 7 | int i; 8 | for(i=1;i<=300;i++){dp[i][1]=i-1;dp[1][i]=i-1;} 9 | int j,s; 10 | for(i=2;i<=300;i++) 11 | { 12 | for(j=2;j<=300;j++) 13 | { 14 | dp[i][j]=dp[i-1][j]+dp[1][j]+1; 15 | for(s=1;s 2 | #include 3 | struct num{int a,b;}a[500010]; 4 | int cmp(const void *aa,const void *bb) 5 | { 6 | num *a=(num *)aa; 7 | num *b=(num *)bb; 8 | num x=*a,y=*b; 9 | return x.a-y.a; 10 | } 11 | int main(){ 12 | int t; 13 | scanf("%d",&t); 14 | while(t--){ 15 | int n; 16 | scanf("%d",&n); 17 | int i; 18 | for(i=1;i<=n;i++){ 19 | int x; 20 | scanf("%d",&x); 21 | if(x>0){ 22 | a[i].a=x;a[i].b=1; 23 | } 24 | else { 25 | a[i].a=-x;a[i].b=-1; 26 | } 27 | } 28 | qsort(&a[1],n,sizeof(num),cmp); 29 | int flag=a[1].b,res=1; 30 | for(i=2;i<=n;i++){ 31 | if(a[i].b!=flag){ 32 | flag=-flag; 33 | res++; 34 | } 35 | } 36 | printf("%d\n",res); 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Uva/11042 - Complex, difficult and complicated.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int k,z; 5 | scanf("%d",&z); 6 | for(k=1;k<=z;k++) 7 | { 8 | int a,b; 9 | int out; 10 | scanf("%d%d",&a,&b); 11 | if(b==0)out=1; 12 | else if(a==0)out=2; 13 | else if(a==b || a==-b)out=4; 14 | else out=0; 15 | if(out)printf("%d\n",out); 16 | else printf("TOO COMPLICATED\n"); 17 | } 18 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Uva/11044 - Searching for Nessy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int z,x; 5 | scanf("%d",&z); 6 | for(x=1;x<=z;x++) 7 | { 8 | int p,q; 9 | scanf("%d%d",&p,&q); 10 | printf("%d\n",(p/3)*(q/3)); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Uva/11059 - Maximum Product.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define max(a,b) a>b?a:b 3 | long long dp[30][30]; 4 | int main() 5 | { 6 | int n; 7 | int k=1; 8 | while(scanf("%d",&n)!=EOF) 9 | { 10 | int i,j; 11 | int a[30]; 12 | for(i=1;i<=n;i++)scanf("%d",&a[i]); 13 | for(i=1;i<=n;i++)for(j=i-1;j<=n;j++)dp[i][j]=1; 14 | for(i=1;i<=n;i++) 15 | { 16 | for(j=i;j<=n;j++) 17 | { 18 | dp[i][j]=dp[i][j-1]*a[j]; 19 | } 20 | } 21 | long long res=0; 22 | for(i=1;i<=n;i++) 23 | { 24 | for(j=i;j<=n;j++)res=max(res,dp[i][j]); 25 | } 26 | printf("Case #%d: The maximum product is %lld.\n\n",k,res); 27 | k++; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Uva/111 - History Grading.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int max(int a,int b) 3 | { 4 | if(a>b)return a;return b; 5 | } 6 | int main() 7 | { 8 | int n; 9 | scanf("%d",&n); 10 | int i; 11 | int s[30]; 12 | for(i=1;i<=n;i++)scanf("%d",&s[i]); 13 | int std[30]; 14 | for(i=1;i<=n;i++) 15 | { 16 | std[s[i]]=i; 17 | } 18 | int c[30],ck[30]; 19 | while(scanf("%d",&c[1])!=EOF) 20 | { 21 | for(i=2;i<=n;i++)scanf("%d",&c[i]); 22 | for(i=1;i<=n;i++)ck[c[i]]=i; 23 | int dp[30][30]; 24 | int j; 25 | for(i=0;i<=n;i++)for(j=0;j<=n;j++)dp[i][j]=0; 26 | for(i=1;i<=n;i++) 27 | { 28 | for(j=1;j<=n;j++) 29 | { 30 | if(std[i]==ck[j])dp[i][j]=dp[i-1][j-1]+1; 31 | else dp[i][j]=max(dp[i-1][j],dp[i][j-1]); 32 | } 33 | } 34 | printf("%d\n",dp[n][n]); 35 | } 36 | return 0;} 37 | -------------------------------------------------------------------------------- /Uva/11130 - Billiard bounces.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI 3.1415926 4 | double min(double a,double b) 5 | { 6 | if(a>b)return b; 7 | else return a; 8 | } 9 | int f(int x) 10 | { 11 | if(x%2==0)return x/2; 12 | } 13 | int main() 14 | { 15 | double a,b,v,p,s; 16 | while(scanf("%lf%lf%lf%lf%lf",&a,&b,&v,&p,&s)!=EOF) 17 | { 18 | if(a==0 && b==0 && v==0 & p==0 & s==0)break; 19 | int cy=0,cx=0;double t=0,x=a/2,y=b/2; 20 | v/=2; 21 | while(v>=min(a/2,b/2)){v/=2;s*=2;} 22 | for(t=1;t<=s;t++) 23 | { 24 | x+=v*cos(p/180*PI); 25 | y+=v*sin(p/180*PI); 26 | if(x>=a){cy++;p=180-p;x=2*a-x;} 27 | if(x<=0){cy++;p=180-p;x=-x;} 28 | if(y>=b){cx++;p=-p;y=2*b-y;} 29 | if(y<=0){cx++;p=-p;y=-y;} 30 | } 31 | printf("%d %d\n",cy,cx); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Uva/11137 - Ingenuous Cubrency.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | long long dp[22][10010]; 5 | long long money[22]; 6 | int i; 7 | for(i=1;i<=21;i++) 8 | { 9 | money[i]=i*i*i; 10 | dp[i][0]=1; 11 | dp[i][1]=1; 12 | } 13 | int k; 14 | for(i=1;i<=10000;i++)dp[1][i]=dp[1][i-1]; 15 | for(k=2;k<=21;k++) 16 | { 17 | for(i=1;i<=10000;i++) 18 | { 19 | dp[k][i]=dp[k-1][i]; 20 | if(i>=money[k])dp[k][i]+=dp[k][i-money[k]]; 21 | } 22 | } 23 | int n; 24 | while(scanf("%d",&n)==1) 25 | { 26 | printf("%lld\n",dp[21][n]); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Uva/11151 - Longest Palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char a[1010],b[1010]; 4 | int dp[1010][1010]; 5 | int max(int a,int b){ 6 | if(a>b)return a;return b; 7 | } 8 | int main(){ 9 | int t; 10 | scanf("%d%*c",&t);//gets(b); 11 | while(t--){ 12 | int i,j=0; 13 | gets(a); 14 | int len=strlen(a); 15 | for(i=len-1;i>=0;i--)b[j++]=a[i]; 16 | for(i=0;i 2 | int main() 3 | { 4 | int z,x; 5 | scanf("%d",&z); 6 | for(x=1;x<=z;x++) 7 | { 8 | int p,q; 9 | scanf("%d%d",&p,&q); 10 | if(p>q)printf(">\n"); 11 | if(p==q)printf("=\n"); 12 | if(p 2 | int main(){ 3 | int n; 4 | while(scanf("%d",&n)!=EOF){ 5 | if(n<0)break; 6 | int a[1000],pa=0; 7 | int y=n,i; 8 | while(y){ 9 | a[++pa]=y%3; 10 | y/=3; 11 | } 12 | for(i=pa;i>=1;i--)printf("%d",a[i]); 13 | if(n==0)printf("0"); 14 | printf("\n"); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Uva/11192 - Group Reverse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | int n; 5 | while(scanf("%d",&n)!=EOF&&n){ 6 | char s[110]; 7 | scanf("%s",s); 8 | int len=strlen(s); 9 | int k=len/n; 10 | int i,j; 11 | for(i=0;i 2 | int f(int x) 3 | { 4 | if(x%2==1)x+=1; 5 | return x/2; 6 | } 7 | int u(int x) 8 | { 9 | int i; 10 | int res=0; 11 | for(i=1;i<=x;i++)res+=i; 12 | return res; 13 | } 14 | int g(int x) 15 | { 16 | if(x%2==1)x+=1; 17 | return u(x/2); 18 | } 19 | int main() 20 | { 21 | int m,n; 22 | int z,x; 23 | scanf("%d",&z); 24 | for(x=1;x<=z;x++) 25 | { 26 | scanf("%d%d",&m,&n);if(m!=n)printf("%d\n",f(m)*f(n)); 27 | else printf("%d\n",g(m)); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Uva/11231 - Black and white painting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | bool ban[40001][40001]; 3 | int main() 4 | { 5 | int n,m,c; 6 | while(scanf("%d%d%d",&n,&m,&c)==3 && !(n==0 && m==0 && c==0)) 7 | { 8 | n=n-7; 9 | m=m-7; 10 | int i,j,out=0; 11 | int s=m*n; 12 | if(s%2==0)out=s/2; 13 | else 14 | { 15 | if(c==1) out=(s+1)/2; 16 | else out=(s-1)/2; 17 | } 18 | if(s<0)s=0; 19 | printf("%d\n",out); 20 | } 21 | return 0;} 22 | -------------------------------------------------------------------------------- /Uva/11247 - Income Tax.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | long long m,x; 6 | while(scanf("%lld%lld",&m,&x)==2) 7 | { 8 | if(m==0 && x==0)break; 9 | if(x==100){printf("Not found\n");continue;} 10 | long long ans=(long long)(100.0*(m-1.0)/(100.0-x)); 11 | if( (100*(m-1)) % (100-x) ==0)ans--; 12 | if(ans 2 | #include 3 | long long dp[1000010]; 4 | int main() 5 | { 6 | int x,y,z; 7 | int i,j; 8 | int p[4];p[1]=1;p[2]=2;p[3]=2; 9 | for(i=0;i<=1000000;i++)dp[i]=0; 10 | dp[0]=1;dp[1]=1; 11 | for(j=1;j<=3;j++) 12 | { 13 | for(i=2;i<=1000000;i++)dp[i]+=dp[i-p[j]]; 14 | } 15 | //printf("%.2lf",(double)clock()/CLOCKS_PER_SEC); 16 | int n; 17 | while(scanf("%d",&n)==1) 18 | { 19 | printf("%lld\n",dp[n]); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Uva/113 - Power of Cryptography.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | int n; 7 | while(scanf("%d",&n)==1) 8 | { 9 | double p; 10 | scanf("%lf",&p); 11 | double a,b; 12 | b=log(p); 13 | double out=floor(exp(b/n)+0.5); 14 | printf("%.0f\n",out); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Uva/11300 - Spreading the Wealth.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define LL long long 4 | LL a[1000011]; 5 | LL c[1000011]; 6 | LL abs(LL a){ 7 | if(a>0)return a; 8 | return -a; 9 | } 10 | int main(){ 11 | LL n; 12 | while(scanf("%lld",&n)!=EOF&&n){ 13 | int i; 14 | for(i=1;i<=n;i++)scanf("%lld",&a[i]); 15 | LL ev=0; 16 | for(i=1;i<=n;i++)ev+=a[i]; 17 | ev/=n; 18 | c[1]=0; 19 | for(i=2;i<=n;i++)c[i]=c[i-1]+a[i-1]-ev; 20 | std::sort(c+1,c+n+1); 21 | LL x=c[n/2+1]; 22 | LL res=0; 23 | for(i=1;i<=n;i++)res+=abs(x-c[i]); 24 | printf("%lld\n",res); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Uva/11313 - Gourmet Games.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/11313 - Gourmet Games.cpp -------------------------------------------------------------------------------- /Uva/11332 - Summing Digits.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int f(int x) 3 | { 4 | if(x<10)return x; 5 | int sum=0,t=x,i; 6 | for(i=1;i<=10;i++) 7 | { 8 | sum+=t%10; 9 | t/=10; 10 | } 11 | return f(sum); 12 | } 13 | int main() 14 | { 15 | int n; 16 | while(scanf("%d",&n)==1 && n!=0) 17 | { 18 | printf("%d\n",f(n)); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Uva/11340 - Newspaper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | long long va[900]; 4 | int main(){ 5 | int t; 6 | scanf("%d%*c",&t); 7 | while(t--){ 8 | int m,n,i; 9 | scanf("%d%*c",&m); 10 | char s[20010]; 11 | for(i=0;i<=800;i++)va[i]=0; 12 | for(i=1;i<=m;i++){ 13 | gets(s); 14 | char p; 15 | long long q; 16 | sscanf(s,"%c %lld",&p,&q); 17 | va[(int)p+200]=q; 18 | } 19 | scanf("%d%*c",&n); 20 | long long res=0; 21 | for(i=1;i<=n;i++){ 22 | gets(s); 23 | int j; 24 | int len=strlen(s); 25 | for(j=0;j 2 | #include 3 | int cmp(const void *aa,const void *bb) 4 | { 5 | int *a=(int *)aa; 6 | int *b=(int *)bb; 7 | return *a-*b; 8 | } 9 | int main() 10 | { 11 | int k,z; 12 | scanf("%d",&z); 13 | for(k=1;k<=z;k++) 14 | { 15 | int n; 16 | scanf("%d",&n); 17 | int a[130],i; 18 | for(i=1;i<=n;i++)scanf("%d",&a[i]); 19 | qsort(&a[1],n,sizeof(int),cmp); 20 | //for(i=1;i<=n;i++)printf("%d ",a[i]); 21 | printf("%d\n",(a[n]-a[1])*2); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Uva/11371 - Number Theory for Newbies.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/11371 - Number Theory for Newbies.cpp -------------------------------------------------------------------------------- /Uva/11384 - Help is needed for Dexter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int a[50000010]; 4 | int main() 5 | { 6 | int n; 7 | double ln2=log(2); 8 | while(scanf("%d",&n)!=EOF) 9 | { 10 | double nn=log(n); 11 | nn/=ln2; 12 | nn=floor(nn+1); 13 | printf("%.0lf\n",round(nn)); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Uva/11388 - GCD LCM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int z,x; 5 | int l,g; 6 | scanf("%d",&z); 7 | for(x=1;x<=z;x++) 8 | { 9 | int flag=1; 10 | scanf("%d%d",&g,&l); 11 | if(l%g!=0){flag=0;printf("-1\n");} 12 | else 13 | { 14 | int s=l/g; 15 | printf("%d %d\n",g,l); 16 | } 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Uva/11389 - The Bus Driver Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int a[110],b[110]; 4 | int cmp(const void *aa,const void *bb) 5 | { 6 | int *a=(int *)aa; 7 | int *b=(int *)bb; 8 | return *a-*b; 9 | } 10 | int main(){ 11 | int n,d,r; 12 | while(scanf("%d%d%d",&n,&d,&r)!=EOF){ 13 | if(n==0&&d==0&&r==0)break; 14 | int i; 15 | for(i=1;i<=n;i++)scanf("%d",&a[i]); 16 | for(i=1;i<=n;i++)scanf("%d",&b[i]); 17 | qsort(&a[1],n,sizeof(int),cmp); 18 | qsort(&b[1],n,sizeof(int),cmp); 19 | int p; 20 | int res=0; 21 | for(p=0;pd)res+=a[1+p]+b[n-p]-d; 23 | } 24 | res*=r; 25 | printf("%d\n",res); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Uva/11428 - Cubes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int s[62]; 5 | int i; 6 | for(i=0;i<=59;i++)s[i]=i*i*i; 7 | int z,j; 8 | bool flag[10010];int big[10010],small[10010]; 9 | for(i=1;i<=10009;i++){flag[i]=0,big[i]=0,small[i]=0;} 10 | for(i=59;i>=1;i--) 11 | { 12 | for(j=1;j<=i;j++) 13 | { 14 | int p=s[i]-s[j]; 15 | if(p>0 && p<=10001){flag[p]=1;big[p]=i;small[p]=j;} 16 | } 17 | } 18 | while(scanf("%d",&z)==1 && z!=0) 19 | { 20 | if(flag[z])printf("%d %d\n",big[z],small[z]); 21 | else printf("No solution\n"); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Uva/11461 - Square Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int k[320];int i; 6 | for(i=0;i<=317;i++)k[i]=i*i; 7 | int a,b; 8 | while(scanf("%d%d",&a,&b)==2) 9 | { 10 | if(a==0 && b==0)break; 11 | int count=0; 12 | for(i=sqrt(a)-1;i<=sqrt(b)+1;i++) 13 | { 14 | if(k[i]>=a && k[i]<=b)count++; 15 | } 16 | printf("%d\n",count); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Uva/11462 - Age Sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | int a[110]; 6 | int i,t; 7 | 8 | while(scanf("%d",&n)==1 && n) 9 | { 10 | for(i=1;i<=100;i++)a[i]=0; 11 | for(i=1;i<=n;i++){scanf("%d",&t);a[t]++;} 12 | int j,fr=1; 13 | for(i=1;i<=100;i++) 14 | { 15 | for(j=0;j 2 | int main() 3 | { 4 | int n; 5 | while(scanf("%d",&n)!=EOF&&n) 6 | { 7 | int a,b; 8 | scanf("%d%d",&a,&b); 9 | int k; 10 | int x,y; 11 | for(k=1;k<=n;k++) 12 | { 13 | scanf("%d%d",&x,&y); 14 | x-=a;y-=b; 15 | if(x==0 || y==0)printf("divisa\n"); 16 | else if(x>0 && y>0)printf("NE\n"); 17 | else if(x>0 && y<0)printf("SE\n"); 18 | else if(x<0 && y>0)printf("NO\n"); 19 | else if(x<0 && y<0)printf("SO\n"); 20 | } 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Uva/11530 - SMS Typing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int dic[30]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4,1}; 4 | int main() 5 | { 6 | int z,k; 7 | scanf("%d",&z); 8 | for(k=1;k<=z;k++) 9 | { 10 | char a; int res=0;int flag=1; 11 | while(a=getchar()) 12 | { 13 | if(flag!=1&&a=='\n')break; 14 | if(a==' ')a='a'+26; 15 | res+=dic[ a-'a' ]; 16 | flag++; 17 | } 18 | printf("Case #%d: %d\n",k,res); 19 | } 20 | return 0;} 21 | -------------------------------------------------------------------------------- /Uva/11538 - Chess Queen.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | unsigned long long d[1000010]; 3 | int main() 4 | { 5 | unsigned long long i; 6 | d[0]=0; 7 | for(i=1;i<=1000010;i++)d[i]=i*(i-1); 8 | unsigned long long m,n; 9 | while(scanf("%llu%llu",&m,&n)==2) 10 | { 11 | if(m==0 && n==0)break; 12 | unsigned long long res=0; 13 | res+=n*d[m]; 14 | res+=m*d[n]; 15 | unsigned long long min=m>n?n:m; 16 | unsigned long long max=m+n-min; 17 | for(i=1;i 2 | #include 3 | int main(){ 4 | char c; 5 | int k,z; 6 | scanf("%d",&z);getchar(); 7 | for(k=1;k<=z;k++){ 8 | printf("Case %d: ",k); 9 | while(c=getchar()){ 10 | int s,i; 11 | if(c=='\n')break; 12 | // while(c==' ')c=getchar(); 13 | scanf("%d",&s); 14 | for(i=1;i<=s;i++)printf("%c",c); 15 | } 16 | printf("\n"); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Uva/11547 - Automatic Answer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int z,x; 5 | scanf("%d",&z); 6 | for(x=1;x<=z;x++) 7 | { 8 | int s; 9 | scanf("%d",&s); 10 | s*=63;s+=7492;s*=5;s-=498; 11 | if(s<0)s=-s; 12 | s=s%100; 13 | s-=s%10; 14 | s/=10; 15 | printf("%d\n",s); 16 | } 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Uva/116 - Unidirectional TSP.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/116 - Unidirectional TSP.cpp -------------------------------------------------------------------------------- /Uva/1160 - X-Plosives.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int ft[100010]; 3 | void in_ft(){ 4 | int i; 5 | for(i=1;i<=100000;i++)ft[i]=i; 6 | } 7 | int find(int x){ 8 | int t=x,temp; 9 | while(x!=ft[x])x=ft[x]; 10 | while(t!=x){ 11 | temp=ft[t]; 12 | ft[t]=x; 13 | t=temp; 14 | } 15 | return x; 16 | } 17 | void merge(int a,int b){ 18 | int fa=find(a); 19 | int fb=find(b); 20 | ft[fb]=fa; 21 | } 22 | int main(){ 23 | int x,y; 24 | int sum=0; 25 | in_ft(); 26 | while(scanf("%d",&x)!=EOF){ 27 | if(x==-1){ 28 | printf("%d\n",sum); 29 | in_ft(); 30 | sum=0; 31 | continue; 32 | } 33 | scanf("%d",&y); 34 | if(find(x)!=find(y))merge(x,y); 35 | else sum++; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Uva/11614 - Etruscan Warriors Never Play Chess.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int i; 6 | int n; 7 | scanf("%d",&n); 8 | for(i=1;i<=n;i++) 9 | { 10 | unsigned long long s; 11 | scanf("%llu",&s); 12 | printf("%llu\n",(unsigned long long)((-1+sqrt(1+8*s))/2.0)); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Uva/11636 - Hello World!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n;int count=0; 5 | while(scanf("%d",&n)==1) 6 | { 7 | printf("Case %d: ",++count); 8 | if(n<0)break; 9 | if(n==1){printf("0\n");continue;} 10 | int i,k=1; 11 | int res=1; 12 | while(!(res<= n && 2*res>=n)) 13 | { 14 | res*=2;k++; 15 | } 16 | printf("%d\n",k); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Uva/11689 - Soda Surpler.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int t(int x,int y) 3 | { 4 | if(x 2 | #include 3 | int dp[1000010]; 4 | int main() 5 | { 6 | int i; 7 | dp[0]=1; 8 | for(i=1;i<=1000000;i++) 9 | { 10 | dp[i]=0; 11 | dp[i]+=dp[(int)floor(i-sqrt(i)+0.00000001)]; 12 | dp[i]+=dp[(int)floor( log(i)+0.00000001 )]; 13 | dp[i]+=dp[(int)floor(i*sin(i)*sin(i)+0.00000001)]; 14 | dp[i]=dp[i]%1000000; 15 | } 16 | int n; 17 | while(scanf("%d",&n)!=EOF) 18 | { 19 | if(n<0)break; 20 | printf("%d\n",dp[n]); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Uva/11713 - Abstract Names.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void f(char *a) 4 | { 5 | int len=strlen(a); 6 | int i; 7 | for(i=0;i 2 | int main() 3 | { 4 | int a,b,k=0; 5 | while(scanf("%d%d",&a,&b)==2) 6 | { 7 | if(a==0 && b==0)break; 8 | printf("Case %d: ",++k); 9 | if(a<=b)printf("0\n"); 10 | else if(a<=27*b)printf("%d\n",(a-1)/b); 11 | else printf("impossible\n"); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Uva/11727 - Cost Cutting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int x,y,z,k; 5 | scanf("%d",&k); 6 | int max,min,i; 7 | for(i=1;i<=k;i++) 8 | { 9 | scanf("%d%d%d",&x,&y,&z); 10 | max=x>y?x:y; 11 | min=x+y-max; 12 | max=z>max?z:max; 13 | min=z>min?min:z; 14 | printf("Case %d: %d\n",i,x+y+z-max-min); 15 | 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Uva/11729 - Commando War.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct ml{int b,j;}m[1100]; 4 | int cmp(const void *a,const void *b){ 5 | ml *x=(ml *)a; 6 | ml *y=(ml *)b; 7 | ml p=*x,q=*y; 8 | return q.j-p.j; 9 | } 10 | int main(){ 11 | int n; 12 | int t=0; 13 | while(scanf("%d",&n)!=EOF&&n){ 14 | int i; 15 | for(i=1;i<=n;i++)scanf("%d%d",&m[i].b,&m[i].j); 16 | qsort(&m[1],n,sizeof(ml),cmp); 17 | int time[1010]; 18 | time[1]=m[1].b+m[1].j; 19 | for(i=2;i<=n;i++){ 20 | time[i]=time[i-1]-m[i-1].j+m[i].b+m[i].j; 21 | } 22 | int res=time[1]; 23 | for(i=2;i<=n;i++)if(time[i]>res)res=time[i]; 24 | ++t; 25 | printf("Case %d: %d\n",t,res); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Uva/11764 - Jumping Mario.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int z,x; 5 | scanf("%d",&z); 6 | for(x=1;x<=z;x++) 7 | { 8 | int time,i,s[10010]; 9 | scanf("%d",&time); 10 | for(i=1;i<=time;i++) 11 | { 12 | scanf("%d",&s[i]); 13 | } 14 | int high=0,low=0; 15 | for(i=1;is[i+1])low++; 19 | } 20 | printf("Case %d: %d %d\n",x,high,low); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Uva/11799 - Horror Dash.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int z,x; 5 | scanf("%d",&z); 6 | for(x=1;x<=z;x++) 7 | { 8 | int max,a,time,i,s[10010]; 9 | scanf("%d",&time); 10 | for(i=1;i<=time;i++)scanf("%d",&s[i]); 11 | max=s[1]; 12 | for(i=1;i<=time;i++)max=max>s[i]?max:s[i]; 13 | printf("Case %d: %d\n",x,max); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Uva/11805 - Bafana Bafana.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int z,x; 5 | scanf("%d",&z); 6 | for(x=1;x<=z;x++) 7 | { 8 | int n,k,p; 9 | scanf("%d%d%d",&n,&k,&p); 10 | int s=(k+p)%n; 11 | if(s==0)s=n; 12 | printf("Case %d: %d\n",x,s); 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Uva/11875 - Brick Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int cmp(const void *_a,const void *_b) 4 | { 5 | int *a=(int *)_a; 6 | int *b=(int *)_b; 7 | return *a-*b; 8 | } 9 | int main() 10 | { 11 | int i,k; 12 | scanf("%d",&k); 13 | for(i=1;i<=k;i++) 14 | { 15 | int a[200],b[200]; 16 | int s,j; 17 | scanf("%d",&s); 18 | for(j=1;j<=s;j++)scanf("%d",&a[j]); 19 | qsort(&a[1],s,sizeof(int),cmp); 20 | int k=(s+1)/2; 21 | printf("Case %d: %d\n",i,a[k]); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Uva/11877 - The Coco-Cola Store.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int f(int x) 3 | { 4 | if(x==2)return 3; 5 | if(x<=1)return x; 6 | return 3+f(x-2); 7 | } 8 | int main() 9 | { 10 | int n; 11 | while(scanf("%d",&n)==1) 12 | { 13 | if(n==0)break; 14 | printf("%d\n",f(n)-n); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Uva/11879 - Multiple of 17.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | bool is_17(char *s) 4 | { 5 | int sum=0,len=strlen(s); 6 | int i; 7 | int k[20]={-5,1,-7,-2,-3,4,6,9,5,-1,7,2,3,-4,11,8}; 8 | for(i=len-1;i>=0;i--) 9 | { 10 | sum+=k[(len-i)%16]*(s[i]-'0'); 11 | } 12 | if(sum%17==0)return 1; 13 | return 0; 14 | } 15 | int main() 16 | { 17 | char s[1010]; 18 | while(scanf("%s",s)!=EOF) 19 | { 20 | int len=strlen(s); 21 | if(len==1 && s[0]=='0')break; 22 | if(is_17(s))printf("1\n"); 23 | else printf("0\n"); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Uva/11900 - Boiled Eggs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int cmp(const void *a,const void *b) 4 | { 5 | int *z=(int *)a;int *x=(int *)b; 6 | return *z-*x; 7 | } 8 | int min(int a,int b){if(a>b)return b;return a;} 9 | int main() 10 | { 11 | int k,z; 12 | scanf("%d",&z); 13 | for(k=1;k<=z;k++) 14 | { 15 | int n,p,q,a[50],i; 16 | scanf("%d%d%d",&n,&p,&q); 17 | int sum=0,res=0; 18 | for(i=1;i<=n;i++)scanf("%d",&a[i]); 19 | qsort(&a[1],n,sizeof(int),cmp); 20 | // for(i=1;i<=n;i++)printf("%4d",a[i]);printf("\n"); 21 | for(i=1;i<=min(p,n);i++) 22 | { 23 | sum+=a[i]; 24 | // printf("%d\n",sum); 25 | if(sum>q){res=i-1;break;} 26 | else res=i; 27 | } 28 | printf("Case %d: %d\n",k,res); 29 | sum=0; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Uva/11934 - Magic Formula.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | long long a,b,c,d,l; 6 | while(scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&l)!=EOF) 7 | { 8 | if(a==0 && b==0 && c==0 && d==0 && l==0)break; 9 | long long i,count=0; 10 | for(i=0;i<=l;i++) 11 | { 12 | if(fmod(a*i*i+b*i+c,d)==0)count++; 13 | } 14 | printf("%lld\n",count); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Uva/11942 - Lumberjack Sequencing.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int z,x; 5 | scanf("%d",&z); 6 | printf("Lumberjacks:\n"); 7 | for(x=1;x<=z;x++) 8 | { 9 | int a[12]; 10 | int i; 11 | for(i=1;i<=10;i++)scanf("%d",&a[i]); 12 | int flag=1; 13 | if(a[1]>a[2]) 14 | { 15 | for(i=2;i<=9;i++)if(a[i]a[i+1]){flag=0;break;} 18 | if(flag)printf("Ordered\n"); 19 | else printf("Unordered\n"); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Uva/11968 - In The Airport.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/11968 - In The Airport.cpp -------------------------------------------------------------------------------- /Uva/11970 - Lucky Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int z,x; 5 | scanf("%d",&z); 6 | for(x=1;x<=z;x++) 7 | { 8 | int n; 9 | scanf("%d",&n); 10 | printf("Case %d:",x); 11 | int i; 12 | for(i=1;i*i=1;i--) 14 | { 15 | if(n%i==0)printf(" %d",n-i*i); 16 | } 17 | printf("\n"); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Uva/11984 - A Change in Thermal Unit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | double c,d; 4 | int k,z; 5 | scanf("%d",&z); 6 | for(k=1;k<=z;k++){ 7 | scanf("%lf%lf",&c,&d); 8 | d*=5/9.0; 9 | printf("Case %d: ",k); 10 | printf("%.2lf\n",c+d); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Uva/11991 - Easy Problem from Rujia Liu.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | std::vectorp[1000010]; 4 | int main(){ 5 | int n,m; 6 | while(scanf("%d%d",&n,&m)!=EOF){ 7 | int i; 8 | for(i=1;i<=1000000;i++)p[i].clear(); 9 | for(i=1;i<=n;i++){ 10 | int z; 11 | scanf("%d",&z); 12 | p[z].push_back(i); 13 | } 14 | int k,v; 15 | for(i=1;i<=m;i++){ 16 | scanf("%d%d",&k,&v); 17 | if(p[v].size()>=k)printf("%d\n",p[v][k-1]); 18 | else printf("0\n"); 19 | } 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Uva/12015 - Google is Feeling Lucky.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int z,x; 6 | scanf("%d",&z); 7 | for(x=1;x<=z;x++) 8 | { 9 | printf("Case #%d:\n",x); 10 | char a[12][110]; 11 | int aa[12]; 12 | int i; 13 | for(i=1;i<=10;i++)scanf("%s%d",a[i],&aa[i]); 14 | int max=aa[1]; 15 | for(i=1;i<=10;i++)max=max>aa[i]?max:aa[i]; 16 | for(i=1;i<=10;i++)if(aa[i]==max)printf("%s\n",a[i]); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Uva/12019 - Doom's Day Algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | void pt(int x) 3 | { 4 | if(x==1)printf("Monday\n"); 5 | if(x==2)printf("Tuesday\n"); 6 | if(x==3)printf("Wednesday\n"); 7 | if(x==4)printf("Thursday\n"); 8 | if(x==5)printf("Friday\n"); 9 | if(x==6)printf("Saturday\n"); 10 | if(x==7)printf("Sunday\n"); 11 | } 12 | int main() 13 | { 14 | int a[366],i,j,x,z,t=1; 15 | a[1]=6; 16 | for(i=2;i<=365;i++){a[i]=a[i-1]+1;if(a[i]>7)a[i]-=7;} 17 | int b[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 18 | scanf("%d",&z); 19 | int dp[13][32]; 20 | for(i=1;i<=12;i++) 21 | { 22 | for(j=1;j<=b[i];j++)dp[i][j]=a[t++]; 23 | } 24 | for(x=1;x<=z;x++) 25 | { 26 | int p,q; 27 | scanf("%d%d",&p,&q); 28 | pt(dp[p][q]); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Uva/1210 - Sum of Consecutive Prime Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | bool is_prime(int x) 3 | { 4 | int i; 5 | if(x==1)return false; 6 | for(i=2;i*i<=x;i++) 7 | { 8 | if(x%i==0)return false; 9 | } 10 | return true; 11 | } 12 | int main() 13 | { 14 | int dp[10010]; 15 | int prime[4000]; 16 | int i,mon=1,j; 17 | for(i=1;i<=10000;i++) 18 | { 19 | dp[i]=0; 20 | if(is_prime(i))prime[mon++]=i; 21 | } 22 | mon--; 23 | int k; 24 | for(i=1;i<=mon;i++) 25 | { 26 | for(j=i;j<=mon;j++) 27 | { 28 | int sum=0; 29 | for(k=i;k<=j;k++)sum+=prime[k]; 30 | if(sum<=10000)dp[sum]++; 31 | } 32 | } 33 | int n; 34 | while(scanf("%d",&n)==1 && n!=0) 35 | { 36 | printf("%d\n",dp[n]); 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Uva/12289 - One-Two-Three.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int k,z,i; 6 | char a[10]; 7 | scanf("%d",&z); 8 | for(k=1;k<=z;k++) 9 | { 10 | scanf("%s",a); 11 | if(strlen(a)==5)printf("%d\n",strlen(a)-2); 12 | else 13 | { 14 | if( (a[0]=='o'&&a[1]=='n') || (a[0]=='o'&&a[2]=='e') || (a[2]=='e'&&a[1]=='n') )printf("1\n"); 15 | else printf("2\n"); 16 | } 17 | for(i=0;i<10;i++)a[i]='\0'; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Uva/1339 - Ancient Cipher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int cmp(const void *aa,const void *bb) 5 | { 6 | int *a=(int *)aa; 7 | int *b=(int *)bb; 8 | return *b-*a; 9 | } 10 | int main(){ 11 | char a[110],b[110]; 12 | while(scanf("%s%s",a,b)!=EOF){ 13 | int pa[30],pb[30]; 14 | int i; 15 | for(i=0;i<26;i++)pa[i]=0; 16 | for(i=0;i<26;i++)pb[i]=0; 17 | int len=strlen(a); 18 | for(i=0;i 2 | bool a[999999999]={0}; 3 | int main() 4 | { 5 | freopen("out.txt","w",stdout); 6 | a[0]=a[1]=a[2]=a[5]=a[3]=1; 7 | int b[2000];int i,n,count=1; 8 | n=1500; 9 | for(i=1;;i++) 10 | { 11 | if((i%2==0 && a[i/2]) || (i%3==0 && a[i/3]) || (i%5==0 && a[i/5]) || a[i]){a[i]=1;b[count++]=i;} 12 | if(count==n+1)break; 13 | } 14 | for(i=1;i<=n;i++) 15 | { 16 | printf("b[%d]=%d;\n",i,b[i]); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Uva/146 - ID Codes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | char s[100]; 5 | while(scanf("%s",s)!=EOF){ 6 | int len=strlen(s); 7 | if(len==1&&s[0]=='#')break; 8 | int i; 9 | for(i=len-1;i>=1;i--){ 10 | if(s[i]>s[i-1])break; 11 | } 12 | if(i==0){ 13 | printf("No Successor\n"); 14 | continue; 15 | } 16 | int l=i-1; 17 | int j; 18 | for(j=0;j 2 | int main() 3 | { 4 | unsigned long long dp[6][30010]; 5 | unsigned long long money[6]={0,1,5,10,25,50}; 6 | int i; 7 | for(i=1;i<=5;i++) 8 | { 9 | dp[i][0]=1; 10 | dp[i][1]=1; 11 | } 12 | int k; 13 | for(i=1;i<=30000;i++)dp[1][i]=dp[1][i-1]; 14 | for(k=2;k<=5;k++) 15 | { 16 | for(i=1;i<=30000;i++) 17 | { 18 | dp[k][i]=dp[k-1][i]; 19 | if(i>=money[k])dp[k][i]+=dp[k][i-money[k]]; 20 | } 21 | } 22 | int n; 23 | while(scanf("%d",&n)==1) 24 | { 25 | if(dp[5][n]!=1) 26 | { 27 | printf("There are %llu ways to produce",dp[5][n]); 28 | printf(" %d cents change.\n",n); 29 | } 30 | else printf("There is only 1 way to produce %d cents change.\n",n); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Uva/151 - Power Crisis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int Josephus(int n,int m){ 3 | int i,j; 4 | int ok[110]; 5 | for(i=1;i<=n;i++)ok[i]=0; 6 | int count=m,start=1; 7 | for(i=1;in)j-=n; 11 | if(!ok[j]){ 12 | if(count==m){ 13 | start=j+1; 14 | ok[j]=1; 15 | count=1; 16 | break; 17 | } 18 | else count++; 19 | } 20 | } 21 | if(ok[13])return 0; 22 | } 23 | return 1; 24 | } 25 | int main(){ 26 | int dp[110]; 27 | int i,j; 28 | for(i=13;i<100;i++){ 29 | for(j=1;j<=2*i;j++){ 30 | // printf("%d %d\n",i,j); 31 | if(Josephus(i,j)){ 32 | dp[i]=j; 33 | break; 34 | } 35 | } 36 | } 37 | int n; 38 | while(scanf("%d",&n)!=EOF&&n)printf("%d\n",dp[n]); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Uva/152 - Tree's a Crowd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int p(int a) 4 | { 5 | return a*a; 6 | } 7 | int main() 8 | { 9 | int a[5100],b[5100],c[5100]; 10 | int n,t[20],i; 11 | for(i=1;i<=10;i++)t[i]=0; 12 | n=1; 13 | while(scanf("%d%d%d",&a[n],&b[n],&c[n])!=EOF) 14 | { 15 | if(a[n]==0&&b[n]==0&&c[n]==0)break; 16 | n++; 17 | } 18 | int j; 19 | for(i=1;i<=n;i++) 20 | { 21 | int s=2147483640; 22 | for(j=1;j<=n;j++) 23 | { 24 | if(i==j)continue; 25 | int k=p(a[j]-a[i])+p(b[j]-b[i])+p(c[j]-c[i]); 26 | if(k=p(j-1)&&s 2 | int abs(int x){if(x>0)return x;return -x;} 3 | int choi[10]; 4 | int map[10][10]; 5 | int res=0; 6 | bool place(int k){ 7 | int i; 8 | for(i=1;i8){ 17 | int sum=0; 18 | for(i=1;i<=8;i++)sum+=map[choi[i]][i]; 19 | if(sum>res)res=sum; 20 | } 21 | else { 22 | for(i=1;i<=8;i++){ 23 | choi[t]=i; 24 | if(place(t))queen(t+1); 25 | } 26 | } 27 | } 28 | int main(){ 29 | int k,z; 30 | scanf("%d",&z); 31 | for(k=1;k<=z;k++) 32 | { 33 | res=0; 34 | int i,j; 35 | for(i=1;i<=8;i++)for(j=1;j<=8;j++)scanf("%d",&map[i][j]); 36 | queen(1); 37 | printf("%5d\n",res); 38 | } 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Uva/193 - Graph Coloring.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/193 - Graph Coloring.cpp -------------------------------------------------------------------------------- /Uva/231 - Testing the CATCHER.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int test=1,f1,f2,k,g[100000],i=0; 6 | g[0]=32768; 7 | while(scanf("%d",&f1)==1) 8 | { 9 | if(f1==-1) 10 | { 11 | if(f2==-1)break; 12 | // for(k=1;k<=i;k++)printf("%4d",g[k]); 13 | if(test>=2)printf("\n"); 14 | printf("Test #%d:\n",test++); 15 | printf(" maximum possible interceptions: %d\n",i); 16 | memset(g,0,sizeof(g)); 17 | i=0; 18 | g[0]=32768; 19 | f2=f1; 20 | continue; 21 | } 22 | int j; 23 | // printf("%d %d\n",f1,f2); 24 | int s=g[i],a=f1; 25 | if(a<=s){i++;g[i]=a;} 26 | else 27 | { 28 | for(j=i;j>=1;j--) 29 | { 30 | if(g[j-1]>=a){g[j]=a;break;} 31 | // for(k=1;k<=i;k++)printf("%4d",g[k]);printf("\n"); 32 | } 33 | } 34 | f2=f1; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Uva/264 - Count on Cantor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | while(scanf("%d",&n)==1) 6 | { 7 | int xie; 8 | for(xie=1;;xie++){if(n<=xie*(xie+1)/2)break;} 9 | int x,y,i; 10 | if(xie%2==0){x=1,y=xie;} 11 | else{x=xie,y=1;} 12 | for(i=(xie*(xie-1)/2)+1;i 2 | int min(int a,int b) 3 | { 4 | if(a>b)return b; 5 | return a; 6 | } 7 | int main() 8 | { 9 | int k,z; 10 | scanf("%d",&z); 11 | for(k=1;k<=z;k++) 12 | { 13 | getchar(); 14 | char c; 15 | scanf("%c",&c); 16 | int m,n; 17 | scanf("%d%d",&m,&n); 18 | if(c=='r'||c=='Q')printf("%d\n",min(m,n)); 19 | if(c=='k') 20 | { 21 | if(m*n%2==0)printf("%d\n",m*n/2); 22 | else printf("%d\n",(m*n+1)/2); 23 | } 24 | if(c=='K') 25 | { 26 | if(m%2==1)m++; 27 | if(n%2==1)n++; 28 | m/=2; 29 | n/=2; 30 | printf("%d\n",m*n); 31 | } 32 | } 33 | // printf("!"); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Uva/294 - Divisors.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int s(int x) 3 | { 4 | int i;int count=0; 5 | for(i=1;i*ic[max-l])max=i;} 26 | printf("Between %d and %d, %d has a maximum of %d divisors.\n",l,u,max,c[max-l]); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Uva/299 - Train Swapping.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | scanf("%d",&n); 6 | int z; 7 | for(z=1;z<=n;z++) 8 | { 9 | int m; 10 | scanf("%d",&m); 11 | int a[60]; 12 | int i,temp; 13 | for(i=1;i<=m;i++)scanf("%d",&a[i]); 14 | int j;int count=0; 15 | for(j=1;j<=m*m;j++) 16 | { 17 | for(i=1;ia[i+1]) 20 | { 21 | count++; 22 | temp=a[i];a[i]=a[i+1];a[i+1]=temp; 23 | } 24 | } 25 | } 26 | printf("Optimal train swapping takes %d swaps.\n",count); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Uva/311 - Packets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[70]; 5 | int i; 6 | while(scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])!=EOF && !(!a[1]&&!a[2]&&!a[3]&&!a[4]&&!a[5]&&!a[6])) 7 | { 8 | int res=0; 9 | res+=a[6]+a[5]+a[4]; 10 | a[2]-=a[4]*5; 11 | int kong=a[5]*11; 12 | int s=(a[3]+3)/4;res+=s; 13 | int p=0; 14 | if(a[3]%4==3){p=1;kong+=5;} 15 | if(a[3]%4==2){p=3;kong+=6;} 16 | if(a[3]%4==1){p=5;kong+=7;} 17 | a[2]-=p; 18 | if(a[2]<0){a[2]=-a[2];kong+=a[2]*4;a[2]=0;} 19 | s=(a[2]+8)/9;res+=s; 20 | s=a[2]%9; 21 | if(s!=0)s=9-s;else s=0; 22 | s*=4; 23 | kong+=s; 24 | a[1]-=kong; 25 | if(a[1]<0)a[1]=0; 26 | res+=(a[1]+35)/36; 27 | printf("%d\n",res); 28 | } 29 | // return main(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Uva/369 - Combinations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | double m,n; 6 | while(scanf("%lf%lf",&n,&m)==2 && !(m==0 && n==0)) 7 | { 8 | printf("%.0lf things taken %.0lf at a time is ",n,m); 9 | double s; 10 | if(m>n-m)s=m; 11 | else s=n-m; 12 | double i,c=1; 13 | for(i=s+1;i<=n;i++)c*=i; 14 | for(i=1;i<=n-s;i++)c/=i; 15 | printf("%.0lf exactly.\n",round(c)); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Uva/375 - Inscribed Circles and Isosceles Triangles.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define PI M_PI 4 | #define eps 0.000001 5 | int main(){ 6 | double b,h; 7 | int t; 8 | scanf("%d",&t); 9 | while(t--){ 10 | double b,h; 11 | double A; 12 | scanf("%lf%lf",&b,&h); 13 | double B=atan( (b/2)/h ); 14 | double R=0,res=0; 15 | do{ 16 | res+=2*R; 17 | R=h*sin(B)/(1+sin(B)); 18 | h-=2*R; 19 | }while(R>eps); 20 | printf("%13lf\n",PI*res); 21 | if(t)printf("\n"); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Uva/382 - Perfection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | short a[60010]; 3 | int main() 4 | { 5 | int i,j; 6 | for(i=1;i<=60000;i++) 7 | { 8 | int sum=1; 9 | for(j=2;j*j<=i;j++) 10 | { 11 | if(i%j==0){sum+=j;if(j!=i/j)sum+=i/j;} 12 | } 13 | if(sum==i)a[i]=0; 14 | else if(sum>i)a[i]=1; 15 | else a[i]=-1; 16 | } 17 | a[1]=-1; 18 | int n; 19 | printf("PERFECTION OUTPUT\n"); 20 | while(scanf("%d",&n)==1) 21 | { 22 | if(n==0)break; 23 | if(a[n]==0)printf("%5d PERFECT\n",n); 24 | if(a[n]==-1)printf("%5d DEFICIENT\n",n); 25 | if(a[n]==1)printf("%5d ABUNDANT\n",n); 26 | } 27 | printf("END OF OUTPUT\n"); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Uva/408 - Uniform Generator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int gcd(int x,int y){ 3 | if(x 2 | #include 3 | int gcd(int x,int y){ 4 | if(x 2 | int main() 3 | { 4 | int z; 5 | while(scanf("%d",&z)==1 && z!=0) 6 | { 7 | int i,j;int a[20];char temp; 8 | for(i=1;i<=z;i++)a[i]=0; 9 | for(i=1;i<=z;i++) 10 | { 11 | for(j=1;j<=26;j++) 12 | { 13 | temp=getchar(); 14 | if(temp==' ')a[i]++; 15 | } 16 | } 17 | //for(i=1;i<=z;i++)printf("%d\n",a[i]); 18 | int b[20]; 19 | for(i=1;i<=z;i++)b[i]=a[i]-a[1]; 20 | int min=0; 21 | for(i=1;i<=z;i++)if(b[i] 2 | #define inf (int)1e9 3 | #include 4 | int g[110][110]; 5 | int n; 6 | int main(){ 7 | int n; 8 | while(scanf("%d",&n)!=EOF){ 9 | int i,j,k; 10 | for(i=1;i<=n;i++)for(j=1;j<=n;j++)if(i>j){ 11 | char s[100]; 12 | scanf("%s",s); 13 | if(s[0]=='x')g[i][j]=g[j][i]=inf; 14 | else { 15 | int r;sscanf(s,"%d",&r); 16 | g[i][j]=g[j][i]=r; 17 | } 18 | }else if(i==j)g[i][i]=0; 19 | for(k=1;k<=n;k++)for(i=1;i<=n;i++)for(j=1;j<=n;j++){ 20 | g[i][j]=std::min(g[i][j],g[i][k]+g[k][j]); 21 | } 22 | int res=0; 23 | for(i=2;i<=n;i++)res=std::max(res,g[1][i]); 24 | printf("%d\n",res); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Uva/424 - Integer Inquiry.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/424 - Integer Inquiry.cpp -------------------------------------------------------------------------------- /Uva/440 - Eeny Meeny Moo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int Josephus(int n,int m){ 3 | int i,j; 4 | int ok[160]; 5 | for(i=1;i<=n;i++)ok[i]=0; 6 | int count=m,start=1; 7 | for(i=1;in)j-=n; 11 | if(!ok[j]){ 12 | if(count==m){ 13 | start=j+1; 14 | ok[j]=1; 15 | count=1; 16 | break; 17 | } 18 | else count++; 19 | } 20 | } 21 | if(ok[2])return 0; 22 | } 23 | return 1; 24 | } 25 | int main(){ 26 | int dp[160]; 27 | int i,j; 28 | for(i=3;i<=150;i++){ 29 | for(j=1;;j++){ 30 | // printf("%d %d\n",i,j); 31 | if(Josephus(i,j)){ 32 | dp[i]=j; 33 | break; 34 | } 35 | } 36 | } 37 | int n; 38 | while(scanf("%d",&n)!=EOF&&n)printf("%d\n",dp[n]); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Uva/441 - Lotto.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int a[20]; 3 | int cho[20]; 4 | int k; 5 | bool check(int t){ 6 | int i; 7 | for(i=1;i=cho[t])return 0; 8 | return 1; 9 | } 10 | void op(int t){ 11 | int i; 12 | if(t>6){ 13 | int fi=1; 14 | for(i=1;i<=6;i++){ 15 | if(fi)fi=0; 16 | else printf(" "); 17 | printf("%d",a[cho[i]]); 18 | } 19 | printf("\n"); 20 | } 21 | else { 22 | for(i=1;i<=k;i++){ 23 | cho[t]=i; 24 | if(check(t))op(t+1); 25 | } 26 | } 27 | } 28 | int main(){ 29 | int c=0; 30 | while(scanf("%d",&k)!=EOF&&k){ 31 | ++c; 32 | if(c!=1)printf("\n"); 33 | int i; 34 | for(i=1;i<=k;i++)scanf("%d",&a[i]); 35 | op(1); 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Uva/445 - Marvelous Mazes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char c; 4 | int t=0; 5 | while( (c=getchar()) !=EOF){ 6 | if(c=='b')c=' '; 7 | if(c>='0'&&c<='9')t+=c-'0'; 8 | else if(c=='!'||c=='\n')printf("\n"); 9 | else if(t>0){ 10 | while(t--)putchar(c); 11 | t=0; 12 | } 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Uva/455 - Periodic Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int z; 6 | scanf("%d",&z); 7 | int k; 8 | for(k=1;k<=z;k++) 9 | { 10 | char a[999]; 11 | scanf("%s",a); 12 | int p,j; 13 | int len=strlen(a); 14 | for(p=1;;p++) 15 | { 16 | if(len%p!=0)continue; 17 | //printf("%d\n",len); 18 | //printf("%d\n",p); 19 | int flag=1; 20 | for(j=p; flag && j 2 | #include 3 | int dna[20]; 4 | int map[50],last[50]; 5 | void setfree(){ 6 | int i; 7 | for(i=0;i<=41;i++)map[i]=0; 8 | map[20]=1; 9 | } 10 | char f(int x){ 11 | if(x==0)return ' '; 12 | if(x==1)return '.'; 13 | if(x==2)return 'x'; 14 | if(x==3)return 'W'; 15 | } 16 | void put(){ 17 | int i; 18 | for(i=1;i<=40;i++)printf("%c",f(map[i])); 19 | printf("\n"); 20 | } 21 | int main(){ 22 | int z; 23 | scanf("%d",&z); 24 | while(z--){ 25 | int i; 26 | for(i=0;i<10;i++)scanf("%d",&dna[i]); 27 | setfree(); 28 | int j; 29 | for(i=1;i<=50;i++){ 30 | put(); 31 | for(j=0;j<=41;j++)last[j]=map[j]; 32 | for(j=1;j<=40;j++)map[j]=dna[ last[j-1]+last[j]+last[j+1] ]; 33 | } 34 | if(z!=0)printf("\n"); 35 | } 36 | // system("pause"); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Uva/458 - The Decoder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | char s[10000]; 6 | while(scanf("%s",s)!=EOF) 7 | { 8 | int i,len; 9 | len=strlen(s); 10 | for(i=0;i<=len-1;i++)s[i]-=7; 11 | puts(s); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Uva/465 - Overflow.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/465 - Overflow.cpp -------------------------------------------------------------------------------- /Uva/474 - Heads Tails Probability.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | double dp[1000010]; 3 | int ddp[1000010]; 4 | int main() 5 | { 6 | double s=1; 7 | int n; 8 | int i;int k; 9 | dp[0]=1;ddp[0]=0; 10 | for(i=1;i<=1000000;i++) 11 | { 12 | dp[i]=dp[i-1]*5; 13 | k=i-1-ddp[i-1]; 14 | while(dp[i]>=10){dp[i]/=10;k++;} 15 | ddp[i]=i-k; 16 | } 17 | while(scanf("%d",&n)==1) 18 | { 19 | printf("2^-%d = ",n); 20 | printf("%.3lfe-%d\n",dp[n],ddp[n]); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Uva/483 - Word Scramble.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/483 - Word Scramble.cpp -------------------------------------------------------------------------------- /Uva/488 - Triangle Wave.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void pri(int h){ 4 | int i,j; 5 | for(i=1;i=1;i--){ 10 | for(j=1;j<=i;j++)printf("%d",i); 11 | printf("\n"); 12 | } 13 | } 14 | int main(){ 15 | int n; 16 | int k,z; 17 | scanf("%d",&z); 18 | for(k=1;k<=z;k++){ 19 | int h,n,i; 20 | scanf("%d%d",&h,&n); 21 | for(i=1;i<=n;i++){ 22 | pri(h); 23 | if(!(k==z&&n==i))printf("\n"); 24 | } 25 | } 26 | // system("pause"); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Uva/489 - Hangman Judge.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/489 - Hangman Judge.cpp -------------------------------------------------------------------------------- /Uva/499 - What's The Frequency, Kenneth.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | char b[10000]; 6 | while(gets(b)) 7 | { 8 | int len=strlen(b); 9 | int i; 10 | int a[60]; 11 | for(i=1;i<=52;i++)a[i]=0; 12 | char dic[60]; 13 | for(i=1;i<=26;i++)dic[i]='A'-1+i; 14 | for(i=27;i<=52;i++)dic[i]='a'-1+i-26; 15 | for(i=0;i='a' && s<='z')a[s-'a'+1+26]++; 19 | if(s>='A' && s<='Z')a[s-'A'+1]++; 20 | } 21 | int max=0; 22 | for(i=1;i<=52;i++) 23 | { 24 | if(a[i]>max)max=a[i]; 25 | } 26 | for(i=1;i<=52;i++) 27 | { 28 | if(a[i]==max)printf("%c",dic[i]); 29 | } 30 | printf(" %d\n",max); 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Uva/524 - Prime Ring Problem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/524 - Prime Ring Problem.cpp -------------------------------------------------------------------------------- /Uva/530 - Binomial Showdown.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | double m,n; 5 | while(scanf("%lf%lf",&n,&m)==2 && !(m==0 && n==0)) 6 | { 7 | double s; 8 | if(m>n-m)s=m; 9 | else s=n-m; 10 | double i,c=1; 11 | for(i=s+1;i<=n;i++)c*=i; 12 | for(i=1;i<=n-s;i++)c/=i; 13 | printf("%.0lf\n",c); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Uva/532 - Dungeon Master.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/532 - Dungeon Master.cpp -------------------------------------------------------------------------------- /Uva/543 - Goldbach's Conjecture.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | bool p[1000010]={0}; 3 | bool is_prime(int x) 4 | { 5 | int i; 6 | if(x==1)return false; 7 | for(i=2;i*i<=x;i++) 8 | { 9 | if(x%i==0)return false; 10 | } 11 | return true; 12 | } 13 | int main() 14 | { 15 | int i; 16 | for(i=1;i<=1000000;i++)p[i]=is_prime(i); 17 | int n; 18 | while(scanf("%d",&n)==1 && n) 19 | { 20 | for(i=1;2*i<=n;i++) 21 | { 22 | if(p[i] && p[n-i])break; 23 | } 24 | printf("%d = %d + %d\n",n,i,n-i); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Uva/545 - Heads.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | double dp[9010]; 3 | int ddp[9010]; 4 | int main() 5 | { 6 | double s=1; 7 | int n; 8 | int i;int k; 9 | dp[0]=1;ddp[0]=0; 10 | for(i=1;i<=9000;i++) 11 | { 12 | dp[i]=dp[i-1]*5; 13 | k=i-1-ddp[i-1]; 14 | while(dp[i]>=10){dp[i]/=10;k++;} 15 | ddp[i]=i-k; 16 | } 17 | dp[6]=1.563;dp[7]=7.813; 18 | int z;scanf("%d",&z); 19 | for(k=1;k<=z;k++) 20 | { 21 | scanf("%d",&n); 22 | printf("2^-%d = %.3lfE-%d\n",n,dp[n],ddp[n]); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Uva/568 - Just the Facts.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MAX 100000 3 | int dp[10010]; 4 | int main(){ 5 | int i; 6 | dp[0]=1; 7 | for(i=1;i<=9999;i++){ 8 | dp[i]=i*dp[i-1]; 9 | while(dp[i]%10==0)dp[i]/=10; 10 | dp[i]%=MAX; 11 | } 12 | int n; 13 | while(scanf("%d",&n)!=EOF)printf("%5d -> %d\n",n,dp[n]%10); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Uva/572 - Oil Deposits.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/572 - Oil Deposits.cpp -------------------------------------------------------------------------------- /Uva/573 - The Snail.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/573 - The Snail.cpp -------------------------------------------------------------------------------- /Uva/575 - Skew Binary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | long long skew[32]; 6 | skew[1]=1; 7 | int i; 8 | for(i=1;i<=31;i++)skew[i+1]=2*skew[i]+1; 9 | char s[50]; 10 | while(scanf("%s",s)!=EOF) 11 | { 12 | int len=strlen(s); 13 | int zj[50]; 14 | int j; 15 | long long sum=0; 16 | for(j=1;j<=len;j++)zj[j]=s[len-j]-'0'; 17 | for(j=1;j<=len;j++)sum+=zj[j]*skew[j]; 18 | if(sum==0)break; 19 | printf("%lld\n",sum); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Uva/579 - ClockHands.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int h,m; 6 | while(scanf("%d:%d",&h,&m)==2) 7 | { 8 | if(h==0 && m==0)break; 9 | double res,hh=h,mm=m; 10 | double amm=mm*6; 11 | double ahh=hh*30; 12 | ahh+=mm/2; 13 | res=ahh-amm; 14 | if(res<0)res=-res; 15 | if(res>180)res=360-res; 16 | printf("%.3lf\n",res); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Uva/591 - Box of Bricks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n,k=0; 5 | while(scanf("%d",&n)==1 && n!=0) 6 | { 7 | k++; 8 | int a[60],i,sum=0; 9 | for(i=1;i<=n;i++){scanf("%d",&a[i]);sum+=a[i];} 10 | int avg=sum/n; 11 | int kum=0; 12 | for(i=1;i<=n;i++) 13 | { 14 | if(a[i] 2 | #include 3 | char s[1000010]; 4 | int main(){ 5 | int t; 6 | scanf("%d%*c",&t); 7 | while(t--){ 8 | gets(s); 9 | char res; 10 | int len=strlen(s); 11 | if(strcmp(s,"1")==0)res='+'; 12 | else if(strcmp(s,"4")==0)res='+'; 13 | else if(strcmp(s,"78")==0)res='+'; 14 | else { 15 | if(len>=2&&s[len-1]=='5'&&s[len-2]=='3')res='-'; 16 | else if(len>=2&&s[0]=='9'&&s[len-1]=='4')res='*'; 17 | else res='?'; 18 | } 19 | printf("%c\n",res); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Uva/623 - 500!.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int dp[1010][2610]; 3 | int main() 4 | { 5 | int i,j; 6 | for(i=1;i<=1000;i++)for(j=1;j<=2600;j++)dp[i][j]=0; 7 | dp[1][1]=1; 8 | dp[0][1]=1; 9 | for(i=1;i<=1000;i++) 10 | { 11 | for(j=1;j<=2600;j++)dp[i][j]=dp[i-1][j]*i; 12 | for(j=1;j<=2600;j++) 13 | { 14 | dp[i][j+1]+=dp[i][j]/10; 15 | dp[i][j]%=10; 16 | } 17 | } 18 | int n; 19 | while(scanf("%d",&n)!=EOF) 20 | { 21 | printf("%d!\n",n); 22 | int len; 23 | for(len=2600;len>=1;len--) 24 | { 25 | if(dp[n][len]!=0)break; 26 | } 27 | for(i=len;i>=1;i--)printf("%d",dp[n][i]);printf("\n"); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Uva/640 - Self Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | bool a[1000100]; 6 | int f(int i) 7 | { 8 | int sum=0,temp=i; 9 | while(temp>0) 10 | { 11 | sum+=temp%10; 12 | temp/=10; 13 | } 14 | return sum+i; 15 | } 16 | int main() 17 | { 18 | int i; 19 | memset(a,1,sizeof(a)); 20 | for(i=1;i<=1000000;i++) 21 | { 22 | a[f(i)]=0; 23 | } 24 | //printf("%.2f",(double)clock()/(CLOCKS_PER_SEC)); 25 | //system("pause"); 26 | for(i=1;i<=1000000;i++) 27 | { 28 | if(a[i])printf("%d\n",i); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Uva/641 - Do the Untwist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char map[30]="_abcdefghijklmnopqrstuvwxyz."; 4 | char f(char a,int i) 5 | { 6 | int s; 7 | if(a=='_')s=0; 8 | if(a>='a' && a<='z')s=a-'a'+1; 9 | if(a=='.')s=27; 10 | // printf("%d ",s); 11 | s+=i; 12 | s%=28; 13 | // printf("%d\n",s); 14 | return map[s]; 15 | } 16 | int main() 17 | { 18 | int k; 19 | while(scanf("%d",&k)&&k) 20 | { 21 | char cipher[100],plain[100]; 22 | scanf("%s",cipher); 23 | int i; 24 | int n=strlen(cipher); 25 | int cid[100]; 26 | for(i=0;i 2 | #include 3 | int main() 4 | { 5 | int k,z; 6 | scanf("%d",&z); 7 | char a[150];getchar(); 8 | for(k=1;k<=z;k++) 9 | { 10 | gets(a); 11 | int len=strlen(a); 12 | int i,j;int p=0; 13 | 14 | while(++p<=len) 15 | { 16 | for(i=1;i 2 | int main() 3 | { 4 | int max1[7510],max5[7510],max10[7510],max25[7510],max50[7510]; 5 | int i; 6 | max1[0]=1;max5[0]=1;max10[0]=1;max25[0]=1;max50[0]=1; 7 | for(i=1;i<=7500;i++) 8 | { 9 | max1[i]=max1[i-1]; 10 | } 11 | for(i=1;i<=7500;i++) 12 | { 13 | max5[i]=max1[i]; 14 | if(i>=5)max5[i]+=max5[i-5]; 15 | } 16 | for(i=1;i<=7500;i++) 17 | { 18 | max10[i]=max5[i]; 19 | if(i>=10)max10[i]+=max10[i-10]; 20 | } 21 | for(i=1;i<=7500;i++) 22 | { 23 | max25[i]=max10[i]; 24 | if(i>=25)max25[i]+=max25[i-25]; 25 | } 26 | for(i=1;i<=7500;i++) 27 | { 28 | max50[i]=max25[i]; 29 | if(i>=50)max50[i]+=max50[i-50]; 30 | } 31 | int n; 32 | while(scanf("%d",&n)==1) 33 | { 34 | printf("%d\n",max50[n]); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Uva/686 - Goldbach's Conjecture (II).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | bool p[33000]={0}; 3 | bool is_prime(int x) 4 | { 5 | int i; 6 | if(x==1)return false; 7 | for(i=2;i*i<=x;i++) 8 | { 9 | if(x%i==0)return false; 10 | } 11 | return true; 12 | } 13 | int main() 14 | { 15 | int i; 16 | for(i=1;i<=33000;i++)p[i]=is_prime(i); 17 | int n; 18 | while(scanf("%d",&n)==1 && n) 19 | { 20 | int count=0; 21 | for(i=1;2*i<=n;i++) 22 | { 23 | if(p[i] && p[n-i])count++; 24 | } 25 | printf("%d\n",count); 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Uva/694 - The Collatz Sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int f(long long a,long long b) 3 | { 4 | if(a==1)return 1; 5 | long long s; 6 | if(a%2==0)s=a/2; 7 | else s=3*a+1; 8 | if(s>b)return 1; 9 | else return 1+f(s,b); 10 | } 11 | int main() 12 | { 13 | long long a,b;int ca=1; 14 | while(scanf("%lld %lld",&a,&b)==2 && !(a==-1,b==-1)) 15 | { 16 | printf("Case %d: A = %lld, limit = %lld, number of terms = %d\n",ca++,a,b,f(a,b)); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Uva/696 - How Many Knights.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int m,n; 5 | while(scanf("%d%d",&m,&n)!=EOF) 6 | { 7 | int res; 8 | if(m==0&&n==0)break; 9 | if(m*n==0)res=0; 10 | else if(m>=3&&n>=3) 11 | { 12 | if(m*n%2==0)res=m*n/2; 13 | else res=(m*n+1)/2; 14 | } 15 | else if(m==1)res=n; 16 | else if(n==1)res=m; 17 | else if(m==2) 18 | { 19 | if(n==2)res=4; 20 | else if(n%4==1)res=2+(n-1); 21 | else if(n%4==3)res=m*(n+1)/2; 22 | else if(n%4==2)res=4+(n-2); 23 | else res=n; 24 | } 25 | else if(n==2) 26 | { 27 | if(m==2)res=4; 28 | else if(m%4==1)res=2+(m-1); 29 | else if(m%4==3)res=n*(m+1)/2; 30 | else if(m%4==2)res=4+(m-2); 31 | else res=m; 32 | } 33 | printf("%d knights may be placed on a %d row %d column board.\n",res,m,n); 34 | res=0; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Uva/701 - The Archeologists' Dilemma.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int len(int n) 4 | { 5 | int i=0; 6 | while(n!=0){n/=10;i++;} 7 | return i; 8 | } 9 | double log2(double a) 10 | { 11 | return log(a)/log(2); 12 | } 13 | int main() 14 | { 15 | int n; 16 | while(scanf("%d",&n)!=EOF) 17 | { 18 | int p=len(n)+1; 19 | int e,res; 20 | // double q=floor(log2(n))+1; 21 | // printf("%d\n",p); 22 | // if(p==len(n))p+=1; 23 | for(;;p++) 24 | { 25 | int flag=0; 26 | double xqj=log2(n)+p*log2(10); 27 | double sqj=log2(n+1)+p*log2(10); 28 | for(e=(int)xqj-1;e=xqj){res=e;/*printf("%lf\t%lf\n",xqj,sqj);*/flag=1;} 31 | } 32 | if(flag)break; 33 | } 34 | printf("%d\n",res); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Uva/706 - LCD Display.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Uva/706 - LCD Display.cpp -------------------------------------------------------------------------------- /Uva/729 - The Hamming Distance Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int m,n; 3 | int cho[20]; 4 | bool check(int t){ 5 | int i,sum=0; 6 | for(i=1;i<=t;i++)sum+=cho[i]; 7 | if(sum>m)return 0; 8 | return 1; 9 | } 10 | void op(int t){ 11 | int i; 12 | if(t>n){ 13 | int sum=0; 14 | for(i=1;i<=n;i++)sum+=cho[i]; 15 | if(sum==m){ 16 | for(i=1;i<=n;i++)printf("%d",cho[i]); 17 | printf("\n"); 18 | } 19 | } 20 | else { 21 | for(i=0;i<=1;i++){ 22 | cho[t]=i; 23 | if(check(t))op(t+1); 24 | } 25 | } 26 | } 27 | int main(){ 28 | int k,z; 29 | scanf("%d",&z); 30 | for(k=1;k<=z;k++){ 31 | scanf("%d%d",&n,&m); 32 | op(1); 33 | if(k!=z)printf("\n"); 34 | } 35 | // return main(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Uva/834 - Continued Fractions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int p,q; 6 | while(scanf("%d%d",&p,&q)==2) 7 | { 8 | int a[100000];a[1]=0; 9 | int i,wz=0; 10 | while(1) 11 | { 12 | a[wz++]=p/q; 13 | int z=p,x=q; 14 | z-=(int)(p/q)*q; 15 | p=q;q=z; 16 | if(q==0)break; 17 | } 18 | wz--; 19 | printf("[%d",a[0]); 20 | for(i=1;i<=wz;i++){if(i==1)printf(";%d",a[i]);else printf(",%d",a[i]);} 21 | printf("]\n"); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Uva/847 - A Multiplication Game.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | unsigned long long a[100]; 5 | int i; 6 | a[1]=1; 7 | for(i=2;i<=30;i++) 8 | { 9 | if(i%2==1)a[i]=a[i-1]*2; 10 | else a[i]=a[i-1]*9; 11 | } 12 | // for(i=1;i<=30;i++)printf("%d:%I64u\n",i,a[i]); 13 | unsigned long long n; 14 | while(scanf("%llu",&n)!=EOF) 15 | { 16 | int flag; 17 | for(i=1;i<=29;i++) 18 | { 19 | if(a[i]=n&&i%2==1)flag=1; 20 | if(a[i]=n&&i%2==0)flag=2; 21 | } 22 | if(flag==1)printf("Stan wins.\n"); 23 | else if(flag==2)printf("Ollie wins.\n"); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Uva/880 - Cantor Fractions.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | long long n; 6 | while(scanf("%lld",&n)==1) 7 | { 8 | long long xie; 9 | for(xie=sqrt(2*n)-1;;xie++){if(n<=xie*(xie+1)/2)break;} 10 | long long x,y,i; 11 | x=xie,y=1; 12 | long long cz=n-1-(xie*(xie-1)/2); 13 | x-=cz;y+=cz; 14 | printf("%lld/%lld\n",x,y); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Uva/900 - Brick Wall Patterns.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | unsigned long long dp[60]; 3 | int main() 4 | { 5 | int i; 6 | dp[1]=1;dp[2]=2; 7 | for(i=3;i<=50;i++)dp[i]=dp[i-1]+dp[i-2]; 8 | int n; 9 | while(scanf("%d",&n)!=EOF&&n)printf("%llu\n",dp[n]); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Uva/913 - Joana and the Odd Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | unsigned long long n,m; 5 | while(scanf("%lld",&n)==1) 6 | { 7 | m=(n+1)*(n+1)*3/2-9; 8 | printf("%llu\n",m); 9 | } 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Uva/962 - Taxicab Numbers.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | int i; 6 | int j; 7 | int p,q; 8 | while(scanf("%d%d",&p,&q)==2) 9 | { 10 | int a[100010]; 11 | for(i=0;i<=q;i++)a[i]=0; 12 | for(i=1;;i++) 13 | { 14 | int s=i*i*i; 15 | if(s>p+q)break; 16 | for(j=i;;j++) 17 | { 18 | int m=s+j*j*j; 19 | if(mp+q)break; 21 | a[m-p]+=1; 22 | } 23 | } 24 | int flag=1; 25 | for(i=0;i<=q;i++)if(a[i]>=2){flag=0;printf("%d\n",i+p);} 26 | if(flag)printf("None\n"); 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Zoj/2107.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Zoj/2107.cpp -------------------------------------------------------------------------------- /Zoj/3421.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ronnoc/Training/b69eb3b7cd6370ff0247ff1e52bc8b001f5840e2/Zoj/3421.cpp -------------------------------------------------------------------------------- /_Template/Data Structure/BIT.cpp: -------------------------------------------------------------------------------- 1 | inline int LB(int x) {return x & (-x);} 2 | struct BIT { 3 | LL _[MXN+5]; 4 | int n; 5 | void init(int m) { 6 | n = m + 5; 7 | for (int i = 0; i <= n; i++)_[i] = 0; 8 | } 9 | LL query(int w) { 10 | LL ret = 0; 11 | for (w += 3; w > 0; w -= LB(w))ret += _[w]; 12 | return ret; 13 | } 14 | void update(int w, LL d) { 15 | for (w += 3; w < n; w += LB(w))_[w] += d; 16 | } 17 | int find_Kth(int k) { //UESTC_Dagon 18 | int ans=0,cnt=0; 19 | for(int i=22;i>=0;i--){ 20 | ans+=1<=n||cnt+_[ans]>=k)ans-=1< class Matrix{ 3 | public: 4 | int n,m ; 5 | T a[MXN][MXN]; 6 | Matrix() {memset(a , 0 , sizeof(a));} 7 | Matrix(int _n , int _m) { 8 | n = _n , m = _m , memset(a , 0 , sizeof(a)); 9 | }; 10 | T* operator[] (int i) {return a[i];} 11 | Matrix friend operator * (Matrix A , Matrix B){ 12 | Matrix ans(A.n , B.m); 13 | for (int i = 0 ; i < A.n ; ++ i) 14 | for (int j = 0 ; j < A.m ; ++ j)if(A[i][j]!=0) 15 | for (int k = 0 ; k < B.m ; ++ k) 16 | ans[i][k]=ans[i][k]+A[i][j]*B[j][k]; 17 | return ans; 18 | } 19 | }; -------------------------------------------------------------------------------- /_Template/Math/Polya.cpp: -------------------------------------------------------------------------------- 1 | //Polya 原理 2 | //>验题:poj1286 3 | 4 | //返回置换最小周期,num返回循环节个数 5 | int polya (int* perm, int n, int& num) { 6 | int i, j, p, v[MXN] = {0}, ret = 1; 7 | for (num = i = 0; i < n; i++)if (!v[i]) { 8 | for (num++, j = 0, p = i; !v[p = perm[p]]; j++) 9 | v[p] = 1; 10 | ret *= j / __gcd (ret, j); 11 | } 12 | return ret; 13 | } -------------------------------------------------------------------------------- /_Template/Math/Polynomial_interpolation.cpp: -------------------------------------------------------------------------------- 1 | //多项式拟合 2 | //>EternalReality 3 | 4 | typedef double VAL; 5 | // 传入y=f(x)上的n个点,拟合出对应的一元n-1次方程,返回各项系数 6 | // VAL类型需支持加、减、乘、除、取反、加等于这六种操作 7 | vector interpolation(const VAL x[], const VAL y[], int n) { 8 | vector u(y, y + n), ret(n), sum(n); 9 | ret[0] = u[0], sum[0] = 1; 10 | for (int i = 1; i < n; i++) { 11 | for (int j = n - 1; j >= i; j--) u[j] = (u[j] - u[j - 1]) / (x[j] - x[j - i]); 12 | for (int j = i; j; j--) { 13 | sum[j] = -sum[j] * x[i - 1] + sum[j - 1]; 14 | ret[j] += sum[j] * u[i]; 15 | } 16 | sum[0] = -sum[0] * x[i - 1]; 17 | ret[0] += sum[0] * u[i]; 18 | } 19 | return ret; 20 | } -------------------------------------------------------------------------------- /_Template/Math/Simpson.cpp: -------------------------------------------------------------------------------- 1 | //自适应Simpson 2 | //>验题:hdu4978 3 | 4 | long double simpson(long double a, long double b) { 5 | long double c = a + (b - a) / 2; 6 | return (f(a) + 4 * f(c) + f(b)) * (b - a) / 6; 7 | } 8 | long double asr(long double a, long double b, long double eps, long double A) { 9 | long double c = a + (b - a) / 2; 10 | long double L = simpson(a, c), R = simpson(c, b); 11 | if (fabs(L + R - A) < 15 * eps) return L + R + (L + R - A) / 15.; 12 | return asr(a, c, eps / 2, L) + asr(c, b, eps / 2, R); 13 | } 14 | long double asr(long double a, long double b, long double eps) { 15 | return asr(a, b, eps, simpson(a, b)); 16 | } -------------------------------------------------------------------------------- /_Template/Math/sqrtBigInteger.java: -------------------------------------------------------------------------------- 1 | public static BigInteger getsqrt(BigInteger n) { 2 | if (n.compareTo(BigInteger.ZERO) <= 0) return n; 3 | BigInteger x, xx, txx; xx = x = BigInteger.ZERO; 4 | for (int t = n.bitLength() / 2; t >= 0; t--) { 5 | txx = xx.add(x.shiftLeft(t + 1)).add(BigInteger.ONE.shiftLeft(t + t)); 6 | if (txx.compareTo(n) <= 0) { 7 | x = x.add(BigInteger.ONE.shiftLeft(t)); xx = txx; 8 | } 9 | } 10 | return x; 11 | } -------------------------------------------------------------------------------- /_Template/Math/直线下格点统计.cpp: -------------------------------------------------------------------------------- 1 | //直线下格点统计 2 | //>shoka 3 | //sigma i in range(0,n) [(a+b*i)/m] 4 | //n,m>0;a,b>=0; 5 | LL count(LL n, LL a, LL b, LL m) { 6 | if (b == 0) 7 | return n * (a / m); 8 | if (a >= m) 9 | return n * (a / m) + count(n, a % m, b, m); 10 | if (b >= m) 11 | return (n - 1) * n / 2 * (b / m) + count(n, a, b % m, m); 12 | return count((a + b * n) / m, (a + b * n) % m, m, b); 13 | } -------------------------------------------------------------------------------- /_Template/Number Theory/CRT.cpp: -------------------------------------------------------------------------------- 1 | LL extGcd (LL a, LL b, LL &x, LL &y) { 2 | LL ret = a; 3 | if (b) { 4 | ret = extGcd (b, a % b, y, x); 5 | y -= (a / b) * x; 6 | } else x = 1, y = 0; 7 | return ret; 8 | } 9 | LL modInv (LL a, LL m) { 10 | LL x, y; 11 | extGcd(a, m, x, y); 12 | return (m + x % m) % m; 13 | } 14 | //模同余方程组中国剩余定理 15 | //>验题:poj2891 16 | //a_i*x=b_i {%m_i} m_i可以不互质 17 | //pair x=b {%m} 18 | pair linearMod( vector&A, vector&B, vector&M ) { 19 | LL x = 0, m = 1; 20 | for ( int i = 0; i < A.SZ; i++ ) { 21 | LL a = A[i] * m, b = B[i] - A[i] * x, d = __gcd( M[i], a ); 22 | if ( b % d )return MP( 0, -1 ); 23 | LL t = b / d * modInv( a / d, M[i] / d ) % ( M[i] / d ); 24 | x += m * t; 25 | m *= M[i] / d; 26 | x %= m; 27 | } 28 | return MP( ( ( x % m ) + m ) % m, m ); 29 | } -------------------------------------------------------------------------------- /_Template/Number Theory/eulerPhi.cpp: -------------------------------------------------------------------------------- 1 | //欧拉函数 2 | //>验题: poj 1284 3 | 4 | int eulerPhi (int n) { // test: phi(846720)=193536 5 | int res = n; 6 | for (int i = 2; i * i <= n; i++) //可用质数加速 7 | if (n % i == 0) { 8 | res = res / i * (i - 1); 9 | for (; n % i == 0; n /= i); 10 | } 11 | if (n != 1) res = res / n * (n - 1); 12 | return res; 13 | } -------------------------------------------------------------------------------- /_Template/Number Theory/extGcd.cpp: -------------------------------------------------------------------------------- 1 | //扩展欧几里得 2 | //>ax+by==gcd(a,b)的解 3 | //>验题: poj1061 4 | 5 | LL extGcd (LL a, LL b, LL &x, LL &y) { 6 | LL ret = a; 7 | if (b) { 8 | ret = extGcd (b, a % b, y, x); 9 | y -= (a / b) * x; 10 | } else x = 1, y = 0; 11 | return ret; 12 | } -------------------------------------------------------------------------------- /_Template/Number Theory/modInv.cpp: -------------------------------------------------------------------------------- 1 | //逆元 2 | //>验题: poj2447 3 | //for(inv[1]=1,i=2;i<10000;i++)inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;//MOD is prime 4 | LL extGcd (LL a, LL b, LL &x, LL &y) { 5 | LL ret = a; 6 | if (b) { 7 | ret = extGcd (b, a % b, y, x); 8 | y -= (a / b) * x; 9 | } else x = 1, y = 0; 10 | return ret; 11 | } 12 | LL modInv (LL a, LL m) { 13 | LL x, y; 14 | extGcd(a, m, x, y); 15 | return (m + x % m) % m; 16 | } 17 | //if m为质数 [费马小定理]a^(m-1)=1 mod m ==>a^(m-2)是a关于m的逆元 -------------------------------------------------------------------------------- /_Template/Number Theory/moebius.cpp: -------------------------------------------------------------------------------- 1 | //莫比乌斯 2 | //>验题:zju_watashi(map) 3 | map moebius (LL n) { 4 | map res; 5 | vectorprime; 6 | int i, j; 7 | for (i = 2; i * i <= n; i++) 8 | if (n % i == 0) { 9 | prime.push_back (i); 10 | while (n % i == 0) n /= i; 11 | } 12 | if (n != 1) prime.push_back (n); 13 | int m = prime.size(); 14 | for (int i = 0; i < (1 << m); i++) { 15 | int mu = 1, d = 1; 16 | for (j = 0; j < m; j++) { 17 | if (i >> j & 1) { 18 | mu *= -1; 19 | d *= prime[j]; 20 | } 21 | res[d] = mu; 22 | } 23 | } 24 | return res; 25 | } -------------------------------------------------------------------------------- /_Template/Number Theory/二次剩余.cpp: -------------------------------------------------------------------------------- 1 | //求解x^2=a mod P 2 | //>验题:ural 1132 3 | LL modPow( LL x, LL n, LL mod ) { 4 | LL ret = 1; 5 | while ( n ) { 6 | if ( n & 1 )ret = ret * x % mod; 7 | x = x * x % mod; 8 | n >>= 1; 9 | } 10 | return ret; 11 | } 12 | //call(b,0,a,(p+1)/2,p) return a sol of {x^2=a (mod p)} 13 | //{p is odd prime}&&{a^[(p-1)/2]=1 mod p}&&{b^( (p-1)/2 )==-1 mod p} 14 | LL call(LL b, LL c, LL a, LL x, LL p) { 15 | if (x % 2 == 0)return modPow(b, c / 2, p) * modPow(a, x / 2, p) % p; 16 | LL tp = modPow(b, c / 2, p) * modPow(a, (x - 1) / 2, p) % p; 17 | if (tp == 1)return call(b, c / 2, a, (x + 1) / 2, p); 18 | return call(b, (c + p - 1) / 2, a, (x + 1) / 2, p); 19 | } -------------------------------------------------------------------------------- /_Template/Number Theory/线性递推求mod后最小.cpp: -------------------------------------------------------------------------------- 1 | //线性递推取模最小值 2 | //>验题 : hdu5022 3 | LL getmin(LL start, LL slope, LL cnt, LL mod) { //min{ (start+k*slope)%mod | 0<=k<=cnt } 4 | start %= mod; 5 | if (start + slope * cnt < mod)return start; 6 | if (start >= slope) { 7 | int use = (mod - 1 - start) / slope + 1; 8 | return min(start, getmin(start + use * slope, slope, cnt - use, mod)); 9 | } 10 | LL res = start; 11 | LL ns = slope - mod % slope; 12 | LL ncnt = (start + slope * cnt) / mod; 13 | return min(res, getmin(start, ns, ncnt, slope)); 14 | } -------------------------------------------------------------------------------- /_Template/Number Theory/阶乘模分解.cpp: -------------------------------------------------------------------------------- 1 | //阶乘模分解 2 | //>验题:浙大shi哥译书 3 | 4 | int fact[MAX_P]; //预处理n! mod p 的表 O(min(n,p)) 5 | // n!=a*p^e return a%p 6 | int modFact (int n, int p, int &e) { 7 | e = 0; 8 | if (!n) return 1; 9 | int res = modFact (n / p, p, e); 10 | e += n / p; 11 | if (n / p % 2) 12 | return res * (p - fact[n % p]) % p; 13 | return res * fact[n % p] % p; 14 | } -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | # install vim 2 | curl https://j.mp/spf13-vim3 -L > spf13-vim.sh && sh spf13-vim.sh 3 | 4 | # oh-my-zsh 5 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" 6 | 7 | # my .zshrc 8 | curl -fLo ~/.zshrc https://raw.githubusercontent.com/Ronnoc/Training/master/.zshrc 9 | --------------------------------------------------------------------------------