浙大ACM题库分类
acm数学竞赛试题
acm数学竞赛试题
ACM数学竞赛试题通常涉及各种数学领域,包括但不限于代数、几何、概率统计和组合数学等。
以下是一些经典的ACM数学竞赛试题:
1. 平面上n个点的k距离和最小值问题:给定平面上n个点,对于每个点,计算它到其他所有点的距离,然后求出这些距离中的k个最小值。
问题是:如何有效地计算这k个最小值?
2.最长公共子序列问题:给定两个序列,找出它们的最长公共子序列。
例如,对于序列
A = [1, 2, 3, 4] 和
B = [2, 3, 4, 5],最长公共子序列是[2, 3, 4]。
3. 凸包问题:给定平面上的一组点,找到一个最小的凸多边形,使得这个多边形能够包含这组点中的所有点。
4. 最短路问题:给定一个有向图,其中每条边都有一个非负的权重,找出图中任意两点之间的最短路径。
5. 子集和问题:给定一个正整数数组和一个目标值,判断数组中是否存在和为目标值的两个非空子集。
例如,给定数组[1, 2, 3, 4] 和目标值7,判断是否存在两个子集,它们的和分别为7。
以上只是ACM数学竞赛试题的一部分,实际上还有更多涉及数学各个领域的题目。
要提高解决这类问题的能力,需要不断练习和研究。
ACM题目分类总结及pku题目分类
ACM题目分类总结及pku题目分类第一篇:ACM题目分类总结及pku题目分类ACM题目分类总结及pku题目分类ACM-题型分类的代码主流算法:1.搜索 //回溯 2. DP(动态规划)3.贪心4.图论 //Dijkstra、最小生成树、网络流 5.数论 //解模线性方程6.计算几何 //凸壳、同等安置矩形的并的面积与周长 7.组合数学 //Polya定理 8.模拟9.数据结构 //并查集、堆 10.博弈论1、排序, 1723, 1727, 1763, 1788, 1828, 1838, 1840, 2201, 2376, 2377, 2380, 1318, 1877, 1928, 1971, 1974, 1990, 2001, 2002, 2092, 2379,1002(需要字符处理,排序用快排即可)1007(稳定的排序)2159(题意较难懂)2231 2371(简单排序)2388(顺序统计算法)2418(二叉排序树)2、搜索、回溯、遍历1022 1111 1118 1129 1190 1562 1564 1573 1655 2184 2225 2243 2312 2362 2378 2386 1010 1011 1018 1020 1054 1062 1256 1321 1363 1501 1650 1659 1664 1753 2078 2083 2303 2310 2329 简单:1128, 1166, 1176, 1231, 1256, 1270, 1321, 1543, 1606, 1664, 1731, 1742, 1745, 1847, 1915, 1950, 2038, 2157, 2182, 2183, 2381, 2386, 2426不易:1024, 1054, 1117, 1167, 1708, 1746, 1775, 1878, 1903, 1966, 2046, 2197,2349 推荐:1011, 1190, 1191, 1416, 1579, 1632, 1639, 1659, 1680, 1683, 1691, 1709, 1714, 1753, 1771, 1826, 1855, 1856, 1890, 1924, 1935, 1948, 1979, 1980, 2170, 2288, 2331, 2339, 2340,1979(和迷宫类似)1980(对剪枝要求较高)3、历法1008 2080(这种题要小心)4、枚举1387,2363,2381,1054(剪枝要求较高),1650(小数的精度问题)5、数据结构的典型算法容易:1182, 1656, 2021, 2023, 2051, 2153, 2227, 2236, 2247, 2352, 2395, 不易:1145, 1177, 1195, 1227, 1661, 1834,推荐:1330, 1338, 1451, 1470, 1634, 1689, 1693, 1703, 1724, 1988, 2004, 2010, 2119, 2274, 1125(弗洛伊德算法),2421(图的最小生成树)6、动态规划1037 A decorative fence 1050 To the Max 1088 滑雪Stockbroker Grapevine 1141 Brackets Sequence 1159 Palindrome 1160 Post Office 1163 The Triangle 1458 Common Subsequence 1579 Function Run Fun 1887 Testing the CATCHER 1953 World Cup Noise 2386 Lake Counting7、贪心 , , 1230, 1323, 1477, 1716, 1784,1328 1755(或用单纯形方法),2054,1017,1328,1862, 1922, 2054,2209,2313,2325,23708、模拟容易:1006, 1008, 1013, 1016, 1017, 1169, 1298, 1326, 1350, 1363, 1676, 1786, 1791, 1835, 1970, 2317, 2325, 2390,不易:1012, 1082, 1099, 1114, 1642, 1677, 1684, 1886,1281 1928 2083 2141 20159、递归 166410、字符串处理1488, 1598, 1686, 1706, 1747, 1748, 1750, 1760, 1782, 1790, 1866, 1888, 1896, 1951, 2003, 2121, 2141, 2145, 2159, 2337, 2359, 2372, 2406, 2408, 1016 1051 1126 1318 1572 1917 1936 2039 2083 2136 2271 2317 2330,2121 240311、数论1014, 1023, 1061, 1152, 1183, 1730, 226212、几何有关的题目凸包:1113, 1228, 1794, 2007, 2187,1113 wall,2187 beauty contest 容易:1319, 1654, 1673, 1675, 1836, 2074, 2137, 2318, 不易:1685, 1687, 1696, 1873, 1901, 2172, 2333,13、任意精度运算、数字游戏、高精度计算1001 1023 1047 1060 1079 1131 1140 1142 1207 1220 1284 1289 1306 1316 1338 1405 1454 1503 1504 1519 1565 1650 1969 2000 2006 2081 2247 2262 2305 2316 2389 1001, 1220, 1405, 1503,1001(高精度乘法)2413(高精度加法,还有二分查找)14、概率统计 1037,105015、小费用最大流、最大流2195 going home2400 supervisor, supervisee 1087 a plug for UNIX 1149 PIGS 1273 drainage ditches 1274 the perfect stall 1325 machine schedule 1459 power network 2239 selecting courses16、压缩存储的DP1038 bugs integrated inc,1185 炮兵阵地,2430 lazy cow17、最长公共子串(LCS)1080 human gene functions,1159 palindrome,1458 common subsequence,2192 zipper18、图论及组合数学2421 Constructing Roads 2369 Permutations 2234 Matches Game 2243 Knight Moves 2249 Binomial Showdown 2255 Tree Recovery 2084 Game of Connections 1906 Three powers 1833 排列 1850 Code1562 Oil Deposits 1496 Word Index 1306 Combinations1125 Stockbroker Grapevine 1129 Channel Allocation 1146 ID Codes1095 Trees Made to Order找规律2247 Humble Numbers2309 BST2346 Lucky tickets 2370 Democracy in danger 2365 Rope2101 Honey and Milk Land 2028 When Can We Meet? 2084 Game of Connections 1915 Knight Moves 1922 Ride to School 1941 The Sierpinski Fractal 1953 World Cup Noise1958 Strange Towers of Hanoi 1969 Count on Canton 1806 Manhattan 2025 1809 Regetni 1844 Sum1870 Bee Breeding 1702 Eva‘s Balance 1728 A flea on a chessboard 1604 Just the Facts 1642 Stacking Cubes 1656 Counting Black1657 Distance on Chessboard 1662 CoIns 1663 Number Steps 1313 Booklet Printing 1316 Self Numbers 1320 Street Numbers 1323 Game Prediction 1338 Ugly Numbers 1244 Slots of Fun 1250 Tanning Salon 1102 LC-Display 1147 Binary codes 1013 Counterfeit Dollar19、博弈类1067 取石子游戏1740 A New Stone Game 2234 Matches Game 1082 Calendar Game 2348 Euclid‘s Game 2413 How many Fibs? 2419 Forest20、简单、模拟题1001 Exponentiation 1002 487-3279 1003 Hangover1701 Dissatisfying Lift 2301 Beat the Spread!2304 Combination Lock 2328 Guessing Game 2403 Hay Points 2406 Power Strings2339 Rock, Scissors, Paper 2350 Above Average2218 Does This Make Me Look Fat? 2260 Error Correction 2262 Goldbach‘s Conjecture 2272 Bullseye2136 Vertical Histogram 2174 Decoding Task 2183 Bovine Math Geniuses 2000 Gold Coins 2014 Flow Layout 2051 Argus 2081 Calendar 1918 Ranking List 1922 Ride to School 1970 The Game 1972 Dice Stacking 1974 The Happy Worm 1978 HanafudaShuffle 1979 Red and Black 1617 Crypto Columns 1666 Candy Sharing Game 1674 Sorting by Swapping 1503 Integer Inquiry 1504 Adding Reversed Numbers 1528 Perfection1546 Basically Speaking 1547 Clay Bully 1573 Robot Motion 1575 Easier Done Than Said? 1581 A Contesting Decision 1590 Palindromes1454 Factorial Frequencies 1363 Rails1218 THE DRUNK JAILER 1281 MANAGER 1132 Border1028 Web Navigation21、初等数学1003 Hangover 1045 Bode Plot1254 Hansel and Grethel 1269 Intersecting Lines 1401 Factorial 1410 Intersection 2363 Blocks 2365 Rope2242 The Circumference of the Circle 2291 Rotten Ropes 2295 A DP Problem2126 Factoring a Polynomial 2191 Mersenne Composite Numbers 2196 Specialized Four-Digit Numbers 1914 Cramer‘s Rule 1835 宇航员 1799 Yeehaa!1607 Deck1244 Slots of Fun 1269 Intersecting Lines 1299 Polar Explorer 1183 反正切函数的应用22、匹配1274, 1422, 1469, 1719, 2060, 2239,23、经典1011(搜索好题)1012(学会打表)10131019(它体现了很多此类问题的特点)1050(绝对经典的dp)1088(dp好题)1157(花店,经典的dp)1163(怎么经典的dp那么多呀)1328(贪心)1458(最长公共子序列)1647(很好的真题,考临场分析准确和下手迅速)1654(学会多边形面积的三角形求法)1655(一类无根树的dp问题)1804(逆序对)2084(经典组合数学问题)2187(用凸包求最远点对,求出凸包后应该有O(N)的求法,可我就是调不出来)2195(二分图的最佳匹配)2242(计算几何经典)2295(等式处理)2353(dp,但要记录最佳路径)2354(立体解析几何)2362(搜索好题)2410(读懂题是关键)2411(经典dp)24、趣味1067(很难的数学,但仔细研究,是一片广阔的领域)1147(有O(n)的算法,需要思考)1240(直到一棵树的先序和后序遍历,那么有几种中序遍历呢?dp)1426(是数论吗?错,是图论!)1648(别用计算几何,用整点这个特点绕过精度的障碍吧)1833(找规律)1844(貌似dp或是搜索,其实是道有趣的数学题)1922(贪心,哈哈)22312305(不需要高精度噢)2328(要仔细噢)2356(数论知识)2359(约瑟夫问题变种)2392(有趣的问题)25、很繁的题1001 10081087(构图很烦,还有二分图的最大匹配)1128(USACO)1245 13291550(考的是读题和理解能力)1649(dp)2200(字符串处理+枚举)2358(枚举和避免重复都很烦)2361(仔细仔细再仔细)26、难题1014(数学证明较难,但有那种想法更重要)1037(比较难的dp)1405(高精度算法也有等级,不断改进吧)2002(有没有比O(n^2*logn)更有的算法?)2054(极难,很强的思考能力)2085(组合数学)2414(dp,但要剪枝)2415(搜索)2423(计算几何+统计)27、多解题1002(可以用排序,也可以用统计的方法)1338(搜索和dp都可以)1664(搜索和dp都练一练吧)2082(这可是我讲的题噢)2352(桶排和二叉树都行)28、Note:1011: 很经典的剪支 1014: 难在数学上1017: 严格的数学证明貌似不容易1021: 有点繁,考察对图形进行各种旋转 1083: 巧妙的思考角度 1150: 分奇偶讨论,lg(n)算法1218: 三行就够,虽然简单,但也有优劣之别 1505: 二分加贪心1654: 做法也许很多,本人用有向面积做的 1674: 计算圈的个数(算是graph 吧)1700: 数学证明不容易 1742: O(m*n)的算法 1863: 要耐心地慢慢写…^_^ 1988: 并查集 2051: 堆2078: 不难,但剪支可以做到很好2082::O(n),你想到了吗?2084: 卡特兰数 2182: 线段树2195: 最小费用最大流 2234: 经典博弈算法 2236: 并查集 2299: 二分思想2395: Kruskal 最小生成树的拓展 2406: KMP2411: 用二进制串来表示状态第二篇:垃圾分类题目判断1.打印,墨盒属于有害垃圾(×,是可回收垃圾)2.PC塑料瓶可以制成衣服(×是PET塑料瓶)3.废胶卷及废相纸属于其他垃圾(错,应是有害垃圾)4.污染纸张属于其他垃圾(对)5.世界上最早对包装垃圾分类回收进行立法的是德国(对)6.餐厨废弃物资源化利用和无公害化处理试点城市启动至今,目前已有83个城市成为试点(错,应是100个)7.口红是干垃圾(对)8.烟头是有害垃圾(错)9.家里枯萎的水培植物和鲜花属于其他垃圾(错)10.消毒剂及其包装物属于可回收垃圾(错)单选11.城市垃圾分类处理的基本原则是(BC)A.合理利用,变废为宝B.全民动员,科学引导C.政府主导,社会参与D.统筹规划,综合布局12.可以燃烧的生活垃圾包括(AB)A.废旧木头B.废塑料橡胶C.不易回收的废纸D.玻璃13.没有泡过的干茶叶属于哪类垃圾(AC)A.厨余垃圾B.干垃圾C.湿垃圾D.可回收垃圾E.有害垃圾14.以下哪些不与生活垃圾混合投放(ABD)A.沙发B.油漆桶C.宠物饲料D.砖石混凝土15.危险性包装是指盛装具有对人体,动植物和生态环境有危害特性物资的包装物,包括下列哪些特性描述(BCD)A.易爆性B.易燃性C.腐蚀性D.感染性16.生活垃圾分类办法是根据什么来制定的(ABD)A.处理方式B.管理水平C.居民生活习惯D.垃圾特性17.有害生活垃圾单独收运和处理工作已引起社会高度重视,下列废弃物中哪个不是生活中的有害垃圾(AC)A.烟头B.温度计C.碱性电池D.过期药品E.含汞荧光灯18.垃圾分类的意义,在于实现了生活垃圾(BE)减量化,资源化,无害化A.减量化,整合化B.资源化,无害化C.减量化,分类化D.资源化,整合化E.无害化,减量化19.下列关于垃圾分类的语句正确的是(AD)A.红危危,绿厨厨,蓝宝宝,黄其其B.绿色回收又能卖,红色有毒又有害C.蓝色剩菜瓜果皮,黄灰桶里放其他D.湿纸巾再湿也是干垃圾20.白色垃圾的危害(ACD)A.不易降解,混在土壤里影响农作物吸收养分和水分,导致农作物减产B.混在生活垃圾中不会增加后续处理难度C.影响市容及景观D.焚烧过程中产生大量有毒气体多选21.生物垃圾通常指随着时间的推移可以得到化学分解有机物垃圾以及动物尸体,通常占总量的多少(B)A.30%B.40%C.50%D.60%22.回收1.5吨的废纸可以造好纸约(B)公斤(425+850=1275)A.1255B1275C.1295D.130023.一氧化碳可与人血红蛋白结合致人中毒死亡,排放一氧化碳量较多的汽车状态是(A)A.开着发动机停车等候时B.高速行驶C.超速行驶D.缓慢行驶24.那种垃圾可以重新提炼出有用的材料(B)A.厨余垃圾B.有害垃圾C.可回收垃圾D.其他垃圾25.下列不属于其他垃圾的是(C)A.灰土烟头B.废弃纸巾C.果皮D.宠物粪便26.羊毛衫,靠垫,牙签,筷子,旧手机分别属于什么垃圾(C)A.可回收垃圾,干垃圾,干垃圾,可回收垃圾,有害垃圾B.干垃圾,可回收垃圾,干垃圾,可回收垃圾,有害垃圾C.可回收垃圾,可回收垃圾,干垃圾,干垃圾,可回收垃圾D.干垃圾,干垃圾,可回收垃圾,可回收垃圾,有害垃圾27.薄型塑料袋,吃剩的罐头食品,用完的笔芯,受潮过期的瓜子分别属于什么垃圾(B)A.可回收垃圾,湿垃圾,干垃圾,干垃圾B.干垃圾,湿垃圾,干垃圾,湿垃圾C.可回收垃圾,湿垃圾,可回收垃圾,湿垃圾D.干垃圾,湿垃圾,可回收垃圾,干垃圾28.可回收垃圾是指回收后经过再加工,整理可以成为生产原料或再利用的物品,不包括(D)A.电子废弃品B.纸类C.塑料类D.杀虫剂29.黑色塑料袋,洗发水瓶,葡萄干,没用完的铅笔分别属于哪类垃圾(D)A.可回收垃圾,可回收垃圾,干垃圾,可回收垃圾B.干垃圾,可回收垃圾,干垃圾,干垃圾C.可回收垃圾,干垃圾,湿垃圾,可回收垃圾D.干垃圾,可回收垃圾,湿垃圾,干垃圾30.粉底液,大棒骨,鸡骨头,湿垃圾袋分别是什么垃圾(A)A.干垃圾,干垃圾,湿垃圾,干垃圾B.湿垃圾,干垃圾,湿垃圾,可回收垃圾C.干垃圾,湿垃圾,干垃圾,可回收垃圾D.湿垃圾,干垃圾,湿垃圾,干垃圾31.巧克力,菜刀,洗干净的化妆瓶,睫毛夹分别属于什么垃圾(B)A.干垃圾,有害垃圾,可回收垃圾,干垃圾B.湿垃圾,可回收垃圾,可回收垃圾,可回收垃圾C.湿垃圾,有害垃圾,干垃圾,可回收垃圾D.干垃圾,可回收垃圾,干垃圾,干垃圾32.椰壳,木梳,化妆棉,假花分别属于什么垃圾(D)A.干垃圾,有害垃圾,湿垃圾,可回收垃圾B.可回收垃圾,有害垃圾,干垃圾,干垃圾C.可回收垃圾,干垃圾,湿垃圾,干垃圾D.干垃圾,可回收垃圾,干垃圾,可回收垃圾33.新版《生活垃圾分类标志》标准于12月1日起正式实施,由原来的()大类改为现在的四大类,分别为可回收垃圾,有害垃圾,(),()。
ACM题库完整版
#include<stdio.h> int type(int); char week[7][10]={"saturday","sunday","monday","tuesday","wednesday","thursday","friday"}; int year[2]={365,366}; int month[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31}; int main(void) { int days,dayofweek; int i=0,j=0; while(scanf("%d",&days)&&days!=-1) { dayofweek=days%7; for(i=2000;days>=year[type(i)];i++) days-=year[type(i)]; for(j=0;days>=month[type(i)][j];j++) days-=month[type(i)][j]; printf("%d-%02d-%02d%s\n",i,j+1,days+1,week[dayofweek]); } return 0; } int type(int m) { if(m%4!=0||(m%100==0&&m%400!=0)) return 0; else return 1; }
登山
1.题目描述 五一到了,NUIST-ACM队组织大家去登 山观光,队员们发现山上一个有N个景点, 并且决定按照顺序来浏览这些景点,即 每次所浏览景点的编号都要大于前一个 浏览景点的编号。同时队员们还有另一 个登山习惯,就是不连续浏览海拔相同 的两个景点,并且一旦开始下山,就不 再向上走了。队员们希望在满足上面条 件的同时,尽可能多的浏览景点,你能 帮他们找出最多可能浏览的景点数么? 2.输入 Line 1: N (2 <= N <= 1000) 景点数 Line 2: N个整数,每个景点的海拔 3.输出 最多能浏览的景点数 4.样例输入 8 186 186 150 200 160 130 197 220 5.样例输出 4
acm各大OJ题目分类
id page section no title18 1.2.1例题1盒子里的气球148359 3.1.2例题2管道问题149387 3.3.1例题1篱笆问题150388 3.3.1例题2合金制造问题151401 3.3.4例题1点集的直径29 1.2.1例题2图书馆313 1.2.2例题1钓鱼1438 1.3.1引例小球钟——时间与运动1540 1.3.1引例笑脸1644 1.3.2引例猜猜我想说什么1750 1.3.3引例勇士Ilya的故事1852 1.3.3例题1蚂蚁和瓢虫413 1.2.2例题2照亮的山景515 1.2.2例题3镜子盒2468 1.3.5例题1电缆2569 1.3.5引例黑白按钮2670 1.3.5例题2煎饼2772 1.3.5引例傻瓜Ivanushka的故事619 1.2.3例题1折纸痕720 1.2.3例题2三色多边形820 1.2.3例题3聪明的学生923 1.2.3例题4丢失的数1028 1.2.4例题1月亮之眼1129 1.2.4例题2Yanghee的数表1231 1.2.4例题3原子链1336 1.3.1引例铁轨1438 1.3.1引例小球钟——时间与运动1540 1.3.1引例笑脸1644 1.3.2引例猜猜我想说什么1750 1.3.3引例勇士Ilya的故事1852 1.3.3例题1蚂蚁和瓢虫1954 1.3.3例题2隔三遍历2061 1.3.4引例拯救大兵瑞恩的故事2162 1.3.4引例英雄和公主的故事2264 1.3.4引例电气工程师2367 1.3.5引例爱丽丝和精灵的故事2468 1.3.5例题1电缆2569 1.3.5引例黑白按钮2670 1.3.5例题2煎饼2772 1.3.5引例傻瓜Ivanushka的故事2875 1.3.5例题3士兵排队2976 1.3.5例题4最小可靠交换3080 1.4.1例题1代码等式3181 1.4.1例题2团伙3281 1.4.1例题3银河英雄传说3382 1.4.1例题4可爱的猴子3483 1.4.1例题5蜗牛3589 1.4.2例题1积水3689 1.4.2例题2赛车3790 1.4.2例题3可怜的奶牛3891 1.4.2例题4最轻巧的语言3997 1.4.3例题1马尔可夫链4099 1.4.3例题2促销41102 1.4.3例题3采矿42108 1.4.4例题1火星地图43110 1.4.4例题2最长回文子串44113 1.5.1例题1括号序列45116 1.5.1例题2棋盘分割46117 1.5.1例题3决斗47117 1.5.1例题4“舞蹈家”怀特先生48119 1.5.1例题5积木游戏49123 1.5.2例题1方块消除50123 1.5.2例题2公路巡逻51125 1.5.2例题3并行期望值52126 1.5.2例题4高性能计算机53130 1.5.2例题5模板匹配54131 1.5.2例题6不可分解的编码55133 1.5.2例题7青蛙的烦恼56134 1.5.2例题8排列问题57135 1.5.2例题9最优排序二叉树58138 1.5.2例题10Bugs公司59139 1.5.2例题11迷宫统计60142 1.5.2例题12贪吃的九头龙61150 1.5.3问题1最长公共子序列问题62150 1.5.3例题1排列的LCS问题63151 1.5.3问题2最长上升子序列问题64151 1.5.3问题3最优二分检索树65152 1.5.3问题4任务调度问题66155 1.5.3例题2序列分割67160 1.6.2引例加密网格68162 1.6.2引例最优程序69164 1.6.2引例旋转的玩具70169 1.6.3引例编辑书稿71171 1.6.3引例埃及分数72175 1.6.4引例三角形大战73178 1.6.4例题1L游戏74180 1.6.5例题1带宽75181 1.6.5例题2小木棍76181 1.6.5例题3生日蛋糕77183 1.6.5例题4汽车问题78184 1.6.5例题5Betsy的旅行79189 1.6.6例题1外公的难题80193 1.6.7例题1篮球冠军赛81204 2.1例题1 “麻烦”子82204 2.1例题2沙漠83205 2.1例题3浪人苏比84206 2.1例题4好动的佳佳85207 2.1例题5细菌86208 2.1例题6X行星87220 2.2.1例题1佳佳的困惑88220 2.2.1例题2除法表达式89221 2.2.1例题3数字游戏90221 2.2.1例题4fibonacci质数91222 2.2.1例题5神秘数92225 2.2.2例题1自动取款机93226 2.2.2例题2人类学家的烦恼94226 2.2.2例题3征服者的军营95233 2.2.3例题1仓库问题96233 2.2.3例题2二进制Stirling数97234 2.2.3例题3荒岛野人98240 2.3.2例题1单色三角形99243 2.3.2引例互不攻击的象100245 2.3.3例题1传球游戏101247 2.3.3例题2无聊的排序102252 2.3.3例题3多边形103257 2.3.4例题1装饰栅栏104258 2.3.4例题2Pibonacci数105259 2.3.4例题3巧克力106274 2.4.2例题1绣花107275 2.4.2例题2漆门108275 2.4.2例题3原始基因109276 2.4.2例题4超级翻转110281 2.4.3例题1地图的五着色111282 2.4.3例题2滑雪112283 2.4.3例题3水平可见线段的三角形113287 2.4.4例题1往返路114287 2.4.4例题2连通图编号问题115287 2.4.4例题3跳舞蝇116289 2.4.4例题4参观洞穴117291 2.4.4例题5公主和英雄118293 2.4.4例题6通讯员119295 2.4.4例题7幼儿园小朋友分组120299 2.5.1引例岛国121300 2.5.1引例野餐计划122303 2.5.1引例地震123304 2.5.2引例罗密欧与朱丽叶124306 2.5.2引例出纳员的雇佣125308 2.5.2例题1瘦陀陀与胖陀陀126309 2.5.2例题2新桥127310 2.5.2例题3穿越沙漠128311 2.5.2例题4隐型石头129312 2.5.2例题5双调路径130315 2.5.3引例奶牛的新年晚会131317 2.5.3引例航天计划问题132318 2.5.3引例终极情报网133323 2.5.3例题1圆桌吃饭问题134324 2.5.3例题2数字游戏135324 2.5.3例题3混合图的欧拉回路136325 2.5.3例题4家园137326 2.5.3例题5道路扩容138329 2.5.4引例神奇的魔术师139331 2.5.4引例任务安排140332 2.5.4引例棋盘上的骑士141333 2.5.4引例丘比特的烦恼142333 2.5.4引例魔术球问题143334 2.5.4例题1皇家卫士144336 2.5.4例题2固定分区的内存管理145336 2.5.4例题3玩具兵146338 2.5.4例题4千年盛典147353 3.1.2例题1房间最短路问题148359 3.1.2例题2管道问题149387 3.3.1例题1篱笆问题150388 3.3.1例题2合金制造问题151401 3.3.4例题1点集的直径152402 3.3.4例题2最小外接矩形153404 3.3.4例题3点集分割154410 3.4.1例题1锡刀154410 3.4.2例题2锡刀154410 3.4.3例题3锡刀154410 3.4.4例题4锡刀154410 3.4.5例题5锡刀154410 3.4.6例题6锡刀154410 3.4.7例题7锡刀154410 3.4.8例题8锡刀154410 3.4.9例题9锡刀154410 3.4.10例题10锡刀154410 3.4.11例题11锡刀154410 3.4.12例题12锡刀problem sourceACM/ICPC World Finals 2002. Problem A. Balloons in a BoxACM/ICPC Regional Contest Central Europe 1995. Problem D. Pipe(Classic)(Classic)(Classic)ACM/ICPC Regional Contest Northeast Europe 2001. Problem G. Library. Author: Elena Kryuchkova, Roman Elizarov ACM/ICPC Regional Contest East Central North America 1999. Problem G. Gone FishingACM/ICPC World Finals 1995. Problem B. Tempus et mobilius Time and MotionInternet Problem Solving Contest 2001. Problem F. A Censored SmileIOI2002 Practice Session Problem 2. String from substringsUSU high school programming contest 2001. Problem G.Ilya Murumetz. Author: Katz O.E.Polish Olympiad in Informatics 2001. Stage II Problem 4. Ants and the ladybugCentral European Olympiad in Informatics 2000. Day 2 Problem 3. Enlightened LandscapeBaltic Olympiad in Informatics 2001. Day 1 Problem 3. MirrorACM/ICPC Regional Contest Northeast Europe 2001. Problem C. Cable Master. Author: Vladimir Pinaev, Roman Elizaro Internet Problem Solving Contest 2000. Problem F. PuzzleUniversity of Duke Programming Contest 1993. Problem C. Stacks of FlapjacksUSU high school programming contest 2001. Problem A. Gaby Ivanushka. Author: Shamgunov N.ACM/ICPC Regional Contest South Pacific 1992. Problem F. Paper FoldingThird USU personal programming contest, Ekaterinburg, Russia, February 16, 2002. Author:Dmitry Filimonenkov CTSC 2001. Day 1 Problem 3. Clever. Author: Li Zhang(Classic)Balkan Olympiad in Informatics 1998. Day 2 Problem 2. Evil EyesACM/ICPC Regional Contest Asia-Taejon 2000. Problem H. Lost ListsCentral European Olympiad in Informatics 2001. Day 1 Problem 1. ChainACM/ICPC Regional Contest Central European 1997. Problem A. RailsACM/ICPC World Finals 1995. Problem B. Tempus et mobilius Time and MotionInternet Problem Solving Contest 2001. Problem F. A Censored SmileIOI2002 Practice Session Problem 2. String from substringsUSU high school programming contest 2001. Problem G.Ilya Murumetz. Author: Katz O.E.Polish Olympiad in Informatics 2001. Stage II Problem 4. Ants and the ladybugPolish Olympiad in Informatics 1995. Stage III Problem 2. Step Traversing a TreeCTSC 1999. Day 2 Problem 3. RescueACM/ICPC Regional Contest Asia-Shanghai 1999. Problem I. Princess and HeroCentral European Olympiad in Informatics 1996. Day 2 Problem 3. ElectricianInternet Problem Solving Contest 2000. Problem C. TrollsACM/ICPC Regional Contest Northeast Europe 2001. Problem C. Cable Master. Author: Vladimir Pinaev, Roman Elizaro Internet Problem Solving Contest 2000. Problem F. PuzzleUniversity of Duke Programming Contest 1993. Problem C. Stacks of FlapjacksUSU high school programming contest 2001. Problem A. Gaby Ivanushka. Author: Shamgunov N.Central European Olympiad in Informatics 1998. Day 2 Problem 1. SolidersACM/ICPC Regional Contest Central European 2001. Problem E. ExchangesPolish Olympiad in Informatics 1998. Stage II Problem 2. Word EquationsBaltic Olympiad in Informatics 2003. Day 2 Problem 1. The GangsNOI2002 Day 1 Problem 1. Galaxy. Author: Ji LuoPolish Olympiad in Informatics 2003. Stage III Problem 1. Monkey(Classic)Polish Olympiad in Informatics 1999. Stage III Problem 6. WaterCentral European Olympiad in Informatics 2003. Day 1 Problem 3. The RaceOIBH Reminiscene Programming Contest. Problem E. Eat or Not to Eat. Author: Rujia LiuPolish Olympiad in Informatics 1998. Stage III Problem 4. The lightest languageCTSC 2001. Day 2 Problem 2. Markov. Author: Runting ShiPolish Olympiad in Informatics 2000. Stage III Problem 6. PromotionPolish Olympiad in Informatics 2001. Stage III Problem 5. GoldmineBaltic Olympiad in Informatics 2001. Day 2 Problem 2. Mars MapsACM/ICPC Regional Contest Asia-Kanpur 2001. Problem E. Viewer's Prize in F-TVACM/ICPC Regional Contest Northeast Europe 2001. Problem B. Bracket Sequence. Author: Andrew StankevichNOI99 Day 2 Problem 1. ChessPolish Olympiad in Informatics 1999. Stage I Problem 1. MusketeersACM/ICPC Regional Contest Asia-Shanghai 2000. Problem C. Dance Dance RevolutionNOI97 Day 2 Problem 2. GameIOI2003 National Training Team Originals. Author: Cailiang Liu. ModifiedCTSC2000. Day 1 Problem 3. Patrol. Author: Shenjie LiACM/ICPC Regional Contest Asia-Tehran 2001. Problem G. Parallel ExpectationIOI2001 National Training Team Winter Camp. Problem 2. HPC. Author: Xin QiCentral European Olympiad in Informatics 2001. Day 2 Problem 2. PatternsACM/ICPC World Finals 2002. Problem B. Undecodable Codes(Classic)(Classic)CTSC2001. Day 2 Problem 2. Tree. Author: Fan YangCentral European Olympiad in Informatics 2002. Day 1 Problem 1. BugsElite Problemsetters' First Contest. Problem A. Maze Statistics. Author: Derek KismanNOI2002 Day 1 Problem 3. Dragon. Modification of Internet Problem Solving Contest 2001. B. Author: Ziqing Mao (Classic)(Classic)(Classic)(Classic)IOI2002 Day 2 Problem 1. BatchBalkan Olympiad in Informatics 2003. Day 2 Problem 2. Euro. ModifiedCentral European Olympiad in Informatics 1996. Day 1 Problem 1. Encoding GridACM/ICPC Regional Contest Southwestern Europe 1996. Problem A. Optimal ProgramsACM/ICPC Regional Contest Southwestern Europe 1999. Problem E. Color HashACM/ICPC Regional Contest Asia-Kanpur 2001. Problem G. Editing a Book(Classic)ACM/ICPC Regional Contest East Central North America 1999. Problem A. Traingle WarBaltic Olympiad in Informatics 2002. Day 2 Problem 2. L game. Author: Jimmy MårdellNew Zealand Programming Contest 1991. Problem A. BandwidthACM/ICPC Regional Contest Central Europe 1995. Problem H. SticksNOI99 Day 1 Problem 3. CakeIOI94 Day 2 Problem 1. CarUSACO Computing Olympiad4th Shuguang Programming Contest. Author: Rujia LiuBaltic Olympiad in Informatics 1999. Day 1 Problem 3. BasketballUral Collegiate Programming Contest, April 2001, Perm English TourRomanian Open Contest, December 2001. Author: Mugurel Ionut AndreicaIOI99 National Training Team Originals. Author: Fangfang XiaIV Ural State University Collegiate Programming Contest. Problem G. Nikifor's Walk. Author: Dmitry Filimonenkov Internet Problem Solving Contest 2003. Problem H. Hordes of BacteriaCentral European Olympiad in Informatics 2000. Day 1 Problem 1. X-PlanetUSU Open Collegiate Programming Contest March'2001 Senior Session. Problem F. Nikifor. Author: Filimonenkov D. Baltic Olympiad in Informatics 2000. Day 2 Problem 1. DIVRandy Game. Problem D. Number Game. Author: Chong LongACM/ICPC World Finals Warm-up Contest(Oriental) 2002, Problem A. The Fibonacci Primes. Author: Shahriar Manzoor ACM/ICPC Regional Contest Southeastern European 2001. Problem C. Secret NumbersPolish Olympiad in Informatics 1998. Stage III Problem 2. ATM'sACM/ICPC Regional Contest Southwestern Europe 1999. Problem B. The Archeologists' DilemmaCentral European Olympiad in Informatics 2002. Day 1 Problem 2. ConquerTetrahedron Team Contest May 2001. Problem H. Warehouse Problem. Author: D. FilimonenkovACM/ICPC Regional Contest Central Europe 2001. Problem B. Binary Stirling Numbers.NOI2002. Day 2 Problem 1. Savages. Author: Rujia LiuPolish Olympiad in Informatics 1997. Stage III Problem 5. Monochromatic TrianglesACM/ICPC World Finals Warm-up Contest(Oriental) 2002, Problem B. Bishops. Author: Rezaul Alam ChowdhuryIOI2000 National Training Team Originals. Author: Yi GuoACM/ICPC World Finals 2002. Problem H. Silly Sort(Classic)Central European Olympiad in Informatics 2002. Day 1 Problem 3. FenceInternet Problem Solving Contest 2001. Problem G. FibonacciACM/ICPC Regional Contest Beijing 2002. Problem F. ChocolateUral Collegiate Programming Contest '99. Problem H. Cross-Stitch. Author: Zaletsky PIV Ural State University Collegiate Programming Contest. Problem F. Door Painting. Author: Magaz AsanovPolish Olympiad in Informatics 1999. Stage III Problem 5. PrimitivusIOI2003 National Training Team Originals. Author: Zhilei Xu.(Classic)Polish Olympiad in Informatics 2000. Stage I Problem 3. SkiersACM/ICPC Regional Contest Central Europe 2001. Problem H. Horizontally Visible SegmentsCentral European Olympiad in Informatics 2001. Day 1 Problem 3. Round Trip(Classic)Polish Olympiad in Informatics 2001. Stage III Problem 1. Wandering flees TrainersCentral European Olympiad in Informatics 1997. Day 1 Problem 1. CAVACM/ICPC Regional Contest Central Europe 2001. Problem A. Alice and BobPolish Olympiad in Informatics 1996. Stage I Problem 3. MessengersIV Ural State University Collegiate Programming Contest. Problem E. Partition into Groups. Author: Dmitry Filimonenko ACM/ICPC World Finals 2002. Problem E. IslandACM/ICPC Regional Contest East Central North America 2000. Problem A. PicnicUSACO Computing Olympiad US Open 2001. Problem 2. EarthquakeInternet Problem Solving Contest 1999. Problem H. Romeo and JulietACM/ICPC Regional Contest Asia-Tehran 2000. Problem G. Cashier EmploymentACM/ICPC World Finals Warm-up Contest(Occidental) 2002. Problem A. Asterix and Obelix. Author: Rezaul Alam Cho Balkan Olympiad in Informatics 2000. Day 2 Problem 1. BridgeACM/ICPC World Finals 2002. Problem C. Crossing the DesertACM/ICPC Regional Warm-up Contest 2002. Problem D. The Rock. Author: Jimmy MårdellBaltic Olympiad in Informatics 2002. Day 2 Problem 1. Bicriterial routingUSA Computing Olympiad Winter 2002. Problem 2. New Years Party. Author: Hal Burch(Classic)CTSC2001. Day 1 Problem 1. Agent. Authro: Li ZhangACM/ICPC World Finals Warm-up Contest(Occidental) 2002. Problem D. The Grand Dinner. Author: Rezaul Alam Chow UVA Monthly Contest. Problem H. The Eagles' Nest. Author: Monirul HasanACM/ICPC Regional Contest Northwestern Europe 2002. Problem G. Sightseeing tour. Author: Jimmy MårdellCTSC1999. Day 1 Problem 3. HomelandIOI2000 National Training Team Originals. Author: Li ZhangInternet Problem Solving Contest 2001. Problem H. MagicACM/ICPC Regional Contest Asia-Beijing 2002. Problem G. Machine ScheduleBaltic Olympiad in Informatics 2001. Day 2 Problem 1. KnightCTSC2000. Day 2 Problem 1. Cupid. Author: Fan YangOIBH Reminiscene Programming Contest. Problem H. Hanoi Tower Troubls Again! Author: Rujia LiuCentral European Olympiad in Informatics 2002. Day 2 Problem 2. GuardACM/ICPC World Finals 2001. Problem G. Fixed Partition Memory ManagementCTSC2002. Day 1 Problem 3. Toy. Author: Rujia LiuCTSC2003. Day 1 Problem 3. Ceremony. Author: Rujia LiuACM/ICPC Regional Contest Mid-Central North America 1996. Problem B. The doorACM/ICPC Regional Contest Central Europe 1995. Problem D. Pipe(Classic)(Classic)(Classic)ACM/ICPC Regioanl Warmup 2001. Problem F. Smallest Bounding Rectangle. Author: Rezaul Alam ChowdhuryACM/ICPC World Finals Warm-up Contest(Occidental) 2002. Problem K. The Great Divide. Author: Rezaul Alam Chow ACM/ICPC Regional Contest Central Europe 1996. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 1997. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 1998. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 1999. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 2000. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 2001. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 2002. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 2003. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 2004. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 2005. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 2006. Problem A. Tin CutterACM/ICPC Regional Contest Central Europe 2007. Problem A. Tin Cutterdata submit how2submit n ny y uva303n nn nn ny y ural1188 y y uva757n y uva239y ny nn y ural1088 y nn ny ny y ural1184 y ny y uva120n y ural1082 y y uva177n y ural1181 y nn ny nn ny ny y uva514n y uva239y ny nn y ural1088 y ny ny nn y uva258n ny ny y ural1184 y ny y uva120n y ural1082 y ny y zju1388y ny ny ny nn ny ny ny y uva10273 y nn ny ny ny nn ny y ural1183y ny nn ny ny y uva10559y ny y zju1022y ny nn nn y ural1143n ny ny ny y uva10531y nn nn nn y uva10534(slightly modified) n y uva10304y ny nn ny y uva656n y uva704n ny ny y uva751y ny y uva140y y uva307y ny ny ny ny nn y ural1155n y ural1170y nn y ural1130y ny nn y ural1095y ny y uva10164n y uva10236y yy nn y uva701y nn y ural1107 n y zju1385 y y uva10413 y nn y uva10237 y nn nn ny ny ny y zju1363 n y ural1035 n y ural1129 y nn nn ny ny y zju1391 y nn ny ny ny y zju1384 y nn y ural1128 n ny yy ny ny y zju1420 n y uva10246 y nn nn y uva10381 y ny nn ny nn y uva10249 y y uva10546 y y zju1992 y ny ny ny y zju1364 y ny ny y uva10276 y nn ny y uva10418y ny y uva393 y y uva303 n nn nn nn y uva10173 n y uva10256 y y uva308 y y uva309 y y uva310 y y uva311 y y uva312 y y uva313 y y uva314 y y uva315 y y uva316 y y uva317 y y uva318 y y uva319。
acm编程比赛入门题目集
程序设计比赛试题主办方:迅翔计算机协会最少钱币数:【问题描述】这是一个古老而又经典的问题。
用给定的几种钱币凑成某个钱数,一般而言有多种方式。
例如:给定了6种钱币面值为2、5、10、20、50、100,用来凑15元,可以用5个2元、1个5元,或者3个5元,或者1个5元、1个10元,等等。
显然,最少需要2个钱币才能凑成15元。
你的任务就是,给定若干个互不相同的钱币面值,编程计算,最少需要多少个钱币才能凑成某个给出的钱数。
【要求】【数据输入】输入可以有多个测试用例。
每个测试用例的第一行是待凑的钱数值M(1 <= M <= 2000,整数),接着的一行中,第一个整数K(1 <= K <= 10)表示币种个数,随后是K 个互不相同的钱币面值Ki(1 <= Ki <= 1000)。
输入M=0时结束。
【数据输出】每个测试用例输出一行,即凑成钱数值M最少需要的钱币个数。
如果凑钱失败,输出“Impossible”。
你可以假设,每种待凑钱币的数量是无限多的。
【样例输入】156 2 5 10 20 50 10011 2【样例输出】2ImpossibleFeli 的生日礼物【问题描述】Felicia 的生日是11月1日(和Kitty是同一天生的哦)。
于是Feli请来Kitty一起过生日。
Kitty带来了最新款的“Kitty猫”玩具准备送给Feli,不过她说,这份礼物可不是白送的。
Feli要帮她一个忙,才能够得到心仪已久的玩具。
Kitty说,“Kitty猫”玩具已经卖出了n!个,n<=10^100 *_*,Kitty想知道确切的数字,而不是无聊的“一个数加个感叹号”。
Feli 听了大吃一惊。
要知道,算出n!是一个无比艰巨的任务。
Feli告诉Kitty,就算Feli算出n!,Kitty也看不下去,因为当n=20 时,计算机的长整型已经存不下了(Kitty只能接受1-9之间的数字)。
ACM题目分类
(1)串 (poj1035,poj3080,poj1936)
(2)排序(快排、归并排(与逆序数有关)、堆排) (poj2388,poj2299)
(3)简单并查集的应用.
(4)哈希表和二分查找等高效查找法(数的Hash,串的Hash)
(3)点集最小圆覆盖.
(4)对踵点(poj2079)
八.综合题.
(poj3109,poj1478,poj1462,poj2729,poj2048,poj3336,poj3315,poj2148,poj1263)
同时由于个人练习的时候可能有些偏向性,可能上面的总结不是很全,还请大家提出和指正,而且由于ACM的题目中专门针对某个算法的题目可能比较少出现,所以上面的分类中的题有可能有多种解法或者是一些算法的综合,这都不会影响大家做题,希望练习的同学能够认真,扎实地训练,做到真正的理解算法,掌握算法. 同时在论坛上还有许多前辈的分类,总结,大家也可以按自己的情况采用.注意FTP上有很多的资料,希望大家好好地利用.
目的). (poj2823)
(4)左偏树(可合并堆).
(5)后缀树(非常有用的数据结构,也是赛区考题的热点).
(poj3415,poj3294)
四.搜索
(1)较麻烦的搜索题目训练(poj1069,poj3322,poj1475,poj1924,poj2049,poj3426)
(5)杂题.
(poj1870,poj3296,poj3286,poj1095)
七.计算几何学.
(1)坐标离散化.
(2)扫描线算法(例如求矩形的面积和周长并,常和线段树或堆一起使用).
(poj1765,poj1177,poj1151,poj3277,poj2280,poj3004)
acm训练资料(浙大模板)
1、几何1.1 注意 (4)1.2 几何公式 (4)1.3 多边形 (6)1.4 多边形切割 (9)1.5 浮点函数 (10)1.6 面积 (15)1.7 球面 (16)1.8 三角形 (17)1.9 三维几何 (19)1.10 凸包 (26)1.11 网格 (28)1.12 圆 (29)1.13 整数函数 (30)2、组合2.1 组合公式 (33)2.2 排列组合生成 (33)2.3 生成gray码 (35)2.4 置换(polya) (35)2.5 字典序全排列 (36)2.6 字典序组合 (36)3、结构3.1 并查集 (37)3.2 堆 (38)3.3 线段树 (39)3.4 子段和 (44)3.5 子阵和 (44)4、数论4.1 阶乘最后非0位 (45)4.2 模线性方程组 (46)4.3 素数 (47)4.4 欧拉函数 (48)5、数值计算5.1 定积分计算(Romberg) (49)5.2 多项式求根(牛顿法) (51)5.3 周期性方程(追赶法) (52)6、图论—NP搜索6.1 最大团 (53)6.2 最大团(n<64)(faster) (54)7、图论—连通性7.1 无向图关键点(dfs邻接阵) (56)7.2 无向图关键边(dfs邻接阵) (57)7.3 无向图的块(bfs邻接阵) (58)7.4 无向图连通分支(dfs/bfs邻接阵) (59)7.5 有向图强连通分支(dfs/bfs邻接阵) (60)7.6 有向图最小点基(邻接阵) (61)8、图论—匹配8.1 二分图最大匹配(hungary邻接表) (62)8.2 二分图最大匹配(hungary邻接阵) (63)8.3 二分图最大匹配(hungary正向表) (63)8.4二分图最佳匹配(kuhn_munkras邻接阵) (64)8.5 一般图匹配(邻接表) (65)8.6 一般图匹配(邻接阵) (66)8.7 一般图匹配(正向表) (66)9、图论—网络流9.1 最大流(邻接阵) (67)9.2 上下界最大流(邻接阵) (68)9.3 上下界最小流(邻接阵) (69)9.4 最大流无流量(邻接阵) (70)9.5 最小费用最大流(邻接阵) (70)10、图论—应用10.1 欧拉回路(邻接阵) (71)10.2 树的前序表转化 (72)10.3 树的优化算法 (73)10.4 拓扑排序(邻接阵) (74)10.5 最佳边割集 (75)10.6 最佳点割集 (76)10.7 最小边割集 (77)10.8 最小点割集 (78)10.9 最小路径覆盖 (80)11、图论—支撑树11.1 最小生成树(kruskal邻接表) (80)11.2 最小生成树(kruskal正向表) (82)11.3 最小生成树(prim+binary_heap邻接表) (83)11.4 最小生成树(prim+binary_heap正向表) (84)11.5 最小生成树(prim+mapped_heap邻接表) (85)11.6 最小生成树(prim+mapped_heap正向表) (87)11.7 最小生成树(prim邻接阵) (88)11.8 最小树形图(邻接阵) (88)12、图论—最短路径12.1 最短路径(单源bellman_ford邻接阵) (90)12.2 最短路径(单源dijkstra+bfs邻接表) (90)12.3 最短路径(单源dijkstra+bfs正向表) (91)12.4 最短路径(单源dijkstra+binary_heap邻接表) (92)12.5 最短路径(单源dijkstra+binary_heap正向表) (93)12.6 最短路径(单源dijkstra+mapped_heap邻接表) (94)12.7 最短路径(单源dijkstra+mapped_heap正向表) (95)12.8 最短路径(单源dijkstra邻接阵) (96)12.9 最短路径(多源floyd_warshall邻接阵) (97)13、应用13.1 Joseph问题 (97)13.2 N皇后构造解 (98)13.3 布尔母函数 (99)13.4 第k元素 (99)13.5 幻方构造 (100)13.6 模式匹配(kmp) (101)13.7 逆序对数 (102)13.8 字符串最小表示 (102)13.9 最长公共单调子序列 (103)13.10 最长子序列 (104)13.11 最大子串匹配 (105)13.12 最大子段和 (106)13.13 最大子阵和 (106)14、其它14.1 大数(只能处理正数) (107)14.2 分数 (113)14.3 矩阵 (115)14.4 线性方程组 (117)14.5 线性相关 (119)14.6 日期 (120)1、几何1.1注意1. 注意舍入方式(0.5的舍入方向);防止输出-0.2. 几何题注意多测试不对称数据.3. 整数几何注意xmult和dmult是否会出界;符点几何注意eps的使用.4. 避免使用斜率;注意除数是否会为0.5. 公式一定要化简后再代入.6. 判断同一个2*PI域内两角度差应该是abs(a1-a2)<beta||abs(a1-a2)>pi+pi-beta;相等应该是abs(a1-a2)<eps||abs(a1-a2)>pi+pi-eps;7. 需要的话尽量使用atan2,注意:atan2(0,0)=0,atan2(1,0)=pi/2,atan2(-1,0)=-pi/2,atan2(0,1)=0,atan2(0,-1)=pi.8. cross product = |u|*|v|*sin(a)dot product = |u|*|v|*cos(a)9. (P1-P0)x(P2-P0)结果的意义:正: <P0,P1>在<P0,P2>顺时针(0,pi)内负: <P0,P1>在<P0,P2>逆时针(0,pi)内0 : <P0,P1>,<P0,P2>共线,夹角为0或pi10. 误差限缺省使用1e-8!1.2几何公式三角形:1. 半周长P=(a+b+c)/22. 面积S=aHa/2=absin(C)/2=sqrt(P(P-a)(P-b)(P-c))3. 中线Ma=sqrt(2(b^2+c^2)-a^2)/2=sqrt(b^2+c^2+2bccos(A))/24. 角平分线Ta=sqrt(bc((b+c)^2-a^2))/(b+c)=2bccos(A/2)/(b+c)5. 高线Ha=bsin(C)=csin(B)=sqrt(b^2-((a^2+b^2-c^2)/(2a))^2)6. 内切圆半径r=S/P=asin(B/2)sin(C/2)/sin((B+C)/2)=4Rsin(A/2)sin(B/2)sin(C/2)=sqrt((P-a)(P-b)(P-c)/P)=Ptan(A/2)tan(B/2)tan(C/2)7. 外接圆半径R=abc/(4S)=a/(2sin(A))=b/(2sin(B))=c/(2sin(C))四边形:D1,D2为对角线,M对角线中点连线,A为对角线夹角1. a^2+b^2+c^2+d^2=D1^2+D2^2+4M^22. S=D1D2sin(A)/2(以下对圆的内接四边形)3. ac+bd=D1D24. S=sqrt((P-a)(P-b)(P-c)(P-d)),P为半周长正n边形:R为外接圆半径,r为内切圆半径1. 中心角A=2PI/n2. 内角C=(n-2)PI/n3. 边长a=2sqrt(R^2-r^2)=2Rsin(A/2)=2rtan(A/2)4. 面积S=nar/2=nr^2tan(A/2)=nR^2sin(A)/2=na^2/(4tan(A/2))圆:1. 弧长l=rA2. 弦长a=2sqrt(2hr-h^2)=2rsin(A/2)3. 弓形高h=r-sqrt(r^2-a^2/4)=r(1-cos(A/2))=atan(A/4)/24. 扇形面积S1=rl/2=r^2A/25. 弓形面积S2=(rl-a(r-h))/2=r^2(A-sin(A))/2棱柱:1. 体积V=Ah,A为底面积,h为高2. 侧面积S=lp,l为棱长,p为直截面周长3. 全面积T=S+2A棱锥:1. 体积V=Ah/3,A为底面积,h为高(以下对正棱锥)2. 侧面积S=lp/2,l为斜高,p为底面周长3. 全面积T=S+A棱台:1. 体积V=(A1+A2+sqrt(A1A2))h/3,A1.A2为上下底面积,h为高(以下为正棱台)2. 侧面积S=(p1+p2)l/2,p1.p2为上下底面周长,l为斜高3. 全面积T=S+A1+A2圆柱:1. 侧面积S=2PIrh2. 全面积T=2PIr(h+r)3. 体积V=PIr^2h圆锥:1. 母线l=sqrt(h^2+r^2)2. 侧面积S=PIrl3. 全面积T=PIr(l+r)4. 体积V=PIr^2h/3圆台:1. 母线l=sqrt(h^2+(r1-r2)^2)2. 侧面积S=PI(r1+r2)l3. 全面积T=PIr1(l+r1)+PIr2(l+r2)4. 体积V=PI(r1^2+r2^2+r1r2)h/3球:1. 全面积T=4PIr^22. 体积V=4PIr^3/3球台:1. 侧面积S=2PIrh2. 全面积T=PI(2rh+r1^2+r2^2)3. 体积V=PIh(3(r1^2+r2^2)+h^2)/6球扇形:1. 全面积T=PIr(2h+r0),h为球冠高,r0为球冠底面半径2. 体积V=2PIr^2h/31.3多边形#include <stdlib.h>#include <math.h>#define MAXN 1000#define offset 10000#define eps 1e-8#define zero(x) (((x)>0?(x):-(x))<eps)#define _sign(x) ((x)>eps?1:((x)<-eps?2:0))struct point{double x,y;};struct line{point a,b;};double xmult(point p1,point p2,point p0){return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}//判定凸多边形,顶点按顺时针或逆时针给出,允许相邻边共线int is_convex(int n,point* p){int i,s[3]={1,1,1};for (i=0;i<n&&s[1]|s[2];i++)s[_sign(xmult(p[(i+1)%n],p[(i+2)%n],p[i]))]=0;return s[1]|s[2];}//判定凸多边形,顶点按顺时针或逆时针给出,不允许相邻边共线int is_convex_v2(int n,point* p){int i,s[3]={1,1,1};for (i=0;i<n&&s[0]&&s[1]|s[2];i++)s[_sign(xmult(p[(i+1)%n],p[(i+2)%n],p[i]))]=0;return s[0]&&s[1]|s[2];}//判点在凸多边形内或多边形边上,顶点按顺时针或逆时针给出int inside_convex(point q,int n,point* p){int i,s[3]={1,1,1};for (i=0;i<n&&s[1]|s[2];i++)s[_sign(xmult(p[(i+1)%n],q,p[i]))]=0;return s[1]|s[2];}//判点在凸多边形内,顶点按顺时针或逆时针给出,在多边形边上返回0int inside_convex_v2(point q,int n,point* p){int i,s[3]={1,1,1};for (i=0;i<n&&s[0]&&s[1]|s[2];i++)s[_sign(xmult(p[(i+1)%n],q,p[i]))]=0;return s[0]&&s[1]|s[2];}//判点在任意多边形内,顶点按顺时针或逆时针给出//on_edge表示点在多边形边上时的返回值,offset为多边形坐标上限int inside_polygon(point q,int n,point* p,int on_edge=1){point q2;int i=0,count;while (i<n)for (count=i=0,q2.x=rand()+offset,q2.y=rand()+offset;i<n;i++)if(zero(xmult(q,p[i],p[(i+1)%n]))&&(p[i].x-q.x)*(p[(i+1)%n].x-q.x)<eps&&(p[i].y-q.y)*(p[(i+1)% n].y-q.y)<eps)return on_edge;else if (zero(xmult(q,q2,p[i])))break;else if (xmult(q,p[i],q2)*xmult(q,p[(i+1)%n],q2)<-eps&&xmult(p[i],q,p[(i+1)%n])*xmult(p[i],q2,p[(i+1) %n])<-eps)count++;return count&1;}inline int opposite_side(point p1,point p2,point l1,point l2){return xmult(l1,p1,l2)*xmult(l1,p2,l2)<-eps;}inline int dot_online_in(point p,point l1,point l2){return zero(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;}//判线段在任意多边形内,顶点按顺时针或逆时针给出,与边界相交返回1int inside_polygon(point l1,point l2,int n,point* p){point t[MAXN],tt;int i,j,k=0;if (!inside_polygon(l1,n,p)||!inside_polygon(l2,n,p))return 0;for (i=0;i<n;i++)if (opposite_side(l1,l2,p[i],p[(i+1)%n])&&opposite_side(p[i],p[(i+1)%n],l1,l2)) return 0;else if (dot_online_in(l1,p[i],p[(i+1)%n]))t[k++]=l1;else if (dot_online_in(l2,p[i],p[(i+1)%n]))t[k++]=l2;else if (dot_online_in(p[i],l1,l2))t[k++]=p[i];for (i=0;i<k;i++)for (j=i+1;j<k;j++){tt.x=(t[i].x+t[j].x)/2;tt.y=(t[i].y+t[j].y)/2;if (!inside_polygon(tt,n,p))return 0;}return 1;}point intersection(line u,line v){point ret=u.a;double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x)) /((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));ret.x+=(u.b.x-u.a.x)*t;ret.y+=(u.b.y-u.a.y)*t;return ret;}point barycenter(point a,point b,point c){line u,v;u.a.x=(a.x+b.x)/2;u.a.y=(a.y+b.y)/2;u.b=c;v.a.x=(a.x+c.x)/2;v.a.y=(a.y+c.y)/2;v.b=b;return intersection(u,v);}//多边形重心point barycenter(int n,point* p){point ret,t;double t1=0,t2;int i;ret.x=ret.y=0;for (i=1;i<n-1;i++)if (fabs(t2=xmult(p[0],p[i],p[i+1]))>eps){t=barycenter(p[0],p[i],p[i+1]);ret.x+=t.x*t2;ret.y+=t.y*t2;t1+=t2;}if (fabs(t1)>eps)ret.x/=t1,ret.y/=t1;return ret;}1.4多边形切割//多边形切割//可用于半平面交#define MAXN 100#define eps 1e-8#define zero(x) (((x)>0?(x):-(x))<eps)struct point{double x,y;};double xmult(point p1,point p2,point p0){return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}int same_side(point p1,point p2,point l1,point l2){return xmult(l1,p1,l2)*xmult(l1,p2,l2)>eps;}point intersection(point u1,point u2,point v1,point v2){point ret=u1;double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));ret.x+=(u2.x-u1.x)*t;ret.y+=(u2.y-u1.y)*t;return ret;}//将多边形沿l1,l2确定的直线切割在side侧切割,保证l1,l2,side不共线void polygon_cut(int& n,point* p,point l1,point l2,point side){point pp[100];int m=0,i;for (i=0;i<n;i++){if (same_side(p[i],side,l1,l2))pp[m++]=p[i];if(!same_side(p[i],p[(i+1)%n],l1,l2)&&!(zero(xmult(p[i],l1,l2))&&zero(xmult(p[(i+1)%n],l1,l2)))) pp[m++]=intersection(p[i],p[(i+1)%n],l1,l2);}for (n=i=0;i<m;i++)if (!i||!zero(pp[i].x-pp[i-1].x)||!zero(pp[i].y-pp[i-1].y))p[n++]=pp[i];if (zero(p[n-1].x-p[0].x)&&zero(p[n-1].y-p[0].y))n--;if (n<3)n=0;}1.5浮点函数//浮点几何函数库#include <math.h>#define eps 1e-8#define zero(x) (((x)>0?(x):-(x))<eps)struct point{double x,y;};struct line{point a,b;};//计算cross product (P1-P0)x(P2-P0)double xmult(point p1,point p2,point p0){return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}double xmult(double x1,double y1,double x2,double y2,double x0,double y0){ return (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);}//计算dot product (P1-P0).(P2-P0)double dmult(point p1,point p2,point p0){return (p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y);}double dmult(double x1,double y1,double x2,double y2,double x0,double y0){ return (x1-x0)*(x2-x0)+(y1-y0)*(y2-y0);}//两点距离double distance(point p1,point p2){return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}double distance(double x1,double y1,double x2,double y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}//判三点共线int dots_inline(point p1,point p2,point p3){return zero(xmult(p1,p2,p3));}int dots_inline(double x1,double y1,double x2,double y2,double x3,double y3){ return zero(xmult(x1,y1,x2,y2,x3,y3));}//判点是否在线段上,包括端点int dot_online_in(point p,line l){return zero(xmult(p,l.a,l.b))&&(l.a.x-p.x)*(l.b.x-p.x)<eps&&(l.a.y-p.y)*(l.b.y-p.y)<eps; }int dot_online_in(point p,point l1,point l2){return zero(xmult(p,l1,l2))&&(l1.x-p.x)*(l2.x-p.x)<eps&&(l1.y-p.y)*(l2.y-p.y)<eps;}int dot_online_in(double x,double y,double x1,double y1,double x2,double y2){return zero(xmult(x,y,x1,y1,x2,y2))&&(x1-x)*(x2-x)<eps&&(y1-y)*(y2-y)<eps;}//判点是否在线段上,不包括端点int dot_online_ex(point p,line l){returndot_online_in(p,l)&&(!zero(p.x-l.a.x)||!zero(p.y-l.a.y))&&(!zero(p.x-l.b.x)||!zero(p.y-l.b.y)); }int dot_online_ex(point p,point l1,point l2){returndot_online_in(p,l1,l2)&&(!zero(p.x-l1.x)||!zero(p.y-l1.y))&&(!zero(p.x-l2.x)||!zero(p.y-l2.y)); }int dot_online_ex(double x,double y,double x1,double y1,double x2,double y2){ returndot_online_in(x,y,x1,y1,x2,y2)&&(!zero(x-x1)||!zero(y-y1))&&(!zero(x-x2)||!zero(y-y2));}//判两点在线段同侧,点在线段上返回0int same_side(point p1,point p2,line l){return xmult(l.a,p1,l.b)*xmult(l.a,p2,l.b)>eps;}int same_side(point p1,point p2,point l1,point l2){return xmult(l1,p1,l2)*xmult(l1,p2,l2)>eps;}//判两点在线段异侧,点在线段上返回0int opposite_side(point p1,point p2,line l){return xmult(l.a,p1,l.b)*xmult(l.a,p2,l.b)<-eps;}int opposite_side(point p1,point p2,point l1,point l2){return xmult(l1,p1,l2)*xmult(l1,p2,l2)<-eps;}//判两直线平行int parallel(line u,line v){return zero((u.a.x-u.b.x)*(v.a.y-v.b.y)-(v.a.x-v.b.x)*(u.a.y-u.b.y));}int parallel(point u1,point u2,point v1,point v2){return zero((u1.x-u2.x)*(v1.y-v2.y)-(v1.x-v2.x)*(u1.y-u2.y));}//判两直线垂直int perpendicular(line u,line v){return zero((u.a.x-u.b.x)*(v.a.x-v.b.x)+(u.a.y-u.b.y)*(v.a.y-v.b.y));int perpendicular(point u1,point u2,point v1,point v2){return zero((u1.x-u2.x)*(v1.x-v2.x)+(u1.y-u2.y)*(v1.y-v2.y));}//判两线段相交,包括端点和部分重合int intersect_in(line u,line v){if (!dots_inline(u.a,u.b,v.a)||!dots_inline(u.a,u.b,v.b))return !same_side(u.a,u.b,v)&&!same_side(v.a,v.b,u);return dot_online_in(u.a,v)||dot_online_in(u.b,v)||dot_online_in(v.a,u)||dot_online_in(v.b,u); }int intersect_in(point u1,point u2,point v1,point v2){if (!dots_inline(u1,u2,v1)||!dots_inline(u1,u2,v2))return !same_side(u1,u2,v1,v2)&&!same_side(v1,v2,u1,u2);returndot_online_in(u1,v1,v2)||dot_online_in(u2,v1,v2)||dot_online_in(v1,u1,u2)||dot_online_in(v2,u1,u 2);}//判两线段相交,不包括端点和部分重合int intersect_ex(line u,line v){return opposite_side(u.a,u.b,v)&&opposite_side(v.a,v.b,u);}int intersect_ex(point u1,point u2,point v1,point v2){return opposite_side(u1,u2,v1,v2)&&opposite_side(v1,v2,u1,u2);}//计算两直线交点,注意事先判断直线是否平行!//线段交点请另外判线段相交(同时还是要判断是否平行!)point intersection(line u,line v){point ret=u.a;double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));ret.x+=(u.b.x-u.a.x)*t;ret.y+=(u.b.y-u.a.y)*t;return ret;}point intersection(point u1,point u2,point v1,point v2){point ret=u1;double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));ret.x+=(u2.x-u1.x)*t;ret.y+=(u2.y-u1.y)*t;return ret;//点到直线上的最近点point ptoline(point p,line l){point t=p;t.x+=l.a.y-l.b.y,t.y+=l.b.x-l.a.x;return intersection(p,t,l.a,l.b);}point ptoline(point p,point l1,point l2){point t=p;t.x+=l1.y-l2.y,t.y+=l2.x-l1.x;return intersection(p,t,l1,l2);}//点到直线距离double disptoline(point p,line l){return fabs(xmult(p,l.a,l.b))/distance(l.a,l.b);}double disptoline(point p,point l1,point l2){return fabs(xmult(p,l1,l2))/distance(l1,l2);}double disptoline(double x,double y,double x1,double y1,double x2,double y2){ return fabs(xmult(x,y,x1,y1,x2,y2))/distance(x1,y1,x2,y2);}//点到线段上的最近点point ptoseg(point p,line l){point t=p;t.x+=l.a.y-l.b.y,t.y+=l.b.x-l.a.x;if (xmult(l.a,t,p)*xmult(l.b,t,p)>eps)return distance(p,l.a)<distance(p,l.b)?l.a:l.b;return intersection(p,t,l.a,l.b);}point ptoseg(point p,point l1,point l2){point t=p;t.x+=l1.y-l2.y,t.y+=l2.x-l1.x;if (xmult(l1,t,p)*xmult(l2,t,p)>eps)return distance(p,l1)<distance(p,l2)?l1:l2;return intersection(p,t,l1,l2);}//点到线段距离double disptoseg(point p,line l){point t=p;t.x+=l.a.y-l.b.y,t.y+=l.b.x-l.a.x;if (xmult(l.a,t,p)*xmult(l.b,t,p)>eps)return distance(p,l.a)<distance(p,l.b)?distance(p,l.a):distance(p,l.b);return fabs(xmult(p,l.a,l.b))/distance(l.a,l.b);}double disptoseg(point p,point l1,point l2){point t=p;t.x+=l1.y-l2.y,t.y+=l2.x-l1.x;if (xmult(l1,t,p)*xmult(l2,t,p)>eps)return distance(p,l1)<distance(p,l2)?distance(p,l1):distance(p,l2);return fabs(xmult(p,l1,l2))/distance(l1,l2);}//矢量V以P为顶点逆时针旋转angle并放大scale倍point rotate(point v,point p,double angle,double scale){point ret=p;v.x-=p.x,v.y-=p.y;p.x=scale*cos(angle);p.y=scale*sin(angle);ret.x+=v.x*p.x-v.y*p.y;ret.y+=v.x*p.y+v.y*p.x;return ret;}1.6面积#include <math.h>struct point{double x,y;};//计算cross product (P1-P0)x(P2-P0)double xmult(point p1,point p2,point p0){return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}double xmult(double x1,double y1,double x2,double y2,double x0,double y0){ return (x1-x0)*(y2-y0)-(x2-x0)*(y1-y0);}//计算三角形面积,输入三顶点double area_triangle(point p1,point p2,point p3){return fabs(xmult(p1,p2,p3))/2;}double area_triangle(double x1,double y1,double x2,double y2,double x3,double y3){ return fabs(xmult(x1,y1,x2,y2,x3,y3))/2;}//计算三角形面积,输入三边长double area_triangle(double a,double b,double c){double s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}//计算多边形面积,顶点按顺时针或逆时针给出double area_polygon(int n,point* p){double s1=0,s2=0;int i;for (i=0;i<n;i++)s1+=p[(i+1)%n].y*p[i].x,s2+=p[(i+1)%n].y*p[(i+2)%n].x;return fabs(s1-s2)/2;}1.7球面#include <math.h>const double pi=acos(-1);//计算圆心角lat表示纬度,-90<=w<=90,lng表示经度//返回两点所在大圆劣弧对应圆心角,0<=angle<=pidouble angle(double lng1,double lat1,double lng2,double lat2){ double dlng=fabs(lng1-lng2)*pi/180;while (dlng>=pi+pi)dlng-=pi+pi;if (dlng>pi)dlng=pi+pi-dlng;lat1*=pi/180,lat2*=pi/180;return acos(cos(lat1)*cos(lat2)*cos(dlng)+sin(lat1)*sin(lat2));}//计算距离,r为球半径double line_dist(double r,double lng1,double lat1,double lng2,double lat2){ double dlng=fabs(lng1-lng2)*pi/180;while (dlng>=pi+pi)dlng-=pi+pi;if (dlng>pi)dlng=pi+pi-dlng;lat1*=pi/180,lat2*=pi/180;return r*sqrt(2-2*(cos(lat1)*cos(lat2)*cos(dlng)+sin(lat1)*sin(lat2))); }//计算球面距离,r为球半径inline double sphere_dist(double r,double lng1,double lat1,double lng2,double lat2){ return r*angle(lng1,lat1,lng2,lat2);}1.8三角形#include <math.h>struct point{double x,y;};struct line{point a,b;};double distance(point p1,point p2){return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}point intersection(line u,line v){point ret=u.a;double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));ret.x+=(u.b.x-u.a.x)*t;ret.y+=(u.b.y-u.a.y)*t;return ret;}//外心point circumcenter(point a,point b,point c){line u,v;u.a.x=(a.x+b.x)/2;u.a.y=(a.y+b.y)/2;u.b.x=u.a.x-a.y+b.y;u.b.y=u.a.y+a.x-b.x;v.a.x=(a.x+c.x)/2;v.a.y=(a.y+c.y)/2;v.b.x=v.a.x-a.y+c.y;v.b.y=v.a.y+a.x-c.x;return intersection(u,v);}//内心point incenter(point a,point b,point c){line u,v;double m,n;u.a=a;m=atan2(b.y-a.y,b.x-a.x);n=atan2(c.y-a.y,c.x-a.x);u.b.x=u.a.x+cos((m+n)/2);u.b.y=u.a.y+sin((m+n)/2);v.a=b;m=atan2(a.y-b.y,a.x-b.x);n=atan2(c.y-b.y,c.x-b.x);v.b.x=v.a.x+cos((m+n)/2);v.b.y=v.a.y+sin((m+n)/2);return intersection(u,v);}//垂心point perpencenter(point a,point b,point c){line u,v;u.a=c;u.b.x=u.a.x-a.y+b.y;u.b.y=u.a.y+a.x-b.x;v.a=b;v.b.x=v.a.x-a.y+c.y;v.b.y=v.a.y+a.x-c.x;return intersection(u,v);}//重心//到三角形三顶点距离的平方和最小的点//三角形内到三边距离之积最大的点point barycenter(point a,point b,point c){line u,v;u.a.x=(a.x+b.x)/2;u.a.y=(a.y+b.y)/2;u.b=c;v.a.x=(a.x+c.x)/2;v.a.y=(a.y+c.y)/2;v.b=b;return intersection(u,v);}//费马点//到三角形三顶点距离之和最小的点point fermentpoint(point a,point b,point c){point u,v;double step=fabs(a.x)+fabs(a.y)+fabs(b.x)+fabs(b.y)+fabs(c.x)+fabs(c.y);int i,j,k;u.x=(a.x+b.x+c.x)/3;u.y=(a.y+b.y+c.y)/3;while (step>1e-10)for (k=0;k<10;step/=2,k++)for (i=-1;i<=1;i++)for (j=-1;j<=1;j++){v.x=u.x+step*i;v.y=u.y+step*j;if(distance(u,a)+distance(u,b)+distance(u,c)>distance(v,a)+distance(v,b)+distance(v,c))u=v;}return u;}1.9三维几何//三维几何函数库#include <math.h>#define eps 1e-8#define zero(x) (((x)>0?(x):-(x))<eps)struct point3{double x,y,z;};struct line3{point3 a,b;};struct plane3{point3 a,b,c;};//计算cross product U x Vpoint3 xmult(point3 u,point3 v){point3 ret;ret.x=u.y*v.z-v.y*u.z;ret.y=u.z*v.x-u.x*v.z;ret.z=u.x*v.y-u.y*v.x;return ret;}//计算dot product U . Vdouble dmult(point3 u,point3 v){return u.x*v.x+u.y*v.y+u.z*v.z;}//矢量差U - Vpoint3 subt(point3 u,point3 v){point3 ret;ret.x=u.x-v.x;ret.y=u.y-v.y;ret.z=u.z-v.z;return ret;}//取平面法向量point3 pvec(plane3 s){return xmult(subt(s.a,s.b),subt(s.b,s.c));}point3 pvec(point3 s1,point3 s2,point3 s3){return xmult(subt(s1,s2),subt(s2,s3));}//两点距离,单参数取向量大小double distance(point3 p1,point3 p2){return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z)); }//向量大小double vlen(point3 p){return sqrt(p.x*p.x+p.y*p.y+p.z*p.z);}//判三点共线int dots_inline(point3 p1,point3 p2,point3 p3){return vlen(xmult(subt(p1,p2),subt(p2,p3)))<eps;}//判四点共面int dots_onplane(point3 a,point3 b,point3 c,point3 d){return zero(dmult(pvec(a,b,c),subt(d,a)));}//判点是否在线段上,包括端点和共线int dot_online_in(point3 p,line3 l){return zero(vlen(xmult(subt(p,l.a),subt(p,l.b))))&&(l.a.x-p.x)*(l.b.x-p.x)<eps&& (l.a.y-p.y)*(l.b.y-p.y)<eps&&(l.a.z-p.z)*(l.b.z-p.z)<eps;}int dot_online_in(point3 p,point3 l1,point3 l2){return zero(vlen(xmult(subt(p,l1),subt(p,l2))))&&(l1.x-p.x)*(l2.x-p.x)<eps&& (l1.y-p.y)*(l2.y-p.y)<eps&&(l1.z-p.z)*(l2.z-p.z)<eps;}//判点是否在线段上,不包括端点int dot_online_ex(point3 p,line3 l){return dot_online_in(p,l)&&(!zero(p.x-l.a.x)||!zero(p.y-l.a.y)||!zero(p.z-l.a.z))&&(!zero(p.x-l.b.x)||!zero(p.y-l.b.y)||!zero(p.z-l.b.z));}int dot_online_ex(point3 p,point3 l1,point3 l2){return dot_online_in(p,l1,l2)&&(!zero(p.x-l1.x)||!zero(p.y-l1.y)||!zero(p.z-l1.z))&& (!zero(p.x-l2.x)||!zero(p.y-l2.y)||!zero(p.z-l2.z));}//判点是否在空间三角形上,包括边界,三点共线无意义int dot_inplane_in(point3 p,plane3 s){return zero(vlen(xmult(subt(s.a,s.b),subt(s.a,s.c)))-vlen(xmult(subt(p,s.a),subt(p,s.b)))- vlen(xmult(subt(p,s.b),subt(p,s.c)))-vlen(xmult(subt(p,s.c),subt(p,s.a))));}int dot_inplane_in(point3 p,point3 s1,point3 s2,point3 s3){return zero(vlen(xmult(subt(s1,s2),subt(s1,s3)))-vlen(xmult(subt(p,s1),subt(p,s2)))- vlen(xmult(subt(p,s2),subt(p,s3)))-vlen(xmult(subt(p,s3),subt(p,s1))));}//判点是否在空间三角形上,不包括边界,三点共线无意义int dot_inplane_ex(point3 p,plane3 s){return dot_inplane_in(p,s)&&vlen(xmult(subt(p,s.a),subt(p,s.b)))>eps&&vlen(xmult(subt(p,s.b),subt(p,s.c)))>eps&&vlen(xmult(subt(p,s.c),subt(p,s.a)))>eps; }int dot_inplane_ex(point3 p,point3 s1,point3 s2,point3 s3){return dot_inplane_in(p,s1,s2,s3)&&vlen(xmult(subt(p,s1),subt(p,s2)))>eps&& vlen(xmult(subt(p,s2),subt(p,s3)))>eps&&vlen(xmult(subt(p,s3),subt(p,s1)))>eps; }//判两点在线段同侧,点在线段上返回0,不共面无意义int same_side(point3 p1,point3 p2,line3 l){return dmult(xmult(subt(l.a,l.b),subt(p1,l.b)),xmult(subt(l.a,l.b),subt(p2,l.b)))>eps;}int same_side(point3 p1,point3 p2,point3 l1,point3 l2){return dmult(xmult(subt(l1,l2),subt(p1,l2)),xmult(subt(l1,l2),subt(p2,l2)))>eps;}//判两点在线段异侧,点在线段上返回0,不共面无意义int opposite_side(point3 p1,point3 p2,line3 l){return dmult(xmult(subt(l.a,l.b),subt(p1,l.b)),xmult(subt(l.a,l.b),subt(p2,l.b)))<-eps;}int opposite_side(point3 p1,point3 p2,point3 l1,point3 l2){return dmult(xmult(subt(l1,l2),subt(p1,l2)),xmult(subt(l1,l2),subt(p2,l2)))<-eps;}//判两点在平面同侧,点在平面上返回0int same_side(point3 p1,point3 p2,plane3 s){return dmult(pvec(s),subt(p1,s.a))*dmult(pvec(s),subt(p2,s.a))>eps;}int same_side(point3 p1,point3 p2,point3 s1,point3 s2,point3 s3){return dmult(pvec(s1,s2,s3),subt(p1,s1))*dmult(pvec(s1,s2,s3),subt(p2,s1))>eps; }//判两点在平面异侧,点在平面上返回0int opposite_side(point3 p1,point3 p2,plane3 s){return dmult(pvec(s),subt(p1,s.a))*dmult(pvec(s),subt(p2,s.a))<-eps;}int opposite_side(point3 p1,point3 p2,point3 s1,point3 s2,point3 s3){return dmult(pvec(s1,s2,s3),subt(p1,s1))*dmult(pvec(s1,s2,s3),subt(p2,s1))<-eps; }//判两直线平行int parallel(line3 u,line3 v){return vlen(xmult(subt(u.a,u.b),subt(v.a,v.b)))<eps;}int parallel(point3 u1,point3 u2,point3 v1,point3 v2){return vlen(xmult(subt(u1,u2),subt(v1,v2)))<eps;}//判两平面平行int parallel(plane3 u,plane3 v){return vlen(xmult(pvec(u),pvec(v)))<eps;}int parallel(point3 u1,point3 u2,point3 u3,point3 v1,point3 v2,point3 v3){ return vlen(xmult(pvec(u1,u2,u3),pvec(v1,v2,v3)))<eps;}//判直线与平面平行int parallel(line3 l,plane3 s){return zero(dmult(subt(l.a,l.b),pvec(s)));}int parallel(point3 l1,point3 l2,point3 s1,point3 s2,point3 s3){return zero(dmult(subt(l1,l2),pvec(s1,s2,s3)));}//判两直线垂直int perpendicular(line3 u,line3 v){return zero(dmult(subt(u.a,u.b),subt(v.a,v.b)));}int perpendicular(point3 u1,point3 u2,point3 v1,point3 v2){return zero(dmult(subt(u1,u2),subt(v1,v2)));}//判两平面垂直int perpendicular(plane3 u,plane3 v){return zero(dmult(pvec(u),pvec(v)));}int perpendicular(point3 u1,point3 u2,point3 u3,point3 v1,point3 v2,point3 v3){ return zero(dmult(pvec(u1,u2,u3),pvec(v1,v2,v3)));}//判直线与平面平行int perpendicular(line3 l,plane3 s){return vlen(xmult(subt(l.a,l.b),pvec(s)))<eps;}int perpendicular(point3 l1,point3 l2,point3 s1,point3 s2,point3 s3){return vlen(xmult(subt(l1,l2),pvec(s1,s2,s3)))<eps;}//判两线段相交,包括端点和部分重合int intersect_in(line3 u,line3 v){if (!dots_onplane(u.a,u.b,v.a,v.b))return 0;if (!dots_inline(u.a,u.b,v.a)||!dots_inline(u.a,u.b,v.b))return !same_side(u.a,u.b,v)&&!same_side(v.a,v.b,u);return dot_online_in(u.a,v)||dot_online_in(u.b,v)||dot_online_in(v.a,u)||dot_online_in(v.b,u); }int intersect_in(point3 u1,point3 u2,point3 v1,point3 v2){if (!dots_onplane(u1,u2,v1,v2))return 0;if (!dots_inline(u1,u2,v1)||!dots_inline(u1,u2,v2))return !same_side(u1,u2,v1,v2)&&!same_side(v1,v2,u1,u2);returndot_online_in(u1,v1,v2)||dot_online_in(u2,v1,v2)||dot_online_in(v1,u1,u2)||dot_online_in(v2,u1,u 2);}//判两线段相交,不包括端点和部分重合int intersect_ex(line3 u,line3 v){return dots_onplane(u.a,u.b,v.a,v.b)&&opposite_side(u.a,u.b,v)&&opposite_side(v.a,v.b,u); }int intersect_ex(point3 u1,point3 u2,point3 v1,point3 v2){returndots_onplane(u1,u2,v1,v2)&&opposite_side(u1,u2,v1,v2)&&opposite_side(v1,v2,u1,u2);}//判线段与空间三角形相交,包括交于边界和(部分)包含int intersect_in(line3 l,plane3 s){return !same_side(l.a,l.b,s)&&!same_side(s.a,s.b,l.a,l.b,s.c)&& !same_side(s.b,s.c,l.a,l.b,s.a)&&!same_side(s.c,s.a,l.a,l.b,s.b);}int intersect_in(point3 l1,point3 l2,point3 s1,point3 s2,point3 s3){ return !same_side(l1,l2,s1,s2,s3)&&!same_side(s1,s2,l1,l2,s3)&& !same_side(s2,s3,l1,l2,s1)&&!same_side(s3,s1,l1,l2,s2);}//判线段与空间三角形相交,不包括交于边界和(部分)包含int intersect_ex(line3 l,plane3 s){return opposite_side(l.a,l.b,s)&&opposite_side(s.a,s.b,l.a,l.b,s.c)&& opposite_side(s.b,s.c,l.a,l.b,s.a)&&opposite_side(s.c,s.a,l.a,l.b,s.b); }int intersect_ex(point3 l1,point3 l2,point3 s1,point3 s2,point3 s3){ return opposite_side(l1,l2,s1,s2,s3)&&opposite_side(s1,s2,l1,l2,s3)&& opposite_side(s2,s3,l1,l2,s1)&&opposite_side(s3,s1,l1,l2,s2);}//计算两直线交点,注意事先判断直线是否共面和平行!//线段交点请另外判线段相交(同时还是要判断是否平行!)point3 intersection(line3 u,line3 v){point3 ret=u.a;double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));ret.x+=(u.b.x-u.a.x)*t;ret.y+=(u.b.y-u.a.y)*t;ret.z+=(u.b.z-u.a.z)*t;return ret;}point3 intersection(point3 u1,point3 u2,point3 v1,point3 v2){point3 ret=u1;double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));ret.x+=(u2.x-u1.x)*t;ret.y+=(u2.y-u1.y)*t;ret.z+=(u2.z-u1.z)*t;return ret;}//计算直线与平面交点,注意事先判断是否平行,并保证三点不共线!。
整理出ACM所有题目和答案解析
1000 A + B ProblemProblem DescriptionCalculate A + B.InputEach line will contain two integers A and B. Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2AuthorHDOJ代码:#include<stdio.h>int main(){int a,b;while(scanf("%d %d",&a,&b)!=EOF)printf("%d\n",a+b);}1001 Sum ProblemProblem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.InputThe input will consist of a series of integers n, one integer per line.OutputFor each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.Sample Input1100Sample Output15050AuthorDOOM III解答:#include<stdio.h>main(){int n,i,sum;sum=0;while((scanf("%d",&n)!=-1)){sum=0;for(i=0;i<=n;i++)sum+=i;printf("%d\n\n",sum);}}1002 A + B Problem IIProblem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2112233445566778899 998877665544332211Sample OutputCase 1:1 +2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110AuthorIgnatius.L代码:#include <stdio.h>#include <string.h>int main(){char str1[1001], str2[1001];int t, i, len_str1, len_str2, len_max, num = 1, k; scanf("%d", &t);getchar();while(t--){int a[1001] = {0}, b[1001] = {0}, c[1001] = {0}; scanf("%s", str1);len_str1 = strlen(str1);for(i = 0; i <= len_str1 - 1; ++i)a[i] = str1[len_str1 - 1 - i] - '0';scanf("%s",str2);len_str2 = strlen(str2);for(i = 0; i <= len_str2 - 1; ++i)b[i] = str2[len_str2 - 1 - i] - '0';if(len_str1 > len_str2)len_max = len_str1;elselen_max = len_str2;k = 0;for(i = 0; i <= len_max - 1; ++i){c[i] = (a[i] + b[i] + k) % 10;k = (a[i] + b[i] + k) / 10;}if(k != 0)c[len_max] = 1;printf("Case %d:\n", num);num++;printf("%s + %s = ", str1, str2);if(c[len_max] == 1)printf("1");for(i = len_max - 1; i >= 0; --i){printf("%d", c[i]);}printf("\n");if(t >= 1)printf("\n");}return 0;}1005 Number SequenceProblem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).InputThe input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed.OutputFor each test case, print the value of f(n) on a single line.Sample Input1 1 31 2 100 0 0Sample Output25AuthorCHEN, ShunbaoSourceZJCPC2004RecommendJGShining代码:#include<stdio.h>int f[200];int main(){int a,b,n,i;while(scanf("%d%d%d",&a,&b,&n)&&a&&b&&n) {if(n>=3){f[1]=1;f[2]=1;for(i=3;i<=200;i++){f[i]=(a*f[i-1]+b*f[i-2])%7; if(f[i-1]==1&&f[i]==1)break;}i-=2;n=n%i;if(n==0)printf("%d\n",f[i]);elseprintf("%d\n",f[n]);}elseprintf("1\n");}return 0;}1008 ElevatorProblem DescriptionThe highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.InputThere are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.OutputPrint the total time on a single line for each test case.Sample Input1 23 2 3 1Sample Output1741AuthorZHENG, JianqiangSourceZJCPC2004RecommendJGShining代码:#include<stdio.h>int a[110];int main(){int sum,i,n;while(scanf("%d",&n)&&n!=0){for(i=1;i<=n;i++)scanf("%d",&a[i]);sum=0;a[0]=0;for(i=1;i<=n;i++){if(a[i]>a[i-1])sum+=6*(a[i]-a[i-1]);elsesum+=4*(a[i-1]-a[i]);sum+=5;}printf("%d\n",sum);}return 0;}1009 FatMouse' TradeProblem DescriptionFatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.InputThe input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followedby two -1's. All integers are not greater than 1000.OutputFor each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.Sample Input5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1Sample Output13.333 31.500AuthorCHEN, YueSourceZJCPC2004RecommendJGShining代码:#include<stdio.h>#include<string.h>#define MAX 1000int main(){int i,j,m,n,temp;int J[MAX],F[MAX];double P[MAX];double sum,temp1;scanf("%d%d",&m,&n);while(m!=-1&&n!=-1){sum=0;memset(J,0,MAX*sizeof(int));memset(F,0,MAX*sizeof(int));memset(P,0,MAX*sizeof(double));for(i=0;i<n;i++){ scanf("%d%d",&J[i],&F[i]); P[i]=J[i]*1.0/((double)F[i]); }for(i=0;i<n;i++){for(j=i+1;j<n;j++){if(P[i]<P[j]){temp1=P[i]; P[i]=P[j]; P[j]=temp1;temp=J[i]; J[i]=J[j]; J[j]=temp;temp=F[i]; F[i]=F[j]; F[j]=temp;}}}for(i=0;i<n;i++){if(m<F[i]){ sum+=m/((double)F[i])*J[i]; break; }else { sum+=J[i]; m-=F[i]; }}printf("%.3lf\n",sum); scanf("%d%d",&m,&n);}return 0;}1021 Fibonacci AgainProblem DescriptionThere are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2).InputInput consists of a sequence of lines, each containing an integer n. (n < 1,000,000).OutputPrint the word "yes" if 3 divide evenly into F(n).Print the word "no" if not.Sample Input12345Sample OutputnonoyesnononoAuthorLeojayRecommendJGShining#include<stdio.h>int main(){long n;while(scanf("%ld",&n) != EOF) if (n%8==2 || n%8==6)printf("yes\n");elseprintf("no\n");return 0;}1089 A+B for Input-Output Practice(I)Problem DescriptionYour task is to Calculate a + b.Too easy?! Of course! I specially designed the problem for acm beginners.You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.Sample Input1 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio.h>main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF)printf("%d\n",a+b);}1090 A+B for Input-Output Practice(II)Problem DescriptionYour task is to Calculate a + b.InputInput contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.Sample Input21 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio.h>#define M 1000void main(){int a ,b,n,j[M],i;//printf("please input n:\n");scanf("%d",&n);for(i=0;i<n;i++){scanf("%d%d",&a,&b);//printf("%d %d",a,b);j[i]=a+b;}i=0;while(i<n){printf("%d",j[i]);i++;printf("\n");}}1091 A+B for Input-Output Practice(III)Problem DescriptionYour task is to Calculate a + b.InputInput contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.OutputFor each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.Sample Input1 510 200 0Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio.h>main(){int a,b;scanf("%d %d",&a,&b);while(!(a==0&&b==0)){printf("%d\n",a+b);scanf("%d %d",&a,&b);}}1092 A+B for Input-Output Practice(IV)Problem DescriptionYour task is to Calculate the sum of some integers.InputInput contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.OutputFor each group of input integers you should output their sum in one line, and with one line of output for each line in input.Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecommendJGShining解答:#include <stdio.h>int main(){int n,sum,i,t;while(scanf("%d",&n)!=EOF&&n!=0){sum=0;for(i=0;i<n;i++){scanf("%d",&t);sum=sum+t;}printf("%d\n",sum);}}1093 A+B for Input-Output Practice(V)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.OutputFor each group of input integers you should output their sum in one line, and with one line of output for each line in input.Sample Input24 1 2 3 45 1 2 3 4 5Sample Output1015Authorlcy解答:#include<stdio.h>main(){int n,a,b,i,j,sum;sum=0;while(scanf("%d\n",&n)!=-1){for(i=0;i<n;i++){scanf("%d",&b);for(j=0;j<b;j++){scanf("%d",&a);sum+=a;}printf("%d\n",sum);sum=0;}}}1094 A+B for Input-Output Practice(VI)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.OutputFor each test case you should output the sum of N integers in one line, and with one line of output for each line in input.Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecommendJGShining解答:#include<stdio.h>main(){int n,a,b,i,j,sum;sum=0;while(scanf("%d\n",&n)!=-1){for(j=0;j<n;j++){scanf("%d",&a);sum+=a;}printf("%d\n",sum);sum=0;}}[ Copy to Clipboard ][ Save to File]1095 A+B for Input-Output Practice(VII)Problem DescriptionYour task is to Calculate a + b.InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.OutputFor each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.Sample Input1 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio.h>main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF)printf("%d\n\n",a+b);}1096 A+B for Input-Output Practice(VIII)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.OutputFor each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.Sample Input34 1 2 3 45 1 2 3 4 53 1 2 3Sample Output10156AuthorlcyRecommendJGShining解答:int main(){int a,b,i,j,l[1000],k;scanf("%d",&i);getchar();for(j=1;j<=i;j++)l[j]=0;for(j=1;j<=i;j++){scanf("%d",&a);getchar();for(k=1;k<=a;k++){scanf("%d",&b);getchar();l[j]+=b;}}for(j=1;j<=i-1;j++)printf("%d\n\n",l[j]);printf("%d\n",l[i]);}1176 免费馅饼Problem Description都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。
浙江大学ACM试题解答
}
int main()
{
int tmp,n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
if(m>n)
{
tmp=m ;
m=n ;
n=tmp;
}
flag1=flag2=0;
dfs(n,m,100);
if(flag1||!flag2)
Unfortunately, anyone who is willing to referee a game of crashing balloon is likely to get over-excited in the hot atmosphere that he\she could not reasonably be expected to perform the intricate calculations that refereeing requires. Hence the need for you, sober programmer, to provide a software solution.
--------------------------------------------------------------------------------
Submit Back Status
--------------------------------------------------------------------------------
On the other hand, if one player claims 162 points and the other claims 81, it is possible for both to be telling the truth (e.g. one crashes balloons 2, 3 and 27, while the other crashes balloon 81), so the challenge would not be upheld.
hdoj详细题目ACM分类超级经典题目分类
hdu 题目分类1001 整数求和 水题1002 C 语言实验题——两个数比较 水题1003 1、2、3、4、5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment 猜想 数论:容斥定理1007 童年生活二三事 递推题 1008 University 简单hash 1009 目标柏林 简单模拟题 1010 Rails 模拟题(堆栈) 1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY Huffman 编码1013 STAMPS 搜索or 动态规划 1014 Border 模拟题1015 Simple Arithmetics 高精度计算 1016 Shoot-out 博弈+状态压缩DP 1017 Tour Guide 1018 Card Trick 简单题1019 Necklace Decomposition 贪心1020 Crashing Robots 模拟题1021 Electrical Outlets 简单题 1022 Watchdog 简单题1023 Taxi Cab Scheme 图论:最小路径覆盖--->最大二分匹配1024 Pseudo-random Numbers 数论 1025 Card Game Cheater 简单题 1026 Investment 动态规划 1027 Pipes1028 SETI 数学:高斯消元法1029 Minimax Triangulation 计算几何 1030 Unequalled Consumption 母函数 1031 Declaration of Content 1032 Laserbox 搜索:DFS 1033 Bowlstack 1034 Pesky Heroes1035 Reduced ID Numbers 暴力 1036 Tantrix1037 Guardian of Decency 图论:匈牙利算法求二分图的最大匹配1038 Up the Stairs 简单数学题 1039 Sudoku 搜索:DFS 1040 The SetStack Computer 1041 Pie 二分法1042 Ticket to Ride 动态规划 1043 The Bookcase 动态规划 1044 Printer Queue 模拟题 1045 Prime Path 搜索:BFS1046 Lineland's Airport 1047 Leonardo's Notebook 数学题:群置换 1048 简易版最长序列 简单题 1049 Jesse's problem 搜索:DFS 1050 Error Correction 模拟题 1051 A × B problem 高精度计算 1052 Redraiment 的走法 动态规划 1053 Word Encoding 动态规划 1054 Jesse's Code 组合数学:排列 1055 简单密码破解 水题1056 英文金曲大赛 水题 1057 有假币 水题 1058 寄居蟹与海葵 水题1059 天仙配 水题1060 鹊桥相会 水题 1061 杨辉三角 水题 1062 蟠桃记 水题1063 养兔子 水题 1064 字符统计 水题 1065 完美数 水题 1066 亲和数 水题 1067 成绩评估 水题 1068 找零钱 水题 1069 漂亮菱形 水题 1070 Least Common Multiple 水题 1071 第几天 水题 1072 编辑距离 水题1073 支配值数目 水题 1074 等值数目 水题 1075 两数组最短距离 水题 1076 输入入门(1) 水题 1077 输入入门(2) 水题 1078 输入入门(3) 水题 1079 输出入门 水题1080 Counterfeit Dollar 组合数学 1081 Dividing 动态规划 1082 Sorting It All Out 图论:拓扑排序 1083 False coin 暴力法 1084 File Mapping 1085 Color Me Less 简单题1086 Round and Round We Go 简单题 1087 Microprocessor Simulation 简单题 1088 求奇数的乘积 水题 1089 平方和与立方和 水题1090 绝对值排序 水题 1091 JudgeOnline 水题 1092 More Beautiful 水题 1093 猴子分桃 水题 1094 C 语言实验题——一元二次方程 水题 1095 C 语言实验题——保留字母 水题 1096 C 语言实验题——排列 水题 1097 C 语言实验题——矩阵转置 水题 1098 C 语言实验题——素数 水题1099 Ambiguous permutations 简单题 1100 Home Work 贪心法1101 Redraiment 的遭遇 数学题:找规律 1102 Decorate the wall 搜索or 动态规划 1103 Economic phone calls 动态规划or 贪心 1104 Any fool can do it 记忆化搜索 1105 Wine trading in Gergovia 贪心法 1106 Homogeneous squares 随机算法 1107 Automatic Correction of Misspellings 字符串1108 Black and white painting 简单数学题 1109 Cylinder 计算几何:公式推导 1110 Deli Deli 水题1111 Expressions 数据结构:树的遍历 1112 Flavius Josephus Reloaded 数论:Pollard's R1113 Annoying painting tool 贪心法 1114 Frequent values RMQ 区间最值问题 OR 线段树1115 Anagram Groups 字符串匹配 1116 Let it Bead 组合数学->Polya 定理 1117 Simple Computers 简单题 1118 Mondriaan's Dream 动态规划 1119 Equidistance 计算几何 1120 How many Fibs? 高精度计算 1121 Hike on a Graph 搜索:BFS 1122 ASCII Art 1123 Billing Tables1124 Cellular Automaton 矩阵计算1125 Exchange 1126 Fool's Game 1127 Java vs C++ 字符串处理 1128 Kickdown 字符串处理 1129 Copying Books 贪心+二分法1130 Adding Reversed Numbers 简单题 1131 Glass Beads 字符串的最小表示 1132 The Circumference of the Circle 计算几何题 1133 Knight Moves 搜索:BFS 1134 Eeny Meeny Moo 变形的约瑟夫问题 1135 Lotto 组合数学1136 Humble Numbers 动态规划 1137 Average is not Fast Enough! 简单题 1138 Etaoin Shrdlu 简单题 1139 Hard to Believe, but True! 简单题 1140 Code the Tree 简单题 1141 Fiber Network 图论:全源最短路径,Floyd-Warshall 算法 1142 Global Roaming 3D 几何题 1143 All in All 字符串处理1144 The Sierpinski Fractal 递归 1145 Assistance Required 简单题:预处理 1146 Drink, on Ice 模拟题 1147 All Discs Considered 搜索:BFS 1148 In Danger 模拟题 1149 Run Length Encoding 字符串处理 1150 Bee Maja 模拟题 1151 Friends 表达式求值 1152 John 博弈论 1153 Double Queue 最大堆与最小堆 1154 ‘JBC’1155 Loan Scheduling 贪心+堆 1156 Showstopper 1157 Highway 贪心法 1158 Computers 动态规划 1159 The Stable Marriage Problem 组合数学 1160 Arne Saknussemm 模拟题 1161 Sum Problem 水题 1162 Fire Net 搜索题 1163 统计1到N 之间数字1的个数 推理题 1164 最大公因子 水题1165 C 语言实验题——三个整数 水题 1166 C 语言实验题——大小写转换 水题 1167 C 语言实验题——分数序列 水题 1168 C 语言实验题——最值 水题 1169 C 语言实验题——保留整数 水题 1170 C 语言实验题——矩阵下三角元素之和 水题 1171 C 语言实验题——字符逆序 水题 1172 C 语言实验题——打印菱形 水题 1173 C 语言实验题——分割整数 水题 1174 C 语言实验题——删除指定字符 水题 1175 C 语言实验题——时间间隔 水题 1176 C 语言实验题——数组逆序 水题 1177 C 语言实验题——打印数字图形 水题 1178 C 语言实验题——单词统计 水题 1179 C 语言实验题——最小公倍数和最大公约数 水题 1180 Crashing Balloon 搜索题1181 念数字 模拟题1182 A+B for Input-Output Practice(1) 水题 1183 Anagrams by Stack 搜索:回溯 1184 Elevator 数学:找规律1185 Substrings 字符串处理1186 Calling Extraterrestrial Intelligence Again 搜索:枚举法 1187 Do the Untwist 简单数学题 1188 数字对 水题 1189 A+B for Input-Output Practice (2) 水题 1190 火星A+B 简单题1191 三齿轮问题:三个齿轮啮合 简单数学题 1192 A + B Problem II 高精度计算 1193 The ones to remain 数学题 1194 Chinese Chess 博弈论1195 Page Replacement 数据结构:队列or hash 1196 RSA Signing 数论:Pollard's Rho 算法 1197 Number Guessing 搜索:穷举 1198 求n 的阶乘 高精度计算 1199 Area 计算几何 1200 求两直线的夹角 水题 1201 三角形面积 水题 1202 Max Sum 动态规划 1203 Number Sequence 大数问题1204 u Calculate e 水题 1205 斐波那契数列 高精度计算 1206 Fibonacci Again 大数问题 1207 Let the Balloon Rise 字符串处理 1208 还是A+B 水题1209 A + B 水题1210 The area 简单计算几何1211 Ignatius's puzzle 简单数学问题 1212 Computer Transformation 高精度计算 1213 N! 高精度计算 1217 Text Reverse 水题 1220 填数字游戏 搜索:DFS1221 Tempter of the Bone 搜索:DFS or BFS+剪枝 1226 Last non-zero Digit in N! 数论 1227 三角形 递推求解 1228 回文数猜想 简单题 1229 Factorial 简单题 1230 Specialized Four-Digit Numbers 简单数学题 1231 Lowest Bit 简单题1232 To and Fro 简单题 1233 AC Me 简单题1234 Wolf and Rabbit 数论1235 最大连续子序列 动态规划 1236 开门人和关门人 字符串处理 1237 排名 排序1238 统计难题 字符串处理:字典树1239 Tick and Tick 数学题 1240 Quoit Design 分治法1241 钱币兑换问题 递推求解 1242 求出前m 大的数 简单题 1243 角谷猜想 简单题1244 Reverse Number 简单题1245 寻找素数对 简单题 1246 ZJUTACM 简单题1247 Hat's Fibonacci 高精度计算1248 Encoding 简单题 1249 四数相加 高精度计算 1250 两数相减 高精度计算1251 Square Coins 母函数 1252 Counting Triangles 递推求解 1253 2^x mod n = 1 数论:费尔马小定理 1254 Minimum Inversion Number 简单题 1255 Surround the Trees 计算几何:凸包 1256 Number Steps 简单题 1257 Binary Numbers 简单题 1258 Knight Moves 搜索:BFS 1259 Lotto 组合数学 1260 A Simple Task 简单题 1261 The Drunk Jailer 数论1262 Hanoi Tower Troubles Again! 递推求解 1263 IBM Minus One 水题1264 Definite Values 简单题 1265 Box of Bricks 水题 1266 Perfection 简单题 1267 Reverse Text 水题 1268 Inversion 模拟题1269 Prime Cuts 简单题1270 How Many Fibs? 高精度计算1271 Round and Round We Go 简单题 1272 Red and Black 搜索:DFS 1273 What Day Is It? 简单题1274 String Matching 字符串匹配 1275 A Contesting Decision 简单题 1276 Doubles 简单题 1277 The Snail 简单题1278 Jungle Roads 图论:最小生成树 1279 Prime Ring Problem 搜索:DFS 1280 Big Number 大数问题 1281 Least Common Multiple 简单题 1283 简单排序 水题 1284 Gridland 简单题 1285 An Easy Task 简单题 1286 Calendar Game 模拟题1287 Human Gene Functions 动态规划 1288 计算几何练习题——线段相交 计算几何 1289 计算几何练习题——线段相交II 计算几何 1290 计算几何练习题——直线交点 计算几何 1291 Trees Made to Order 递归求解 1292 排序 简单题 1293 18岁生日 简单题 1294 吃糖果 递推求解 1295 变种汉诺塔 递推求解 1296 洗牌 递推求解 1297 大数求余 数论 1298 圆桌会议 递推求解 1299 畅通工程 并查集 1300 还是畅通工程 最小生成树 1301 统计同成绩学生人数 水题1302 简单计算器 表达式求值:栈的应用 1303 改进版计算器 表达式求值:栈的应用 1304 FatMouse' Trade 贪心法 1305 Digital Roots 大数问题 1306 Uniform Generator 数论 1307 A Mathematical Curiosity 穷举法 1308 Safecracker 穷举法 1309 The 3n + 1 problem 简单题 1310 分享糖果 模拟题 1311 宝物收集 搜索:BFS 1312 Climbing Worm 简单题 1313 搬桌子 贪心法1314 Humble Numbers 动态规划 1315 Dividing 动态规划1316 Rightmost Digit 数学问题 1317 Leftmost Digit 数学问题 1318 Hangover 简单数学问题1319 Exponentiation 高精度计算 1320 I Think I Need a Houseboat 简单题 1321 Girls and Boys DFS+二分图 1322 Monkey and Banana 动态规划 1323 买牛奶 简单题 1324 Matrix Chain Multiplication 数据结构:栈的应用 1325 计算成绩 简单题1326 Holding Bin-Laden Captive! 母函数 1327 You can Solve a Geometry Problem too 计算几何 1328 Super Jumping! Jumping! Jumping! 动态规划 1329 a^b 数论 1330 计算GPA 水题1331 Give me an offer! 动态规划:0-1背包 1332 田忌赛马 贪心法 1333 Asteroids! 搜索:BFS 1334 Oil Deposits 搜索:DFS 1335 营救天使 搜索:BFS 1336 小数化分数 高精度计算 1337 I Hate It 线段树 1338 Strange Billboard 位运算+枚举 1339 Frobenius 递推求解 1340 奇怪的公式 数学题 1341 Fibonacci again and again 博弈论 1342 A New Tetris Game 博弈论 1343 Sum It Up 搜索:DFS 1344 速算24点 搜索 1345 推箱子 搜索:BFS1346 Pushing Boxes 搜索:BFS 1347 The Worm Turns 搜索 1348 Alfredo's Pizza Restaurant 简单题 1349 Broken Keyboard 字符串处理 1350 Convert Kilometers to Miles 简单题 1351 单词数 水题1352 仙人球的残影 简单题 1353 Family planning 简单题1354 Rout 66 简单题 1355 LC-Display 模拟题 1356 A == B ? 高精度计算 1357 不容易系列之一 递推求解 1358 折线分割平面 递推求解1359 find the nth digit 二分查找 1360 奇数阶魔方(II) 简单题 1361 Keep on Truckin' 简单题 1362 Factstone Benchmark 简单题1363 Destroy the Well of Life 模拟题 1365 Brave Game 博弈论 1366 ASCII 码排序 水题 1367 计算两点间的距离 水题1368 计算球体积 水题 1369 求绝对值 水题 1370 数值统计 水题1371 求数列的和 水题1372 水仙花数 水题 1373 多项式求和 水题 1374 素数判定 水题 1375 偶数求和 水题 1376 母牛的故事 水题 1377 数列有序! 水题 1378 发工资咯:) 水题 1379 C 语言合法标识符 水题 1380 海选女主角 水题 1381 查找最大元素 水题 1382 首字母变大写 水题1383 统计元音 水题1384 Palindromes _easy version 水题 1385 汉字统计 水题 1386 进制转换 水题1387 人见人爱A+B 水题 1388 人见人爱A-B 水题 1389 人见人爱A^B 水题 1390 改革春风吹满地 计算几何 1391 今年暑假不AC 动态规划 1392 三角形 水题1393 求平均成绩 水题1394 不容易系列之二 递推求解 1395 密码 水题1396 一只小蜜蜂... 递推求解 1397 不容易系列之(3)—— LELE 的RPG 难题 递推求解1398 骨牌铺方格 递推求解 1399 阿牛的EOF 牛肉串 递推求解 1400 神、上帝以及老天爷 递推求解 1401 不容易系列之(4)——考新郎 递推求解 1402 Bitset 简单题 1403 Picture 简单模拟题1404 Switch Game 找规律1405 An easy problem 简单模拟题 1406 A + B Again 简单题 1407 The sum problem 简单数学题 1408 龟兔赛跑 动态规划 1409 Snooker 简单数学题 1410 Subset sequence 简单题 1411 汉诺塔III 递推求解 1412 "红色病毒"问题 递推求解 1413 小兔的棋盘 递推求解 1414 RPG 的错排 错排+排列组合 1415 无限的路 简单题 1416 夹角有多大 数学题 1417 汉诺塔IV 递推求解 1418 复习时间 简单题 1419 选课时间 暴力求解 1420 手机短号 字符串处理 1421 找单词 母函数1422 简易版之最短距离 数学题 1423 数塔 动态规划 1424 核反应堆 简单题 1425 A1 = ? 公式推导 1426 剪花布条 字符串处理 1427 不要62 数学题 1428 空心三角形 字符串处理 1429 小明A+B 简单题 1430 Sky 数 进制转换 1431 整除的尾数 简单题 1432 分拆素数和 数论 1433 正整数解 数学题 1434 挂盐水 模拟题 1435 {A} + {B} 简单题 1436 小数A+B 高精度计算 1437 Zigzag 简单题 1438 螺旋形 简单题 1439 行李寄存 简单题 1440 判断多边形凹凸 计算几何 1441 The centre of polygon 计算几何 1442 最小正整数 简单题 1443 Elevator Stopping Plan 二分+贪心法 1444 TOYS 计算几何 1445 The Doors 计算几何 1446 Polygon And Segment 计算几何 1447 Fence 计算几何 1448 两圆相交面积 计算几何1449 Area of Circles 计算几何 1450 Pipe 计算几何1451 zero sum 搜索:DFS1452 C 语言实验题——Hello World 水题 1453 C 语言实验题——数日子 水题 1454 C 语言实验题——三个数排序 水题 1455 C 语言实验题——数字串求和 水题 1456 C 语言实验题——拍皮球 水题 1457 C 语言实验题——求一个3*3矩阵对角线元素之和 水题1458 C 语言实验题——数组逆序 水题 1459 C 实验题——求最大值 水题 1460 C 实验题——求绝对值最大值 水题 1461 C 语言实验题——求平均值 水题 1462 C 语言实验题——打印直角三角形 水题 1463 C 语言实验题——相加和最大值 水题 1464 C 语言实验题——简单编码 水题 1465 C 语言实验题——某年某月的天数 水题 1466 C 语言实验题——各位数字之和排序 水题 1467 C 语言实验题——两个数最大 水题 1468 C 语言实验题——求级数值 水题 1469 Pipe II 计算几何 1470 Transmitters 计算几何 1471 Wall 计算几何1472 C 语言实验题——逆置正整数 水题 1473 C 语言实验题——找中间数 水题 1474 C 语言实验题——整数位 水题 1475 C 语言实验题——一元二次方程 II 水题 1476 C 语言实验题——圆周率 水题 1477 C 语言实验题——余弦 水题 1478 C 语言实验题——打印金字塔 水题 1479 C 语言实验题——排序 水题 1480 C 语言实验题——约瑟夫问题 水题 1481 C 语言实验题——鞍点 水题 1482 C 语言实验题——计算表达式 水题 1483 C 语言实验题——汉诺塔 水题 1484 C 语言实验题——字符串排序 水题 1485 C 语言实验题——整除 水题 1486 Solitaire 搜索:(双向)BFS 1487 Abbreviation 水题1488 C 语言实验题——买糖果 水题 1489 C 语言实验题——字符编码 水题 1490 C 语言实验题——合法的C 标识符 水题 1491 C 语言实验题——三角形面积 水题 1492 C 语言实验题——大小写转换 水题 1493 C 语言实验题——圆柱体计算 水题 1494 C 语言实验题——温度转换 水题 1495 C 语言实验题——统计字串 水题1496 C 语言实验题——字符过滤 水题 1497 Coin Change 暴力求解 1498 Beautiful Meadow 搜索题 1499 C 语言实验题——鸡兔同笼 水题 1500 Coins of Luck 数学题:数学期望 1501 Friends 搜索:DFS 1502 Find All M^N Please 数学题 1503 Incredible Cows 搜索:二分+DFS 1504 计算直线的交点数 递推求解 1505 Number Game 动态规划 1506 Sort ZOJ7 字符串处理 1507 Find 7 Faster Than John Von Neumann 高精度计1508 免费馅饼 动态规划 1509 Worm 动态规划1510 Common Subsequence 动态规划 1511 搬寝室 动态规划 1512 Daydream 字符串处理 1513 Ballroom Lights 1514 Drop the Triples 1515 Finding Seats1516 He is offside! 1517 Justice League 1518 星星点点 搜索1519 逆波兰表达式 表达式求解:栈的应用 1520 十六进制 高精度计算 1521 Palindromic sequence 1522 Hotel 模拟题1523 Intersecting Lines 计算几何 1524 Heap Construction 最短路径 1525 Pizza Anyone? 1526 Adam's Genes 1527 Risk1528 Just the Facts 数论 1529 Horse Shoe Scoring 计算几何 1530 哥德巴赫猜想 数论1531 爱的伟大意义 简单题1532 校门外的树 模拟题 1533 最多约数问题 数论 1534 Quicksum 数学题1535 找规律填数字 数学题1536 Accepted Necklace 搜索:DFS1537 除法表达式 数论 1538 A Walk Through the Forest 图论:最短路径 1539 Accurately Say "CocaCola"! 简单题 1540 Build The Electric System 图论:最小生成树 1541 Colorful Rainbows 计算几何 1542 Easy Task 数学题1543 Faster, Higher, Stronger 简单题 1544 Give Me the Number 模拟题 1545 Hurdles of 110m 动态规划 1546 Just Pour the Water 矩阵计算 1547 Kinds of Fuwas 穷举法 1548 复数运算 简单题 1549 元素个数排序 简单题 1550 Fiber Communications 1551 Power Hungry Cows 搜索:BFS 1552 Cow Cycling 动态规划 1553 Rebuilding Roads 树型DP 1554 Triangular Pastures 动态规划 1555 Chores 动态规划 1556 Extra Krunch1557 BUY LOW, BUY LOWER 动态规划 1558 Hypnotic Milk Improvement 1559 Happy Cows1560 Unary Cow Counting 1561 Dairy Route 1562 Calf Numbers 1563 Hide and Seek 1564 Mountain Majesties 1565 Secret Milk Pipes 1566 Circus Tickets 1567 Life Cycle 1568 Wiggle Numbers 1569 Superwords 1570 Cow Brainiacs 1571 Pasture Fences 1572 New Years Party 1573 Strolling Cows 1574 Grazing Sets 1575 Factorial Power 1576 Friday the Thirteenth 1577 Beef McNuggets 1578 Calf Flac 1579 Light Bulbs 1580 Cow Math 图论1581 Cow Imposters 动态规划 1582 Traffic Lights 递推求解 1583 Farm Tour 图论:最短路径 1584 Vertical Histogram 简单题 1585 Cowties 动态规划 1586 Travel Games 搜索:DFS1587 Best Cow Fences 二分法 1588 Cornfields RMQ 问题 1589 Six Degrees of Cowvin Bacon 简单题 1590 Herd Sums 简单题1591 Message Decoding 简单题1592 Mountain Walking 二分+flood fill 1593 Millenium Leapcow 动态规划 1594 Optimal Milking 最大流+二分法1595 Bale Figures 模拟+二分法1596 Jumping Cows 动态规划 1597 Lost Cows SBT 树1598 Bovine Math Geniuses 简单题 1599 Dividing the Path 动态规划 1600 Fence Obstacle Course 动态规划 1601 Cow Ski Area 图论:flood fill 1602 Cleaning Shifts 贪心法 1603 Bad Cowtractors 最大生成树 1604 Tree Cutting 树状动态规划 1605 Navigation Nightmare 并查集 1606 Cow Marathon 树状动态规划 1607 Distance Queries LCA ,tarjan 算法 1608 Distance Statistics 楼天成大牛“男人八题”中的一道 1609 Moo University - Team Tryouts 排序+穷举法 1610 Moo University - Emergency Pizza Order 1611 Moo University - Financial Aid 最大堆、最小堆 1612 Cube Stacking 并查集 1613 The Cow Lineup 穷举法 1614 MooFest 线段树1615 Turning in Homework 动态规划 1616 Alignment of the Planets 1617 Finding Bovine Roots 1618 Cow Bowling1619 Cow Patterns 字符串匹配的扩展 1620 Barn Expansion 二分查找 1621 Layout 差分约束系统 1622 Knights of Ni 搜索:BFS 1623 Cleaning Shifts DP +Heap 1624 Scales 搜索+剪枝1625 Secret Milking Machine 二分+网络流 1626 Aggressive cows 二分法1627 Rigging the Bovine Election 穷举法 1628 Feed Accounting 简单模拟题1629 Muddy Fields 穷举法1630 The Wedding Juicer 堆+flood fill 1631 Naptime 动态规划 1632 Sumsets 动态规划1633 Moo Volume 简单题1634 Ombrophobic Bovines Floyd-Warshall 1635 Space Elevator 动态规划1636 Yogurt factory 动态规划 1637 Checking an Alibi 最短路径 1638 Out of Hay 1639 Satellite Photographs 搜索:BFS or DFS 1640 Asteroids 最大网络流 1641 Grazing on the Run 动态规划1642 Walk the Talk 动态规划1643 City Skyline 栈的应用 1644 Cow Acrobats 贪心法1645 Ant Counting 动态规划 1646 Hopscotch 搜索:DFS1647 Securing the Barn 穷举法 1648 Bovine Birthday 递推求解 1649 Max Factor 简单题 1650 Flying Right 1651 Close Encounter 1652 Allowance 1653 Lazy Cows 1654 Expedition 1655 Around the world 1656 Landscaping 1657 Waves1658 Navigating the City1659 Disease Management 1660 Muddy roads 1661 Wormholes 最短路径 1662 The Fewest Coins 动态规划 1663 Milk Patterns 二分法or 后缀树1664 Cow Picnic 搜索:BFS or DFS 1665 Cow Roller Coaster 动态规划 1666 River Hopscotch 二分法+贪心 1667 The Moronic Cowmpouter 进制转换 1668 DNA Assembly 穷举法1669 Cow Phrasebook 二分法 1670 Cellphones 穷举法1671 Steady Cow Assignment 网络流 1672 Treats for the Cows 动态规划 1673 Backward Digit Sums 穷举法 1674 Stump Removal 简单题 1675 Finicky Grazers 动态规划 1676 The Water Bowls 枚举二进制位 1677 Redundant Paths 图论 1678 Roping the Field 动态规划 1679 Corral the Cows 二分法 1680 The Cow Prom 图论 1681 Dollar Dayz 动态规划 1682 The Grove 最短路径 1683 Fence Repair Huffman 编码 1684 Corn Fields 状态压缩DP 1685 Roadblocks 图论:最短路径 1686 Bad Hair Day 搜索 1687 Big Square 穷举法 1688 Round Numbers 枚举二进制位 1689 Building A New Barn 1690 Cow Sorting 置换群 1691 Lilypad Pond 最短路径 1692 The Cow Lexicon 动态规划 1693 Silver Cow Party 最短路径 1694 Problem Solving 动态规划 1695 Cow School1696 Protecting the Flowers 贪心法 1697 Tallest Cow 区间统计 1698 Balanced Lineup RMQ 问题1699 Gold Balanced Lineup RMQ 问题 1700 Ranking the Cows 搜索:DFS 1701 Face The Right Way 穷举法 1702 Cow Traffic 动态规划 1703 Monthly Expense 贪心法 1704 Cheapest Palindrome 动态规划 1705 Dining 贪心+网络流 1706 City Horizon 离散化+ 扫描 1707 Catch That Cow 最短路径 1708 Fliptile 枚举+位压缩 1709 2-Dimensional Rubik's Cube 搜索:BFS 1710 Ball 计算几何1711 3D Camera 三维计算几何 1712 Cipher 模拟题1713 Five in a Row 简单题 1714 Pinhole Imaging 简单计算几何1715 URL 模拟题 1716 Battle of Submarines 集合DP 1717 WOJ 动态规划 1718 钥匙计数之二 递推求解 1719 BrokenLED 模拟题 1722 A+B again and again! 模拟题 1723 Just calculate it! 数论 1724 Guess how much I love you? 简单题 1725 NBA Finals 1726 Find Out an “E” 1727 Judging ACM/ICPC 1728 Cryptography of Alex 1729 Rings of square grid 1730 Fermat's Theorem 1731 Cup 二分法1732 Find the Path DP+二分法1733 Five in a Row, Again 动态规划 1734 Minimum Heap 递推求解1735 Name PK 模拟题 1736 Pendant 动态规划 1737 Radar 计算几何+搜索 1738 Ring 多串模式匹配 1739 Run 计算几何1740 Toxophily 简单题 1741 通讯录编排 简单题 1742 超缘分ACM 队伍 简单题1743 集合运算 简单题 1744 矩阵计算 简单题1745 Arbitrage 动态规划1746 The Tower of Babylon 动态规划 1747 Binomial Showdown 组合数学 1748 Dungeon Master 搜索:BFS1749 Equation Solver 表达式求值应用 1750 Frogger 最短路径 1751 Globetrotter 计算几何1752 Tree Recovery 数据结构:二叉树 1753 Artificial Intelligence? 1754 The Settlers of Catan 搜索 1755 France '98 概率问题1756 Goldbach's Conjecture 数论 1757 Heavy Cargo 最小生成树 1758 Quadtree1759 From Dusk till Dawn or: Vladimir the Vampir1760 Euro Cup 2000 1761 Quadtree II or: Florida Jones strikes back 1762 HTML 简单题1763 Paths on a Grid 组合数学:T 路问题 1764 Balanced Food 动态规划1765 California Jones and the Gate to Freedom 组1766 Diplomatic License 简单计算几何题 1767 Polygon Programming with Ease 数学题 1768 Hall of Fountains 搜索:BFS or DP1769 The Bottom of a Graph 图论:强连通分量 1770 Edge 1771 Fold1772 Largest Rectangle in a Histogram 动态规划 1773 Boolean Logic 1774 Code1775 In Danger 模拟题 1776 Fractran1777 Huffman's Greed 1778 Bullshit Bingo 字符串处理 1779 A Song contest 1780 Message1781 The skatepark's new ramps 1782 Road 1783 Warfare 1784 Blackjack 1785 Robintron1786 Diamond Dealer 计算几何:凸包 1787 Best Compression Ever 1788 Code Theft 1789 Dinner1790 Event Planning 1791 Getting Gold 1792 Introspective Caching1793 Just A Few More Triangles! 1794 Knights of the Round Table 图论:无向图的块1795 The Cow Doctor 穷举法1796 Wild West 线段树1797 Find the Clones 1798 The Warehouse1799 Widget Factory 数论:同余方程组1800 Martian Mining 动态规划 3301 字符串;AC 自动机, 动态规划;状态压缩3302 计算几何 3303 数学;代数运算;高斯消元 3304 图论;强连通分量;2-SAT 3305 动态规划;凸单调性优化 3306 枚举 3307 贪心3308 数学;代数运算 3309 最短路;佛洛伊德 3310 动态规划 3311 贪心3312 计数问题;递推,数状数组,二分查找 3313 数论;欧拉定理,快速幂取模 3314 计数问题,数状数组3315 博弈;Surreal 数;Farey 数列; 3316 计数问题;递推,高精度 3317 计数问题;容斥原理 3318 递推;矩阵乘法 3319 数学;概率 3320 背包 3321 动态规划3322 字符串;AC 自动机 3323 动态规划 3324 博弈 3325 搜索 3326 贪心 3327 最短路3328 数据结构(实现一种数据结构,支持要求的操作),数状数组 3329 图论;二分图最大权匹配 3330 数学;数论 3331 递推;矩阵乘法 3332 数学;数论,二分查找 3333 计算几何 3334 动态规划3335 字符串,后缀数组或拉宾卡普;动态规划 3336 数据结构;并查集 3337 计数问题,递推 3338 二分查找,贪心 3339 数学 3340 计算几何;凸包,图论;佛洛伊德;最小环 3341 动态规划 3342 广搜 3343 动态规划 3344 计算几何 3345 二分图最大匹配3346 树型DP 3347 动态规划 3348 数学;数论;进制 3349 计数问题 3350 贪心3351 数学;数论;进制 3352 动态规划,数论,组合数学 3353 数学;数论 3354 计数;递推 3355 图论;佛洛伊德3356 博弈 3357 动态规划 3358 数据结构;线段树,数状数组3359 计算几何,动态规划 3360 博弈;SG 函数 3361 图论;最近公共祖先 3362 图论;强连通分量;2-SAT 3363 计算几何3364 字符串;AC 自动机,动态规划 3365 搜索,舞蹈链 3366 数学;数论3367 数学;代数运算;高斯消元 3368 动态规划 3369 计数问题;递推 3370 网络流(错题) 3371 树型DP3372 数学;高精度 3373 数学; 3374 RMQ 3376 数学;进制 3377 字符串;后缀数组 3378 动态规划 3379 计算几何 3380 线段树3381 图论;欧拉路 3382 简单题3383 字符串;AC 自动机 3384 广搜 3385 计算几何,矩阵3386 语言处理3387 动态规划;状态压缩 3388 图论;全局最小割 3389 简单题 3390 广搜3391 数学;Pell 方程 3392 背包 3393 计算几何 3394 广搜3395 搜索;迭代加深 3396 数学;计数问题 3397 数学;解方程3398 分析 3399 模拟3400 数学;计数问题,数论。
浙江大学ACM题解分类
1475 Ranklist 没有完美解决,不知道您有没有好方法……
1572 Bracelet 题义不明,感觉可能是判定欧拉回路的存在性,但是过不去
动态规划:
1011 NTA 简单题
1013 Great Equipment 简单题
1024 Calendar Game 简单题
1027 Human Gene Functions 简单题
1239 Hanoi Tower Troubles Again! SRbGa的经典题……
字符串处理:
1050 Start Up the Startup 简单题
1315 Excuses, Excuses! 简单题
1350 The Drunk Jailer 简单题
1352 Number Base Conversion 简单题
1353 Unimodal Palindromic Decompositions 规模不大,所以是简单题……
1037 Gridland 简单题
1052 Algernon s Noxious Emissions 简单题
1409 Communication System 简单题,但是很容易看错~~~
1425 Crossed Matchings 简单题
1078 Palindrom Numbers 简单题
1086 Octal Fractions 简单题
1199 Point of Intersection 简单题
1104 Leaps Tall Buildings 简单题
1110 Dick and Jane 简单题
ACM题目分类
-----------------------------最优化问题------------------------------------- ----------------------常规动态规划SOJ1162 I-KeyboardSOJ1685 ChopsticksSOJ1679 GangstersSOJ2096 Maximum SubmatrixSOJ2111 littleken bgSOJ2142 Cow ExhibitionSOJ2505 The County FairSOJ2818 QQ音速SOJ2469 Exploring PyramidsSOJ1833 Base NumbersSOJ2009 Zeros and OnesSOJ2032 The Lost HouseSOJ2113 数字游戏SOJ2289 A decorative fenceSOJ2494 ApplelandSOJ2440 The days in fzkSOJ2494 ApplelandSOJ2515 Ski LiftSOJ2718 BookshelfSOJ2722 Treats for the CowsSOJ2726 Deck of CardsSOJ2729 Space ElevatorSOJ2730 Lazy CowsSOJ2713 Cut the SequenceSOJ2768 BombSOJ2779 Find the max (I) (最大M子段和问题)SOJ2796 Letter DeletionSOJ2800 三角形SOJ2804 Longest Ordered Subsequence (II)SOJ2848 River Hopscotch(二分)SOJ2849 Cow Roller CoasterSOJ2886 Cow WalkSOJ2896 AlphacodeSOJ2939 bailey's troubleSOJ2994 RSISOJ3037 Painting the ballsSOJ3072 ComputersSOJ3078 windy's "K-Monotonic"SOJ3084 windy's cake IVSOJ3104 Game(注意大数运算,高精度)SOJ3110 k Cover of LineSOJ3111 k Median of LineSOJ3123 Telephone WireSOJ3142 Unfriendly Multi Permutation SOJ3213 PebblesSOJ3219 Cover UpSOJ3263 FunctionSOJ3264 Evil GameSOJ3339 graze2SOJ3341 SkiSOJ3352 The Baric BovineSOJ3503 Banana BoxesSOJ3633 Matches's GameSOJ3636 理想的正方形SOJ3711 Mountain RoadSOJ3723 Robotic Invasionnankai1134 Relation Orderingsrm150--div1--500----------------背包问题SOJ2222 Health PowerSOJ2749 The Fewest CoinsSOJ2785 Binary PartitionsSOJ2930 积木城堡SOJ3172 FishermanSOJ3300 Stockholm CoinsSOJ3360 Buying HaySOJ3531 Number Pyramids----------------状态DPSOJ2089 lykooSOJ2768 BombSOJ2819 AderSOJ2842 The TSP problemSOJ3025 Artillery(状态DP)SOJ3088 windy's cake VIIISOJ3183 Fgjlwj's boxesSOJ3259 Counting numbersSOJ3262 Square Fields(二分+状态DP) SOJ3371 Mixed Up CowsSOJ3631 Shopping Offers----------------树状DPSOJ 1870 Rebuilding RoadsSOJ 2136 Apple(树形依赖背包n*C算法)SOJ 2514 Milk Team SelectSOJ 2199 Apple TreeSOJ 3295 Treeland ExhibitionSOJ 3635 World Cup 2010hdoj1561 The more, The BetterPKU1655 Balancing ActPKU3107 GodfatherPKU3345 Bribing FIPAPKU2378 Tree CuttingPKU3140 Contestants DivisionPKU3659 Cell Phone Network---------------配合数据结构的优化DPSOJ 2702 AlannaSOJ 2978 TasksSOJ 3234 Finding SeatsSOJ 3540 股票交易-------------- 斜率优化SOJ 3710 特别行动队SOJ 3734 搬家SOJ 3736 Lawrence of Arabia---------------四边形不等式SOJ 1702 Cutting SticksSOJ 2775 Breaking Strings--------------- 最优化之排序(思考两个元素之间的先后关系,以此得出一个二元比较关系,并验证此关系可传递,反对称,进而排序)SOJ2509 The Milk QueueSOJ2547 cardsSOJ2850 Protecting the FlowersSOJ2957 Setting ProblemsSOJ3167 ComputerSOJ3331 Cards(2547加强版)SOJ3327 Dahema's Computer(通过此题学会排序)-----------------最优化之必要条件枚举(思考最优解所具有的性质,得出最优解的一个强必要条件,在此基础上枚举)SOJ3317 FGJ's PlaneSOJ3429 Food portion sizes--------------------------------贪心---------------------------------------SOJ1078 BlueEyes' ScheduleSOJ1203 Pass-MurailleSOJ1673 Gone FishingSOJ2574 pieSOJ2645 Buy One Get One FreeSOJ2701 In a CycleSOJ2876 Antimonotonicity(经典模型 O(n)算法)SOJ3343 Tower--------------------------------搜索--------------------------------------- SOJ1106 DWeepSOJ1626 squareSOJ2061 8 puzzleSOJ2485 SudokuSOJ1045 SticksSOJ2736 FliptileSOJ2771 Collecting StonesSOJ2715 Maze BreakSOJ2518 Magic Cow ShoesSOJ2829 binary strings(双向BFS)SOJ3005 Dropping the stonesSOJ3136 scu07t01的迷宫(BFS预处理然后枚举交汇点)SOJ3330 Windy's Matrix(BFS)--------------------------------DFA---------------------------------------- ---------------状态矩阵SOJ1826 Number SequenceSOJ1936 FirepersonsSOJ2552 Number of TilingsSOJ2919 Matrix Power Series (学习矩阵的快速乘法从此开始)SOJ2920 Magic BeanSOJ3021 Quad TilingSOJ3046 Odd Loving BakersSOJ3176 E-stringSOJ3246 Tiling a Grid With DominoesSOJ3323 K-Satisfied NumbersSOJ3337 Wqb's Word----------------DFA+DPSOJ1112 Repeatless Numbers(DFA+二分)SOJ2913 Number SubstringSOJ2826 Apocalypse SomedaySOJ3128 windy和水星 -- 水星数学家 1SOJ3182 Windy numbers---------------------------------图论-----------------------------------------------------------最短路SOJ1697 Cashier EmploymentSOJ2325 Word TransformationSOJ2427 Daizi's path systemSOJ2468 CatcusSOJ2751 Wormholes(SPFA判断负圈回路的存在性)SOJ2932 道路SOJ3160 Clear And Present DangerSOJ3335 Windy's Route(最短路径的分层图思想)SOJ3346 Best Spot(N^3放心的写)SOJ3423 Revamping Trails---------------------查分约束SOJ1687 Intervals---------------------最小生成树SOJ1169 NetworkingSOJ2198 HighwaysSOJ3366 Watering HoleSOJ3427 Dark roads---------------------强连通分支SOJ2832 Mars city---------------------2-SATSOJ3535 Colorful DecorationHDU3062 Party---------------------拓扑排序SOJ1075 BlueEyes and Apples (II)---------------------无向连通图上的割点和割边问题SOJ1935 ElectricityWHU145 Railway---------------------二分图的匹配------------------最大匹配SOJ1183 Girls and BoysSOJ1186 CoursesSOJ2035 The Tiling ProblemSOJ2077 Machine ScheduleSOJ2160 Optimal MilkingSOJ2342 Rectangles(Beloved Sons 模型)SOJ2472 Guardian of DecencySOJ2681 平方数 2SOJ2737 AsteroidsSOJ2764 Link-up GameSOJ2806 LED DisplaySOJ2958 Weird FenceSOJ3043 Minimum CostSOJ3038 Beloved Sons(简单贪心一下)SOJ3453 Stock ChartsZOJ3265 Strange Game---------------最佳匹配SOJ1981 Going HomeWHU1451 Special Fish---------------------最近公共祖先问题SOJ1187 Closest Common AncestorsSOJ1677 How far awaySOJ3023 NetworkSOJ3098 Bond---------------------其他SOJ3013 treeSOJ3056 Average distance(树上的DFS)---------------------------------网络流------------------------------------- ---------------------最大流POJ 1273 Drainage DitchesPOJ 1274 The Perfect Stall (二分图匹配)POJ 1698 Alice's ChancePOJ 1459 Power NetworkPOJ 2112 Optimal Milking (二分)POJ 2455 Secret Milking Machine (二分)POJ 3189 Steady Cow Assignment (枚举)POJ 1637 Sightseeing tour (混合图欧拉回路)POJ 3498 March of the Penguins (枚举汇点)POJ 1087 A Plug for UNIXPOJ 1149 Pigs (构图题)ZOJ 2760 How Many Shortest Path (边不相交最短路的条数)POJ 2391 Ombrophobic Bovines (必须拆点,否则有BUG)WHU 1124 Football Coach (构图题)SGU 326 Perspective (构图题,类似于 WHU 1124)UVa 563 CrimewaveUVa 820 Internet BandwidthPOJ 3281 Dining (构图题)POJ 3436 ACM Computer FactoryPOJ 2289 Jamie's Contact Groups (二分)SGU 438 The Glorious Karlutka River =) (按时间拆点)SGU 242 Student's Morning (输出一组解)SGU 185 Two shortest (Dijkstra 预处理,两次增广,必须用邻接阵实现,否则 MLE) HOJ 2816 Power LinePOJ 2699 The Maximum Number of Strong Kings (枚举+构图)ZOJ 2332 GemsJOJ 2453 Candy (构图题)SOJ 2414 Leapin' LizardsSOJ 2835 Pick Up PointsSOJ 3312 Stockholm KnightsSOJ 3353 Total Flow--------------------最小割SOJ2662 PlaygroundSOJ3106 Dual Core CPUSOJ3109 Space flightSOJ3107 SelectSOJ3185 Black and whiteSOJ3254 Rain and FgjSOJ3134 windy和水星 -- 水星交通HOJ 2634 How to earn moreZOJ 2071 Technology Trader (找割边)HNU 10940 CoconutsZOJ 2532 Internship (找关键割边)POJ 1815 Friendship (字典序最小的点割集)POJ 3204 Ikki's Story I - Road Reconstruction (找关键割边)POJ 3308 ParatroopersPOJ 3084 Panic RoomPOJ 3469 Dual Core CPUZOJ 2587 Unique Attack (最小割的唯一性判定)POJ 2125 Destroying The Graph (找割边)ZOJ 2539 Energy MinimizationZOJ 2930 The Worst ScheduleTJU 2944 Mussy Paper (最大权闭合子图)POJ 1966 Cable TV Network (无向图点连通度)HDU 1565 方格取数(1) (最大点权独立集)HDU 1569 方格取数(2) (最大点权独立集)HDU 3046 Pleasant sheep and big big wolfPOJ 2987 Firing (最大权闭合子图)SPOJ 839 Optimal Marks (将异或操作转化为对每一位求最小割)HOJ 2811 Earthquake Damage (最小点割集)2008 Beijing Regional Contest Problem A Destroying the bus stations ( BFS 预处理 )(http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=4322)ZOJ 2676 Network Wars (参数搜索)POJ 3155 Hard Life (参数搜索)ZOJ 3241 Being a Hero-----------------有上下界ZOJ 2314 Reactor Cooling (无源汇可行流)POJ 2396 Budget (有源汇可行流)SGU 176 Flow Construction (有源汇最小流)ZOJ 3229 Shoot the Bullet (有源汇最大流)HDU 3157 Crazy Circuits (有源汇最小流)-----------------最小费用流HOJ 2715 Matrix3HOJ 2739 The Chinese Postman ProblemPOJ 2175 Evacuation Plan (消一次负圈)POJ 3422 Kaka's Matrix Travels (与 Matrix3 类似)POJ 2516 Minimum Cost (按物品种类多次建图)POJ 2195 Going HomePOJ 3762 The Bonus Salary!BUAA 1032 Destroying a PaintingPOJ 2400 Supervisor, Supervisee (输出所有最小权匹配)POJ 3680 IntervalsHOJ 2543 Stone IVPOJ 2135 Farm TourSOJ 3186 SegmentsSOJ 2927 终极情报网SOJ 3634 星际竞速HDU 3376 Matrix Again-----------------------------------数据结构--------------------------------- -----------------------------------基础数据结构----------------------栈SOJ2511 MooooSOJ3085 windy's cake V(经典栈与单调性的结合)SOJ3279 hm 与 zx 的故事系列2SOJ3329 Maximum Submatrix II(转化为上面两题的模型)---------------------双端队列SOJ2978 TasksSOJ3139 Sliding Window(双端队列最经典的应用)SOJ3636 理想的正方形-------------------- --------------高级数据结构---------------------线段树SOJ1862 Choice PearsSOJ2057 The manager's worrySOJ2249 Mayor's postersSOJ2309 In the Army NowSOJ2436 Picture puzzle gameSOJ2556 Find the PermutationSOJ2562 The End of CorruptionSOJ2719 Corral the Cows(线段树+二分)SOJ2740 Balanced LineupSOJ2745 零序列SOJ2776 Matrix SearchingSOJ2808 Thermal Death of the UniverseSOJ2822 Buy TicketsSOJ2937 TetrisSOJ2938 Apple Tree(先DFS获得欧拉序列)SOJ2965 capitally playersSOJ2968 Matrix(二维线段树)SOJ3019 Count ColorSOJ3022 Difference Is Beautiful( RMQ+二分经典模型)SOJ3086 windy's cake VI(二维线段树)SOJ3099 A Simple Problem with IntegersSOJ3248 MousetrapSOJ3321 Windy's Sequence IISOJ3370 Light SwitchingSOJ3640 Special Subsequence---------------------树状数组SOJ2309 In the Army Now---------------------归并排序思想SOJ2906 Ultra-QuickSortSOJ2431 Cows distribute food(利用归并排序求逆序数:nlogn) SOJ2497 Number sequenceSOJ2559 What is the Rank?SOJ2728 MooFestSOJ3009 Stones for AmySOJ3010 K-th NumberSOJ3147 K-th number---------------------并查集SOJ1824 The SuspectsSOJ1953 keySOJ2245 Ubiquitous ReligionsSOJ2389 Journey to TibetSOJ2438 PetSOJ2490 Math teacher's testPOJ2832 How many pairs?POJ2821 Auto-Calculation MachineSOJ2979 食物链SOJ3282 Kingdom of HeavenSOJ3417 Skyscrapers------------------------块状链表SOJ3032 Big StringSOJ3035 反转序列----------------------------------- 字符串---------------------后缀数组SOJ1948 sekretarkaSOJ3045 Long Long MessageSOJ3075 回文子串SOJ3296 Windy's S---------------------KMPSOJ2652 OulipoSOJ2307 String MatchingSOJ3014 Seek the Name, Seek the FameSOJ3596 Article Decryption--------------------trie树SOJ3076 相同字符串SOJ3336 DiarySOJ3596 Article Decryption---------------------------------组合数学及数论----------------------------- SOJ1839 Relatives(Euler函数)SOJ1942 FotoSOJ2714 Mountains (II)SOJ2668 C(n,k)SOJ2666 分解 n!SOJ2106 GCD & LCM InverseSOJ2498 Count primeSOJ2238 Let it Bead(置换群-polya定理的应用)SOJ2924 完美交换(置换群)SOJ2638 Cow Sorting(置换群)-------------费马小定理SOJ 3578 H1N1's Problem--------------------------容斥原理SOJ3191 Free squareSOJ3082 windy's cake IISOJ3502 The Almost Lucky NumbersSOJ3547 Coprime----------------------------------博弈论------------------------------------SOJ1128 控制棋SOJ1866 Games(诡异的博弈)SOJ2197 A Funny GameSOJ2188 A multiplication gameSOJ2403 Black and white chessSOJ2477 Simple GameSOJ2687 草稿纸 2SOJ2688 草稿纸 3SOJ2836 Pick Up Points IISOJ2845 JangeSOJ2922 A New Tetris GameSOJ2993 NimSOJ3066 JohnSOJ3132 windy和水星 -- 水星游戏 1SOJ3133 windy和水星 -- 水星游戏 2SOJ3174 Good gameSOJ3307 Stockholm GameSOJ3446 Nim or not NimSOJ3461 Nim-kSOJ3463 Ordered NimSOJ3468 Flip CoinsSOJ3548 gameSOJ3584 Baihacker and Oml-----------------------------------计算几何---------------------------------SOJ1138 WallSOJ1102 Picnic。
浙江大学acm答案完整版
浙江大学acm答案完整版求余运算给出S和M,求0*S%M,1*S%M,2*S%M......(M-1)*S%M能否组成一个集合包含0.1.。
M-1;(这个是原题意改造而来);算法:判断两个数是否互质;or 暴力解决其实暴力完全可以解决这个问题(⊙﹏⊙b),只是其中用数学方法更加高效,巧妙;证明如果S和M互质则满足题意:另G=gcd(S,M);则S=A*G,M=B*G;另X=K*S%M=K*S-T*M(T为整数,满足X属于0到M-1);X=K*A*G-T*B*G;因此取余后的整数一定是G的倍数,G只能取1才能满足条件;充分性的证明:(即当S与M互质,则0到M-1的S倍对M取余一定能遍历0到M-1)只需证明的是,该余数中两两之间互不相等;假设k*S和b*S对M取余相等(k和b∈[0,M),并且k和b不等);则k*S=q1*M+r=q2*M+r=b*S <==> (k-b)*S=M*(q1-q2);S与M互质,由上式子可得M|(k-b),与k和b∈[0,M),并且k和b不等矛盾;因此得证;另外,偶然看到一个很牛叉的辗转相除法;int gcd(int a,int b){while(b) b^=a^=b^=a%=b;return a;}此代码,很好很强大;把涉及位运算的交换的程序加入,便到得这段简洁高效的代码;注:A和B;经过A^=B^=A^=B,结果就得到A和B的交换//////////////////////////// 1000#includeint main(){int a,b,i,;scanf("%d",&a);for(i=1;i<=a;i++){ int sum=0;sum=sum+i;printf("%d\n",sum);}return 0;};1001;#include"stdio.h"int main(){unsigned _int64 n;unsigned _int64 temp;while(scanf("%I64u",&n)!=EOF) //是i 非L{temp=(1+n)*n/2;printf("%I64u\n\n",temp);}return 0;}//////////////////HDU ACM 1014 Uniform Generator 三月22nd, /doc/904868734.html,/showproblem.php?pid=1014这个题目是判断给定的步长和mod,判断所产生的随机数已经覆盖0~mod-1中所有的数,如果是,则说明所选的步长和mod是一个Good choice,否则为bad choice.需要懂得的基本内容为线性同余产生随机数,链接:/doc/904868734.html,/zh-cn/%E7%B7%9A%E6%80%A7%E5%90%8C%E9%A4%98%E6%96 %B9%E6%B3%95Problem DescriptionComputer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the formseed(x+1) = [seed(x) + STEP] % MODwhere '%' is the modulus operator.Such a function will generate pseudo-random numbers (seed) between 0 and MOD-1. One problem with functions of this form is that they will always generate the same pattern over and over. In order to minimize this effect, selecting the STEP and MOD values carefully can result in a uniform distribution of all values between (and including) 0 and MOD-1.For example, if STEP = 3 and MOD = 5, the function will generate the series of pseudo-random numbers 0, 3, 1, 4, 2 in a repeating cycle. In this example, all of the numbers between and including 0 and MOD-1 will be generated every MOD iterations of the function. Note that by the nature of the function to generate the same seed(x+1) every time seed(x) occurs means that if a function will generate all the numbers between 0 and MOD-1, it will generate pseudo-random numbers uniformly with every MOD iterations.If STEP = 15 and MOD = 20, the function generates the series0, 15, 10, 5 (or any other repeating series if the initial seed is other than 0). This is a poor selection of STEP and MOD because no initial seed will generate all of the numbers from 0 and MOD-1.Your program will determine if choices of STEP and MOD will generate a uniform distribution of pseudo-random numbers.InputEach line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).OutputFor each line of input, your program should print the STEP value right- justified in columns 1 through 10, the MOD value right-justified in columns 11 through 20 and either "Good Choice" or "Bad Choice" left-justified starting in column 25. The "Good Choice" message should be printed when the selection of STEP and MOD will generate all the numbers between and including 0 and MOD-1 when MOD numbers are generated. Otherwise, your program should print the message "Bad Choice". After each output test set, your program should print exactly one blank line.Sample Input3 515 2063923 99999Sample Output3 5 Good Choice15 20 Bad Choice63923 99999 Good Choice线性同余方法(LCG)是个产生伪随机数的方法。
适合新手的ACM题
第一套动态规划:ZJU1558难度:比较简单博弈问题:ZJU1913难度:中等偏难递归计算:ZJU1500难度:中等最小生成树:ZJU1914难度:中等第二套动态规划:ZJU1107难度:中等偏难找规律:ZJU2058难度:比较简单迭代计算:ZJU1544难度:中等偏易二分逼近:ZJU1464难度:中等第三套动态规划:ZJU1428难度:中等偏难枚举+判断:ZJU1354难度:比较简单差分/贪心:ZJU1508难度:中等偏难搜索剪枝:ZJU1909难度:中等偏易备选题目:杂题:物理+数学:ZJU1104难度:中等偏易物理题:ZJU1656难度:中等统计计算:ZJU1515难度:中等偏难单词树:ZJU1511难度:中等偏难模拟计算:ZJU2054难度:中等偏易找规律:ZJU1871难度:中等偏易筛法求素数:ZJU1951难度:中等偏易动态规划:暴力DP:ZJU1039难度:中等偏难暴力DP:ZJU1227难度:比较难经典问题:ZJU1149难度:如果不会用剩余类,感觉比较难。
可以考查骗分技巧(就是那种砍到多少多少以下)经典问题:ZJU1366难度:同上。
但这题用搜索用得好的话可以瞬过。
状态表示:ZJU2059难度:中等偏难。
这个题考状态表示的状态表示:ZJU1757难度:中等偏难。
一类NP问题的动规解法。
经典问题:ZJU2096难度:中等偏难。
狗狗的题目。
经典问题:ZJU1717难度:中等偏易。
就是走格子的复杂一点版经典问题:ZJU1986难度:中等。
传说中的最长不XX子序列。
听说这个题不用O(nlogn)的过不了?我是O(nlogn)的。
非纯动规:ZJU1953难度:中等。
传说中的最长公共子序列。
不过这个题只是用到这个,后面还要用构造法。
数据结构:线段树:ZJU1128难度:中等偏难。
求面积并,扫描线法+线段树。
以前的国家队论文有过的题。
线段树:ZJU1659难度:中等偏难。
求面积并。
表达式计算:ZJU1958难度:中等去括号:ZJU2021难度:中等搜索题,BFS/DFS:BFS:ZJU1063难度:中等偏易BFS + DFS :ZJU1085难度:中等偏易经典的BFS :ZJU1136难度:中等偏难分类搜索:ZJU1732难度:中等偏难。
acm初级试题及答案
acm初级试题及答案1. 题目:字符串反转- 描述:编写一个函数,实现对输入字符串的反转。
- 输入:一个字符串。
- 输出:反转后的字符串。
答案:```pythondef reverse_string(s):return s[::-1]```2. 题目:求最大公约数- 描述:编写一个函数,计算两个正整数的最大公约数。
- 输入:两个正整数。
- 输出:两个数的最大公约数。
答案:```pythondef gcd(a, b):while b:a, b = b, a % breturn a```3. 题目:计算阶乘- 描述:编写一个函数,计算一个非负整数的阶乘。
- 输入:一个非负整数。
- 输出:该整数的阶乘。
答案:```pythondef factorial(n):if n == 0:return 1else:return n * factorial(n-1)```4. 题目:判断素数- 描述:编写一个函数,判断一个正整数是否为素数。
- 输入:一个正整数。
- 输出:如果该数是素数,返回True;否则返回False。
答案:```pythondef is_prime(n):if n <= 1:return Falsefor i in range(2, int(n0.5) + 1):if n % i == 0:return Falsereturn True```5. 题目:寻找数组中第二大的数- 描述:编写一个函数,找出数组中第二大的数。
- 输入:一个整数数组。
- 输出:数组中第二大的数。
答案:```pythondef find_second_max(arr):first = second = float('-inf')for num in arr:if num > first:second = firstfirst = numelif num > second and num != first: second = numreturn second```。
acm试题及答案
acm试题及答案ACM试题及答案试题 1: 给定一个整数数组,请找出数组中第二大的数。
答案:1. 对数组进行排序。
2. 数组排序后,倒数第二个元素即为第二大的数。
试题 2: 编写一个函数,计算给定字符串中字符出现的次数。
答案:```pythondef count_characters(s):count_dict = {}for char in s:if char in count_dict:count_dict[char] += 1else:count_dict[char] = 1return count_dict```试题 3: 判断一个数是否为素数。
答案:1. 如果数小于2,则不是素数。
2. 从2开始到该数的平方根,检查是否有因数。
3. 如果没有因数,则该数是素数。
试题 4: 实现一个算法,将一个整数数组按照奇数在前,偶数在后的顺序重新排列。
答案:```pythondef rearrange_array(arr):odd = []even = []for num in arr:if num % 2 == 0:even.append(num)else:odd.append(num)return odd + even```试题 5: 给定一个链表,删除链表的倒数第n个节点。
答案:1. 遍历链表,找到链表的长度。
2. 再次遍历链表,找到倒数第n个节点的前一个节点。
3. 将前一个节点的next指针指向当前节点的下一个节点。
4. 如果当前节点是头节点,则更新头节点。
试题 6: 编写一个函数,实现字符串反转。
答案:```pythondef reverse_string(s):return s[::-1]```试题 7: 给定一个整数数组,找出数组中没有出现的最小正整数。
答案:1. 遍历数组,使用哈希表记录出现的数字。
2. 从1开始,检查每个数字是否在哈希表中。
3. 第一个不在哈希表中的数字即为答案。
试题 8: 实现一个算法,计算斐波那契数列的第n项。
浙大ACM
浙大ACM题集详解ZOJ Problem Set – 1001 A + B ProblemTime Limit: 1 Second Memory Limit: 32768 KBCalculate[计算] a + bInputThe input will consist of a series of pairs of integers a and b,separated by a space, one pair of integers per line.OutputFor each pair of input integers a and b you should output the sum of a and b in one line,and with one line of output for each line in input.Sample Input1 5Sample Output6思路:略代码呈现:#include<stdio.h>int main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF) //无限输入直到遇见shift+F6停止printf("%d\n",a+b);return 0;}代码效果:ZOJ Problem Set – 1037 GridlandTime Limit: 1 Second Memory Limit: 32768 KBBackgroundFor years, computer scientists have been trying to find efficient solutions to different computing[计算] problems. For some of them efficient algorithms[算法] are already available, these are the "easy" problems like sorting[整理;排序;分类拣选], evaluating a polynomial[多项式] or finding the shortest path in a graph. For the "hard" ones only exponential-time algorithms[指数时间算法] are known. The traveling-salesman problem belongs to this latter group. Given a set of N towns and roads between these towns, the problem is to compute the shortest path allowing a salesman to visit each of the towns once and only once and return to the starting point.ProblemThe president of Gridland has hired you to design a program that calculates the length of the shortest traveling-salesman tour for the towns in the country. In Gridland, there is one town at each of the points of a rectangular grid[直角坐标网]. Roads run from every town in the directions North, Northwest, West, Southwest, South, Southeast, East, and Northeast, provided that there is a neighboring town in that direction. The distance between neighboring towns in directions North-South or East-West is 1 unit. The length of the roads is measured by the Euclidean distance[欧几里得距离]. For example, Figure 7 shows 2 * 3-Gridland, i.e., a rectangular grid of dimensions [规模,大小] 2 by 3. In 2 * 3-Gridland, the shortest tour has length 6.Figure 7: A traveling-salesman tour in 2 * 3-Gridland.InputThe first line contains the number of scenarios[剧情(情况)].For each scenario, the grid dimensions m and n will be given as two integer numbers in a single line, separated by a single blank, satisfying 1 < m < 50 and 1 < n < 50.OutputThe output for each scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. In the next line, print the length of the shortest traveling-salesman tour rounded to two decimal digits. The output for every scenario ends with a blank line.Sample Input22 22 3Sample OutputScenario #1:4.00Scenario #2:6.00思路:如果城镇数是偶数,即分布的行和列至少有一个是偶数的时候,我们可以一个个走,正好最后一次回到起始城镇,即m*n;如果是奇数,就是说分布的行和列都是奇数,那么我们倒数第二次到的城镇和起点城镇之间相距斜线,即m*n-1+根号2。