杭电ACM水题题目及代码
杭州电子科技大学OJ题目分类
![杭州电子科技大学OJ题目分类](https://img.taocdn.com/s3/m/415c8659ad02de80d4d8401a.png)
杭州电子科技大学OJ题目分类1001 整数求和水题1002 C语言实验题——两个数比较水题1003 1、2、3、4、5... 简单题1004 渊子赛马排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想数论:容斥定理1007 童年生活二三事递推题1008 University 简单hash1009 目标柏林简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 u Calculate e 简单数学计算1013 STAMPS 搜索or动态规划1014 Border 模拟题1015 Simple Arithmetics 高精度计算1016 Shoot-out 博弈+状态压缩DP1017 Tour Guide1018 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 Content1032 Laserbox 搜索:DFS1033 Bowlstack1034 Pesky Heroes1035 Reduced ID Numbers 暴力1036 Tantrix1037 Guardian of Decency 图论:匈牙利算法求二分图的最大匹配1038 Up the Stairs 简单数学题1039 Sudoku 搜索:DFS1040 The SetStack Computer1041 Pie 二分法1042 Ticket to Ride 动态规划1043 The Bookcase 动态规划1044 Printer Queue 模拟题1045 Prime Path 搜索:BFS1046 Lineland's Airport1047 Leonardo's Notebook 数学题:群置换1048 简易版最长序列简单题1049 Jesse's problem 搜索:DFS1050 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 Mapping1085 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 Rho算法1113 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 搜索:BFS1122 ASCII Art1123 Billing Tables1124 Cellular Automaton 矩阵计算1125 Exchange1126 Fool's Game1127 Java vs C++ 字符串处理1128 Kickdown 字符串处理1129 Copying Books 贪心+二分法1130 Adding Reversed Numbers 简单题1131 Glass Beads 字符串的最小表示1132 The Circumference of the Circle 计算几何题1133 Knight Moves 搜索:BFS1134 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 搜索:BFS1148 In Danger 模拟题1149 Run Length Encoding 字符串处理1150 Bee Maja 模拟题1151 Friends 表达式求值1152 John 博弈论1153 Double Queue 最大堆与最小堆1154 ‘JBC’1155 Loan Scheduling 贪心+堆1156 Showstopper1157 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 hash1196 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 搜索:BFS1259 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 搜索:DFS1273 What Day Is It? 简单题1274 String Matching 字符串匹配1275 A Contesting Decision 简单题1276 Doubles 简单题1277 The Snail 简单题1278 Jungle Roads 图论:最小生成树1279 Prime Ring Problem 搜索:DFS1280 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 宝物收集搜索:BFS1312 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! 搜索:BFS1334 Oil Deposits 搜索:DFS1335 营救天使搜索:BFS1336 小数化分数高精度计算1337 I Hate It 线段树1338 Strange Billboard 位运算+枚举1339 Frobenius 递推求解1340 奇怪的公式数学题1341 Fibonacci again and again 博弈论1342 A New Tetris Game 博弈论1343 Sum It Up 搜索:DFS1344 速算24点搜索1345 推箱子搜索:BFS1346 Pushing Boxes 搜索:BFS1347 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 搜索:(双向)BFS1487 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 搜索:DFS1502 Find All M^N Please 数学题1503 Incredible Cows 搜索:二分+DFS1504 计算直线的交点数递推求解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 Lights1514 Drop the Triples1515 Finding Seats1516 He is offside!1517 Justice League1518 星星点点搜索1519 逆波兰表达式表达式求解:栈的应用1520 十六进制高精度计算1521 Palindromic sequence1522 Hotel 模拟题1523 Intersecting Lines 计算几何1524 Heap Construction 最短路径1525 Pizza Anyone?1526 Adam's Genes1527 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 Communications1551 Power Hungry Cows 搜索:BFS1552 Cow Cycling 动态规划1553 Rebuilding Roads 树型DP1554 Triangular Pastures 动态规划1555 Chores 动态规划1556 Extra Krunch1557 BUY LOW, BUY LOWER 动态规划1558 Hypnotic Milk Improvement1559 Happy Cows1560 Unary Cow Counting1561 Dairy Route1562 Calf Numbers1563 Hide and Seek1564 Mountain Majesties1565 Secret Milk Pipes1566 Circus Tickets1567 Life Cycle1568 Wiggle Numbers1569 Superwords1570 Cow Brainiacs1571 Pasture Fences1572 New Years Party1573 Strolling Cows1574 Grazing Sets1575 Factorial Power1576 Friday the Thirteenth1577 Beef McNuggets1578 Calf Flac1579 Light Bulbs1580 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 fill1593 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 fill1602 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 Order1611 Moo University - Financial Aid 最大堆、最小堆1612 Cube Stacking 并查集1613 The Cow Lineup 穷举法1614 MooFest 线段树1615 Turning in Homework 动态规划1616 Alignment of the Planets1617 Finding Bovine Roots1618 Cow Bowling1619 Cow Patterns 字符串匹配的扩展1620 Barn Expansion 二分查找1621 Layout 差分约束系统1622 Knights of Ni 搜索:BFS1623 Cleaning Shifts DP+Heap1624 Scales 搜索+剪枝1625 Secret Milking Machine 二分+网络流1626 Aggressive cows 二分法1627 Rigging the Bovine Election 穷举法1628 Feed Accounting 简单模拟题1629 Muddy Fields 穷举法1630 The Wedding Juicer 堆+flood fill1631 Naptime 动态规划1632 Sumsets 动态规划1633 Moo Volume 简单题1634 Ombrophobic Bovines Floyd-Warshall 1635 Space Elevator 动态规划1636 Yogurt factory 动态规划1637 Checking an Alibi 最短路径1638 Out of Hay1639 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 Right1651 Close Encounter1652 Allowance1653 Lazy Cows1654 Expedition1655 Around the world1656 Landscaping1657 Waves1658 Navigating the City1659 Disease Management1660 Muddy roads1661 Wormholes 最短路径1662 The Fewest Coins 动态规划1663 Milk Patterns 二分法or后缀树1664 Cow Picnic 搜索:BFS or DFS1665 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 状态压缩DP1685 Roadblocks 图论:最短路径1686 Bad Hair Day 搜索1687 Big Square 穷举法1688 Round Numbers 枚举二进制位1689 Building A New Barn1690 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 搜索:DFS1701 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 集合DP1717 WOJ 动态规划1718 钥匙计数之二递推求解1719 BrokenLED 模拟题1722 A+B again and again! 模拟题1723 Just calculate it! 数论1724 Guess how much I love you? 简单题1725 NBA Finals1726 Find Out an “E”1727 Judging ACM/ICPC1728 Cryptography of Alex1729 Rings of square grid1730 Fermat's Theorem1731 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 Vampire 最短路径1760 Euro Cup 20001761 Quadtree II or: Florida Jones strikes back1762 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 Edge1771 Fold1772 Largest Rectangle in a Histogram 动态规划1773 Boolean Logic1774 Code1775 In Danger 模拟题1776 Fractran1777 Huffman's Greed1778 Bullshit Bingo 字符串处理1779 A Song contest1780 Message1781 The skatepark's new ramps1782 Road1783 Warfare1784 Blackjack1785 Robintron1786 Diamond Dealer 计算几何:凸包1787 Best Compression Ever1788 Code Theft1789 Dinner1790 Event Planning1791 Getting Gold1792 Introspective Caching1793 Just A Few More Triangles!1794 Knights of the Round Table 图论:无向图的块判断奇圈1795 The Cow Doctor 穷举法1796 Wild West 线段树1797 Find the Clones1798 The Warehouse1799 Widget Factory 数论:同余方程组1800 Martian Mining 动态规划3301 字符串;AC自动机,动态规划;状态压缩3302 计算几何3303 数学;代数运算;高斯消元3304 图论;强连通分量;2-SAT3305 动态规划;凸单调性优化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 树型DP3347 动态规划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 RMQ3376 数学;进制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 数学;计数问题,数论6 热度。
杭电acm题目水题英文题目、翻译及ac源代码
![杭电acm题目水题英文题目、翻译及ac源代码](https://img.taocdn.com/s3/m/c036ef677ed5360cba1aa8114431b90d6c8589ff.png)
1040 As Easy As A+BTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768K (Java/Others)TotalSubmis sion(s): 26015Accept ed Submis sion(s): 11054Proble m Descri ptionThesedays, I am thinki ng abouta questi on, how can I get a proble m as easy as A+B? It is fairly diffic ultyto do such a thing. Of course, I got it aftermany waking nights.Give you some intege rs, your task is to sort thesenumber ascend ing (升序).You should know how easy the proble m is now!Good luck!InputInputcontai ns multip le test cases. The firstline of the inputis a single intege r T whichis the number of test cases. T test casesfollow. Each test case contai ns an intege r N (1<=N<=1000 the number of intege rs to be sorted) and then N intege rs follow in the same line.It is guaran tiedthat all intege rs are in the rangeof 32-int.OutputFor each case, printthe sortin g result, and one line one case.问题描述这些天来,我在思考一个问题,我怎样才能得到一个简单的问题,因为A + B?这是相当困难做这样的事情。
杭电ACM试题详细分类,杭电oj详细分类,hdu详细分类,详细,ACM
![杭电ACM试题详细分类,杭电oj详细分类,hdu详细分类,详细,ACM](https://img.taocdn.com/s3/m/d390730ccfc789eb172dc8b2.png)
1164 1211 1215 1222 1286 1299
计算几何
1086 1115 1147
贪心
1009 1052 1055 1232 1272
线段树,离散化
1199 1255
图论 最短路相关的问题
1142 1162 1217 1301
二分图问题
1054 1068 1150 1151 1281
杭电ACM试题分类 枚举
1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 1202 1205 1209 1212(大数取模) 1216(链表)1218 1219 1225 1228 1229 1230 1234 1235 1236 1237 1239 1250 1256 1259 1262 1263 1265 1266 1276 1279 1282 1283 1287 1296 1302 1303 1304 1305 1306 1309 1311 1314
2549、2550、2551、2552、2555、2560、2561、2562、2566、2567、 2568、2700、2710、
DP:1003、10240、1029、1069、1074、1087、1114、1159、1160、
1171、1176、1203、1231、1257、1260、1284、1421、1789、1978、 2059、2084、2159、2191、2544、2571、2602、2709、
ACM水题题目解析
![ACM水题题目解析](https://img.taocdn.com/s3/m/dceaa54e561252d380eb6e22.png)
2
项目设计
• 1. 输入四个整数 • 2. 求第一个数和第二个数的差,用p表示 • 3. 求第二个数和第三个数的差,用q表示 • 4. 若p与q相等,为等差数列,计算并输出该等差数 列的第五项 • 5. 若p与q不相等,为等比数列,计算并输出等比数 列的第五项
3
项目实现
main() { int i; int num[4]; int d; int q; for (i = 0; i < 4; ++i) { scanf("%d", num + i); printf("%d ", num[i]); } d = num[1] - num[0]; q = num[2] - num[1]; if (d == q) printf("%d\n", num[3] + d); else printf("%d\n", (int)(num[3] * (num[1] * 1.0 / num[0]))); }
4
项目运行
5
ACM
项目二——数字排序问题
项目构思:
• 已知一个从1到n的无序数组,我们可以两两互换数字 的方式为该数组排序,如数组2, 3, 5, 4, 1,可以通过 三次交换得到有序数组1,2,3,4,5 • 23541 13542 13245 12345 如上面的数组,要通过三次交换,得到有序数组。 • 编程实现:输入一个1到n的无序序列,计算该序列通 过交换数字得到有序序列的最少次数。
6
项目实现 #include <stdio.h> main() { int num[100]; int len; int count=0; int i,j,k,temp; printf("请输入要输入数字的个数:"); scanf("%d",&len); for(i=0;i<len;i++) { scanf("%d",&num[i]); } for(i=0;i<len-1;i++)//求最小值 { k=i; for(j=k+1;j<len;j++) { if(num[j]<num[k]) k=j; } if(i!=k) {
杭电acm练习题100例(删减版)
![杭电acm练习题100例(删减版)](https://img.taocdn.com/s3/m/59a9a0f2c0c708a1284ac850ad02de80d4d806a4.png)
杭电acm练习题100例(删减版)【程序1】题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。
组成所有的排列后再去掉不满足条件的排列。
#include "stdio.h"#include "conio.h"main(){ int i,j,k;printf("\n");for(i=1;i<5;i++) /*以下为三重循环*/for(j=1;j<5;j++)for (k=1;k<5;k++){ if (i!=k&&i!=j&&j!=k) /*确保i、j、k三位互不相同*/printf("%d,%d,%d\n",i,j,k); }getch(); }==============================================================【程序2】题目:企业发放的奖金根据利润提成。
利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?#include "stdio.h" #include "conio.h"main(){ long int i;int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;scanf("%ld",&i);bonus1=100000*0. 1;bonus2=bonus1+100000*0.75;bonus4=bonus2+200000*0.5;bonus6=bonus4+200000*0.3;bonus10=bonus6+400000*0.15;if(i<=100000)bonus=i*0.1;else if(i<=200000)bonus=bonus1+(i-100000)*0.075;else if(i<=400000)bonus=bonus2+(i-200000)*0.05;else if(i<=600000)bonus=bonus4+(i-400000)*0.03;else if(i<=1000000)bonus=bonus6+(i-600000)*0.015;elsebonus=bonus10+(i-1000000)*0.01;printf("bonus=%d",bonus);getch(); }====================================== ========================【程序3】题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?#include "math.h"#include "stdio.h"#include "conio.h"main(){ long int i,x,y,z;for (i=1;i<100000;i++){ x=sqrt(i+100); /*x为加上100后开方后的结果*/y=sqrt(i+268); /*y为再加上168后开方后的结果*/if(x*x==i+100&&y*y==i+268)printf("\n%ld\n",i); }getch(); }====================================== ========================【程序4】题目:输入某年某月某日,判断这一天是这一年的第几天?#include "stdio.h" #include "conio.h"main(){ int day,month,year,sum,leap;printf("\nplease input year,month,day\n");scanf("%d,%d,%d",&year,&month,&day);switch(month) /*先计算某月以前月份的总天数*/{ case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf("data error");break; }sum=sum+day; /*再加上某天的天数*/if(year%400==0||(year%4==0&&year%100!=0)) /*判断是不是闰年*/leap=1;elseleap=0;if(leap==1&&month>2) /*如果是闰年且月份大于2,总天数应该加一天*/sum++;printf("It is the %dth day.",sum);getch(); }====================================== ======================== 【程序5】题目:输入三个整数x,y,z,请把这三个数由小到大输出。
acm程序 循环题目
![acm程序 循环题目](https://img.taocdn.com/s3/m/409b414091c69ec3d5bbfd0a79563c1ec5dad73d.png)
acm程序循环题目
以下是两道常见的 ACM 循环题目:
1. 水桶挑战赛:一个 n 个人组成的队伍在 m 个水桶中轮流取水,每个人只能取一个水桶的水,且每个水桶的水量不同。
要求每个人取水的总时间不超过 t 分钟。
求出每个人取水的最优策略。
2. 循环赛日程表:给定 n 个队伍,需要安排一场循环赛,每个队伍都要与
其他所有队伍进行一场比赛,并且每个队伍只进行一场比赛。
要求找出一种最优的比赛日程表,使得每个队伍等待的时间最短。
这两道题目都是经典的 ACM 循环题目,考察的是循环和动态规划的思想。
在解决这类问题时,需要注意循环的起点和终点,以及循环中每个状态的含义和转移方程。
同时,还需要注意状态压缩和记忆化搜索等优化技巧的使用。
acm大赛试题及答案
![acm大赛试题及答案](https://img.taocdn.com/s3/m/d6b82f68773231126edb6f1aff00bed5b9f37387.png)
acm大赛试题及答案ACM大赛试题及答案1. 题目一:字符串反转问题描述:编写一个程序,输入一个字符串,输出其反转后的字符串。
输入格式:输入包含一个字符串,字符串长度不超过100。
输出格式:输出反转后的字符串。
示例:输入:hello输出:olleh答案:```pythondef reverse_string(s):return s[::-1]input_string = input().strip()print(reverse_string(input_string))```2. 题目二:计算阶乘问题描述:编写一个程序,输入一个非负整数n,输出n的阶乘。
输入格式:输入包含一个非负整数n,n不超过20。
输出格式:输出n的阶乘。
示例:输入:5输出:120答案:```pythondef factorial(n):if n == 0:return 1else:return n * factorial(n - 1)n = int(input())print(factorial(n))```3. 题目三:寻找最大数问题描述:给定一个包含n个整数的数组,找出数组中的最大数。
输入格式:输入包含一个整数n,表示数组的大小,随后是n个整数。
输出格式:输出数组中的最大数。
示例:输入:5 1 2 3 4 5输出:5答案:```pythonn = int(input())numbers = list(map(int, input().split()))max_number = max(numbers)print(max_number)```4. 题目四:判断闰年问题描述:编写一个程序,输入一个年份,判断该年份是否为闰年。
输入格式:输入包含一个整数,表示年份。
输出格式:如果输入的年份是闰年,则输出"Yes",否则输出"No"。
示例:输入:2000输出:Yes答案:```pythonyear = int(input())if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):print("Yes")else:print("No")```5. 题目五:斐波那契数列问题描述:编写一个程序,输入一个非负整数n,输出斐波那契数列的第n项。
ACM经典的题目代码
![ACM经典的题目代码](https://img.taocdn.com/s3/m/8433f22b16fc700abb68fc36.png)
目录一.数论 41.阶乘最后非零位 42. 模线性方程(组) 43. 素数表64. 素数随机判定(miller_rabin) 65. 质因数分解76. 最大公约数欧拉函数8二.图论_匹配91. 二分图最大匹配(hungary邻接表形式) 92. 二分图最大匹配(hungary邻接表形式,邻接阵接口) 103. 二分图最大匹配(hungary邻接阵形式) 104. 二分图最大匹配(hungary正向表形式) 115. 二分图最佳匹配(kuhn_munkras邻接阵形式) 116. 一般图匹配(邻接表形式) 127. 一般图匹配(邻接表形式,邻接阵接口) 138. 一般图匹配(邻接阵形式) 149. 一般图匹配(正向表形式) 15三.图论_生成树161. 最小生成树(kruskal邻接表形式) 162. 最小生成树(kruskal正向表形式) 173. 最小生成树(prim+binary_heap邻接表形式) 194. 最小生成树(prim+binary_heap正向表形式) 205. 最小生成树(prim+mapped_heap邻接表形式) 216. 最小生成树(prim+mapped_heap正向表形式) 227. 最小生成树(prim邻接阵形式) 238. 最小树形图(邻接阵形式) 24四.图论_网络流251. 上下界最大流(邻接表形式) 252. 上下界最大流(邻接阵形式) 263. 上下界最小流(邻接表形式) 274. 上下界最小流(邻接阵形式) 295. 最大流(邻接表形式) 306. 最大流(邻接表形式,邻接阵接口) 317. 最大流(邻接阵形式) 328. 最大流无流量(邻接阵形式) 329. 最小费用最大流(邻接阵形式) 33五. 图论_最短路径341. 最短路径(单源bellman_ford邻接阵形式) 342. 最短路径(单源dijkstra_bfs邻接表形式) 353. 最短路径(单源dijkstra_bfs正向表形式) 354. 最短路径(单源dijkstra+binary_heap邻接表形式) 365. 最短路径(单源dijkstra+binary_heap正向表形式) 376. 最短路径(单源dijkstra+mapped_heap邻接表形式) 387. 最短路径(单源dijkstra+mapped_heap正向表形式) 398. 最短路径(单源dijkstra邻接阵形式) 409. 最短路径(多源floyd_warshall邻接阵形式) 40六. 图论_连通性411. 无向图关键边(dfs邻接阵形式) 412. 无向图关键点(dfs邻接阵形式) 423. 无向图块(bfs邻接阵形式) 434. 无向图连通分支(bfs邻接阵形式) 435. 无向图连通分支(dfs邻接阵形式) 446. 有向图强连通分支(bfs邻接阵形式) 447. 有向图强连通分支(dfs邻接阵形式) 458. 有向图最小点基(邻接阵形式) 46七. 图论_应用461.欧拉回路(邻接阵形式) 462. 前序表转化473. 树的优化算法484. 拓扑排序(邻接阵形式). 495. 最佳边割集506. 最佳顶点割集517. 最小边割集528. 最小顶点割集539. 最小路径覆盖55八. 图论_NP搜索551. 最大团(n小于64)(faster) 552. 最大团58九. 组合591. 排列组合生成592. 生成gray码603. 置换(polya) 614. 字典序全排列615. 字典序组合626. 组合公式62十. 数值计算631. 定积分计算(Romberg) 632. 多项式求根(牛顿法) 643. 周期性方程(追赶法) 66十一. 几何671. 多边形672. 多边形切割703. 浮点函数714. 几何公式765. 面积786. 球面797. 三角形798. 三维几何819. 凸包(graham) 8910. 网格(pick) 9111. 圆9212. 整数函数9413. 注意96十二. 结构971. 并查集972. 并查集扩展(friend_enemy) 983. 堆(binary) 984. 堆(mapped) 995. 矩形切割996. 线段树1007. 线段树扩展1028. 线段树应用1059. 子段和10510. 子阵和105十三. 其他1061. 分数1062. 矩阵1083. 日期1104. 线性方程组(gauss) 1115. 线性相关113十四. 应用1141. joseph 1142. N皇后构造解 1153. 布尔母函数1154. 第k元素1165. 幻方构造1166. 模式匹配(kmp) 1187. 逆序对数1188. 字符串最小表示1199. 最长公共单调子序列11910. 最长子序列12011. 最大子串匹配12112. 最大子段和12213. 最大子阵和123一.数论1.阶乘最后非零位//求阶乘最后非零位,复杂度O(nlogn)//返回该位,n以字符串方式传入#include <string.h>#define MAXN 10000int lastdigit(char* buf){const int mod[20]={1,1,2,6,4,2,2,4,2,8,4,4,8,4,6,8,8,6,8,2};int len=strlen(buf),a[MAXN],i,c,ret=1;if (len==1)return mod[buf[0]-'0'];for (i=0;i<len;i++)a[i]=buf[len-1-i]-'0';for (;len;len-=!a[len-1]){ret=ret*mod[a[1]%2*10+a[0]]%5;for (c=0,i=len-1;i>=0;i--)c=c*10+a[i],a[i]=c/5,c%=5;}return ret+ret%2*5;}2. 模线性方程(组)#ifdef WIN32typedef __int64 i64;#elsetypedef long long i64;#endif//扩展Euclid求解gcd(a,b)=ax+byint ext_gcd(int a,int b,int& x,int& y){int t,ret;if (!b){x=1,y=0;return a;}ret=ext_gcd(b,a%b,x,y);t=x,x=y,y=t-a/b*y;return ret;}//计算m^a, O(loga), 本身没什么用, 注意这个按位处理的方法:-Pint exponent(int m,int a){int ret=1;for (;a;a>>=1,m*=m)if (a&1)ret*=m;return ret;}//计算幂取模a^b mod n, O(logb)int modular_exponent(int a,int b,int n){ //a^b mod nint ret=1;for (;b;b>>=1,a=(int)((i64)a)*a%n)if (b&1)ret=(int)((i64)ret)*a%n;return ret;}//求解模线性方程ax=b (mod n)//返回解的个数,解保存在sol[]中//要求n>0,解的范围0..n-1int modular_linear(int a,int b,int n,int* sol){int d,e,x,y,i;d=ext_gcd(a,n,x,y);if (b%d)return 0;e=(x*(b/d)%n+n)%n;for (i=0;i<d;i++)sol[i]=(e+i*(n/d))%n;return d;}//求解模线性方程组(中国余数定理)// x = b[0] (mod w[0])// x = b[1] (mod w[1])// ...// x = b[k-1] (mod w[k-1])//要求w[i]>0,w[i]与w[j]互质,解的范围1..n,n=w[0]*w[1]*...*w[k-1]int modular_linear_system(int b[],int w[],int k){int d,x,y,a=0,m,n=1,i;for (i=0;i<k;i++)n*=w[i];for (i=0;i<k;i++){m=n/w[i];d=ext_gcd(w[i],m,x,y);a=(a+y*m*b[i])%n;}return (a+n)%n;}3. 素数表//用素数表判定素数,先调用initprimeint plist[10000],pcount=0;int prime(int n){int i;if((n!=2&&!(n%2))||(n!=3&&!(n%3))||(n!=5&&!(n%5))||(n!=7&&! (n%7)))return 0;for (i=0;plist[i]*plist[i]<=n;i++)if (!(n%plist[i]))return 0;return n>1;}void initprime(){int i;for (plist[pcount++]=2,i=3;i<50000;i++)if (prime(i))plist[pcount++]=i;}4. 素数随机判定(miller_rabin)//miller rabin//判断自然数n是否为素数//time越高失败概率越低,一般取10到50#include <stdlib.h>#ifdef WIN32typedef __int64 i64;#elsetypedef long long i64;#endifint modular_exponent(int a,int b,int n){ //a^b mod nint ret;for (;b;b>>=1,a=(int)((i64)a)*a%n)if (b&1)ret=(int)((i64)ret)*a%n;return ret;}// Carmicheal number: 561,41041,,int miller_rabin(int n,int time=10){if(n==1||(n!=2&&!(n%2))||(n!=3&&!(n%3))||(n!=5&&!(n%5))||(n!= 7&&!(n%7)))return 0;while (time--)if(modular_exponent(((rand()&0x7fff<<16)+rand()&0x7fff+rand() &0x7fff)%(n-1)+1,n-1,n)!=1)return 0;return 1;}5. 质因数分解//分解质因数//prime_factor()传入n, 返回不同质因数的个数//f存放质因数,nf存放对应质因数的个数//先调用initprime(),其中第二个initprime()更快#include<iostream>#include<cstdio>#include<cmath>using namespace std;#define MAXN#define PSIZEint plist[PSIZE], pcount=0;int prime(int n){int i;if((n!=2&&!(n%2))||(n!=3&&!(n%3))||(n!=5&&!(n%5))||(n!=7&&! (n%7)))return 0;for (i=0;plist[i]*plist[i]<=n;++i)if (!(n%plist[i]))return 0;return n>1;}void initprime(){int i;for (plist[pcount++]=2,i=3;i<;++i)if (prime(i))plist[pcount++]=i;}int prime_factor(int n, int* f, int *nf) {int cnt = 0;int n2 = sqrt((double)n);for(int i = 0; n > 1 && plist[i] <= n2; ++i)if (n % plist[i] == 0) {for (nf[cnt] = 0; n % plist[i] == 0; ++nf[cnt], n /= plist[i]);f[cnt++] = plist[i];}if (n > 1) nf[cnt] = 1, f[cnt++] = n;return cnt;}/*//产生MAXN以内的所有素数//note:就是//给所有2的倍数赋初值#include <cmath>#include <iostream>using namespace std;#define MAXNunsigned int plist[],pcount;unsigned int isprime[(MAXN>>5)+1];#define setbitzero(a) (isprime[(a)>>5]&=(~(1<<((a)&31))))#define setbitone(a) (isprime[(a)>>5]|=(1<<((a)&31)))#define ISPRIME(a) (isprime[(a)>>5]&(1<<((a)&31)))void initprime(){int i,j,m;int t=(MAXN>>5)+1;for(i=0;i<t;++i)isprime[i]=;plist[0]=2;setbitone(2);setbitzero(1);m=(int)sqrt(MAXN);for(pcount=1,i=3;i<=m;i+=2)if(ISPRIME(i))for(plist[pcount++]=i,j=i<<1;j<=MAXN;j+=i)setbitzero(j);if(!(i&1))++i;for(;i<=MAXN;i+=2)if(ISPRIME(i))plist[pcount++]=i;}6. 最大公约数欧拉函数int gcd(int a,int b){return b?gcd(b,a%b):a;}inline int lcm(int a,int b){return a/gcd(a,b)*b;}//求1..n-1中与n互质的数的个数int eular(int n){int ret=1,i;for (i=2;i*i<=n;i++)if (n%i==0){n/=i,ret*=i-1;while (n%i==0)n/=i,ret*=i;}if (n>1)ret*=n-1;return ret;}二.图论_匹配1. 二分图最大匹配(hungary邻接表形式)//二分图最大匹配,hungary算法,邻接表形式,复杂度O(m*e)//返回最大匹配数,传入二分图大小m,n和邻接表list(只需一边) //match1,match2返回一个最大匹配,未匹配顶点match值为-1 #include <string.h>#define MAXN 310#define _clr(x) memset(x,0xff,sizeof(int)*MAXN)struct edge_t{int from,to;edge_t* next;};int hungary(int m,int n,edge_t* list[],int* match1,int* match2){ int s[MAXN],t[MAXN],p,q,ret=0,i,j,k;edge_t* e;for(_clr(match1),_clr(match2),i=0;i<m;ret+=(match1[i++]>=0))for (_clr(t),s[p=q=0]=i;p<=q&&match1[i]<0;p++)for (e=list[k=s[p]];e&&match1[i]<0;e=e->next)if (t[j=e->to]<0){s[++q]=match2[j],t[j]=k;if (s[q]<0)for (p=j;p>=0;j=p)match2[j]=k=t[j],p=match1[k],match1[k]=j;}return ret; }2. 二分图最大匹配(hungary邻接表形式,邻接阵接口)//二分图最大匹配,hungary算法,邻接表形式,邻接阵接口,复杂度O(m*e)s//返回最大匹配数,传入二分图大小m,n和邻接阵//match1,match2返回一个最大匹配,未匹配顶点match值为-1 #include <string.h>#include <vector>#define MAXN 310#define _clr(x) memset(x,0xff,sizeof(int)*MAXN)int hungary(int m,int n,int mat[][MAXN],int* match1,int*match2){int s[MAXN],t[MAXN],p,q,ret=0,i,j,k,r;vector<int> e[MAXN];//生成邻接表(只需一边)for(i=0;i<m;++i)for(j=0;j<n;++j)if (mat[i][j]) e[i].push_back(j);for(_clr(match1),_clr(match2),i=0;i<m;ret+=(match1[i++]>=0))for (_clr(t),s[p=q=0]=i;p<=q&&match1[i]<0;p++)for(r=0,k=s[p];r<e[k].size()&&match1[i]<0;++r)if (t[j=e[k][r]]<0){s[++q]=match2[j],t[j]=k;if (s[q]<0)for (p=j;p>=0;j=p)match2[j]=k=t[j],p=match1[k],match1[k]=j;}return ret;}3. 二分图最大匹配(hungary邻接阵形式)//二分图最大匹配,hungary算法,邻接阵形式,复杂度O(m*m*n) //返回最大匹配数,传入二分图大小m,n和邻接阵mat,非零元素表示有边//match1,match2返回一个最大匹配,未匹配顶点match值为-1 #include <string.h>#define MAXN 310#define _clr(x) memset(x,0xff,sizeof(int)*MAXN)int hungary(int m,int n,int mat[][MAXN],int* match1,int*match2){int s[MAXN],t[MAXN],p,q,ret=0,i,j,k;for(_clr(match1),_clr(match2),i=0;i<m;ret+=(match1[i++]>=0))for (_clr(t),s[p=q=0]=i;p<=q&&match1[i]<0;p++)for (k=s[p],j=0;j<n&&match1[i]<0;j++)if (mat[k][j]&&t[j]<0){s[++q]=match2[j],t[j]=k;if (s[q]<0)for (p=j;p>=0;j=p)match2[j]=k=t[j],p=match1[k],match1[k]=j;}return ret;}4. 二分图最大匹配(hungary正向表形式)//二分图最大匹配,hungary算法,正向表形式,复杂度O(m*e)//返回最大匹配数,传入二分图大小m,n和正向表list,buf(只需一边)//match1,match2返回一个最大匹配,未匹配顶点match值为-1 #include <string.h>#define MAXN 310#define _clr(x) memset(x,0xff,sizeof(int)*MAXN)int hungary(int m,int n,int* list,int* buf,int* match1,int* match2){ int s[MAXN],t[MAXN],p,q,ret=0,i,j,k,l;for(_clr(match1),_clr(match2),i=0;i<m;ret+=(match1[i++]>=0))for (_clr(t),s[p=q=0]=i;p<=q&&match1[i]<0;p++)for(l=list[k=s[p]];l<list[k+1]&&match1[i]<0;l++)if (t[j=buf[l]]<0){s[++q]=match2[j],t[j]=k;if (s[q]<0)for (p=j;p>=0;j=p)match2[j]=k=t[j],p=match1[k],match1[k]=j;}return ret;}5. 二分图最佳匹配(kuhn_munkras邻接阵形式)//二分图最佳匹配,kuhn munkras算法,邻接阵形式,复杂度O(m*m*n)//返回最佳匹配值,传入二分图大小m,n和邻接阵mat,表示权值//match1,match2返回一个最佳匹配,未匹配顶点match值为-1 //一定注意m<=n,否则循环无法终止//最小权匹配可将权值取相反数#include <string.h>#define MAXN 310#define inf#define _clr(x) memset(x,0xff,sizeof(int)*n)int kuhn_munkras(int m,int n,int mat[][MAXN],int* match1,int* match2){ints[MAXN],t[MAXN],l1[MAXN],l2[MAXN],p,q,ret=0,i,j,k;for (i=0;i<m;i++)for (l1[i]=-inf,j=0;j<n;j++)l1[i]=mat[i][j]>l1[i]?mat[i][j]:l1[i];for (i=0;i<n;l2[i++]=0);for (_clr(match1),_clr(match2),i=0;i<m;i++){for (_clr(t),s[p=q=0]=i;p<=q&&match1[i]<0;p++)for (k=s[p],j=0;j<n&&match1[i]<0;j++)if (l1[k]+l2[j]==mat[k][j]&&t[j]<0){s[++q]=match2[j],t[j]=k;if (s[q]<0)for (p=j;p>=0;j=p)match2[j]=k=t[j],p=match1[k],match1[k]=j;}if (match1[i]<0){for (i--,p=inf,k=0;k<=q;k++)for (j=0;j<n;j++)if(t[j]<0&&l1[s[k]]+l2[j]-mat[s[k]][j]<p)p=l1[s[k]]+l2[j]-mat[s[k]][j];for (j=0;j<n;l2[j]+=t[j]<0?0:p,j++);for (k=0;k<=q;l1[s[k++]]-=p);}}for (i=0;i<m;i++)ret+=mat[i][match1[i]];return ret;}6. 一般图匹配(邻接表形式)//一般图最大匹配,邻接表形式,复杂度O(n*e)//返回匹配顶点对数,match返回匹配,未匹配顶点match值为-1 //传入图的顶点数n和邻接表list#define MAXN 100struct edge_t{int from,to;edge_t* next;};int aug(int n,edge_t* list[],int* match,int* v,int now){int t,ret=0;edge_t* e;v[now]=1;for (e=list[now];e;e=e->next)if (!v[t=e->to]){if (match[t]<0)match[now]=t,match[t]=now,ret=1;else{v[t]=1;if (aug(n,list,match,v,match[t]))match[now]=t,match[t]=now,ret=1;v[t]=0;}if (ret)break;}v[now]=0;return ret;}int graph_match(int n,edge_t* list[],int* match){int v[MAXN],i,j;for (i=0;i<n;i++)v[i]=0,match[i]=-1;for (i=0,j=n;i<n&&j>=2;)if (match[i]<0&&aug(n,list,match,v,i))i=0,j-=2;elsei++;for (i=j=0;i<n;i++)j+=(match[i]>=0);return j/2;}7. 一般图匹配(邻接表形式,邻接阵接口)//一般图最大匹配,邻接表形式,复杂度O(n*e)//返回匹配顶点对数,match返回匹配,未匹配顶点match值为-1 //传入图的顶点数n和邻接表list#include <vector>#define MAXN 100int aug(int n,vector<int> list[],int* match,int* v,int now){ int t,ret=0,r;v[now]=1;// for (e=list[now];e;e=e->next)for (r=0;r<list[now].size();++r)if (!v[t=list[now][r]]){if (match[t]<0)match[now]=t,match[t]=now,ret=1;else{v[t]=1;if (aug(n,list,match,v,match[t]))match[now]=t,match[t]=now,ret=1;v[t]=0;}if (ret)break;}v[now]=0;return ret;}int graph_match(int n,int mat[][MAXN],int* match){int v[MAXN],i,j;vector<int> list[MAXN];for (i=0;i<n;i++)for (j=0;j<n;j++)if (mat[i][j]) list[i].push_back(j);for (i=0;i<n;i++)v[i]=0,match[i]=-1;for (i=0,j=n;i<n&&j>=2;)if (match[i]<0&&aug(n,list,match,v,i))i=0,j-=2;elsei++;for (i=j=0;i<n;i++)j+=(match[i]>=0);return j/2;}8. 一般图匹配(邻接阵形式)//一般图最大匹配,邻接阵形式,复杂度O(n^3)//返回匹配顶点对数,match返回匹配,未匹配顶点match值为-1 //传入图的顶点数n和邻接阵mat#define MAXN 100int aug(int n,int mat[][MAXN],int* match,int* v,int now){ int i,ret=0;v[now]=1;for (i=0;i<n;i++)if (!v[i]&&mat[now][i]){if (match[i]<0)match[now]=i,match[i]=now,ret=1;else{v[i]=1;if (aug(n,mat,match,v,match[i]))match[now]=i,match[i]=now,ret=1;v[i]=0;}if (ret)break;}v[now]=0;return ret;}int graph_match(int n,int mat[][MAXN],int* match){int v[MAXN],i,j;for (i=0;i<n;i++)v[i]=0,match[i]=-1;for (i=0,j=n;i<n&&j>=2;)if (match[i]<0&&aug(n,mat,match,v,i))i=0,j-=2;elsei++;for (i=j=0;i<n;i++)j+=(match[i]>=0);return j/2;}9. 一般图匹配(正向表形式)//一般图最大匹配,正向表形式,复杂度O(n*e)//返回匹配顶点对数,match返回匹配,未匹配顶点match值为-1 //传入图的顶点数n和正向表list,buf#define MAXN 100int aug(int n,int* list,int* buf,int* match,int* v,int now){ int i,t,ret=0;v[now]=1;for (i=list[now];i<list[now+1];i++)if (!v[t=buf[i]]){if (match[t]<0)match[now]=t,match[t]=now,ret=1;else{v[t]=1;if (aug(n,list,buf,match,v,match[t]))match[now]=t,match[t]=now,ret=1;v[t]=0;}if (ret)break;}v[now]=0;return ret;}int graph_match(int n,int* list,int* buf,int* match){int v[MAXN],i,j;for (i=0;i<n;i++)v[i]=0,match[i]=-1;for (i=0,j=n;i<n&&j>=2;)if (match[i]<0&&aug(n,list,buf,match,v,i))i=0,j-=2;elsei++;for (i=j=0;i<n;i++)j+=(match[i]>=0);return j/2;}三.图论_生成树1. 最小生成树(kruskal邻接表形式)//无向图最小生成树,kruskal算法,邻接表形式,复杂度O(mlogm) //返回最小生成树的长度,传入图的大小n和邻接表list//可更改边权的类型,edge[][2]返回树的构造,用边集表示//如果图不连通,则对各连通分支构造最小生成树,返回总长度#include <string.h>#define MAXN 200#define inftypedef double elem_t;struct edge_t{int from,to;elem_t len;edge_t* next;};#define _ufind_run(x) for(;p[t=x];x=p[x],p[t]=(p[x]?p[x]:x))#define _run_both _ufind_run(i);_ufind_run(j)struct ufind{int p[MAXN],t;void init(){memset(p,0,sizeof(p));}void set_friend(int i,int j){_run_both;p[i]=(i==j?0:j);}int is_friend(int i,int j){_run_both;return i==j&&i;}};#define _cp(a,b) ((a).len<(b).len)struct heap_t{int a,b;elem_t len;};struct minheap{heap_t h[MAXN*MAXN];int n,p,c;void init(){n=0;}void ins(heap_t e){for(p=++n;p>1&&_cp(e,h[p>>1]);h[p]=h[p>>1],p>>=1);h[p]=e;}int del(heap_t& e){if (!n) return 0;for(e=h[p=1],c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n ]);h[p]=h[c],p=c,c<<=1);h[p]=h[n--];return 1;}};elem_t kruskal(int n,edge_t* list[],int edge[][2]){ufind u;minheap h;edge_t* t;heap_t e;elem_t ret=0;int i,m=0;u.init(),h.init();for (i=0;i<n;i++)for (t=list[i];t;t=t->next)if (i<t->to)e.a=i,e.b=t->to,e.len=t->len,h.ins(e);while (m<n-1&&h.del(e))if (!u.is_friend(e.a+1,e.b+1))edge[m][0]=e.a,edge[m][1]=e.b,ret+=e.len,u.set_friend(e.a+ 1,e.b+1);return ret;}2. 最小生成树(kruskal正向表形式)//无向图最小生成树,kruskal算法,正向表形式,复杂度O(mlogm) //返回最小生成树的长度,传入图的大小n和正向表list,buf//可更改边权的类型,edge[][2]返回树的构造,用边集表示//如果图不连通,则对各连通分支构造最小生成树,返回总长度#include <string.h>#define MAXN 200#define inftypedef double elem_t;struct edge_t{int to;elem_t len;};#define _ufind_run(x) for(;p[t=x];x=p[x],p[t]=(p[x]?p[x]:x))#define _run_both _ufind_run(i);_ufind_run(j)struct ufind{int p[MAXN],t;void init(){memset(p,0,sizeof(p));}void set_friend(int i,int j){_run_both;p[i]=(i==j?0:j);}int is_friend(int i,int j){_run_both;return i==j&&i;}};#define _cp(a,b) ((a).len<(b).len)struct heap_t{int a,b;elem_t len;};struct minheap{heap_t h[MAXN*MAXN];int n,p,c;void init(){n=0;}void ins(heap_t e){for(p=++n;p>1&&_cp(e,h[p>>1]);h[p]=h[p>>1],p>>=1);h[p]=e;}int del(heap_t& e){if (!n) return 0;for(e=h[p=1],c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n ]);h[p]=h[c],p=c,c<<=1);h[p]=h[n--];return 1;}};elem_t kruskal(int n,int* list,edge_t* buf,int edge[][2]){ ufind u;minheap h;heap_t e;elem_t ret=0;int i,j,m=0;u.init(),h.init();for (i=0;i<n;i++)for (j=list[i];j<list[i+1];j++)if (i<buf[j].to)e.a=i,e.b=buf[j].to,e.len=buf[j].len,h.ins(e);while (m<n-1&&h.del(e))if (!u.is_friend(e.a+1,e.b+1))edge[m][0]=e.a,edge[m][1]=e.b,ret+=e.len,u.set_friend(e.a+ 1,e.b+1);return ret;}3. 最小生成树(prim+binary_heap邻接表形式)//无向图最小生成树,prim算法+二分堆,邻接表形式,复杂度O(mlogm)//返回最小生成树的长度,传入图的大小n和邻接表list//可更改边权的类型,pre[]返回树的构造,用父结点表示,根节点(第一个)pre值为-1//必须保证图的连通的!#define MAXN 200#define inftypedef double elem_t;struct edge_t{int from,to;elem_t len;edge_t* next;};#define _cp(a,b) ((a).d<(b).d)struct heap_t{elem_t d;int v;};struct heap{heap_t h[MAXN*MAXN];int n,p,c;void init(){n=0;}void ins(heap_t e){for(p=++n;p>1&&_cp(e,h[p>>1]);h[p]=h[p>>1],p>>=1);h[p]=e;}int del(heap_t& e){if (!n) return 0;for(e=h[p=1],c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n ]);h[p]=h[c],p=c,c<<=1);h[p]=h[n--];return 1;}};elem_t prim(int n,edge_t* list[],int* pre){heap h;elem_t min[MAXN],ret=0;edge_t* t;heap_t e;int v[MAXN],i;for (i=0;i<n;i++)min[i]=inf,v[i]=0,pre[i]=-1;h.init();e.v=0,e.d=0,h.ins(e);while (h.del(e))if (!v[e.v])for (v[e.v]=1,ret+=e.d,t=list[e.v];t;t=t->next)if (!v[t->to]&&t->len<min[t->to])pre[t->to]=t->from,min[e.v=t->to]=e.d=t->len,h.ins(e);return ret;}4. 最小生成树(prim+binary_heap正向表形式)//无向图最小生成树,prim算法+二分堆,正向表形式,复杂度O(mlogm)//返回最小生成树的长度,传入图的大小n和正向表list,buf//可更改边权的类型,pre[]返回树的构造,用父结点表示,根节点(第一个)pre值为-1//必须保证图的连通的!#define MAXN 200#define inftypedef double elem_t;struct edge_t{int to;elem_t len;};#define _cp(a,b) ((a).d<(b).d)struct heap_t{elem_t d;int v;};struct heap{heap_t h[MAXN*MAXN];int n,p,c;void init(){n=0;}void ins(heap_t e){for(p=++n;p>1&&_cp(e,h[p>>1]);h[p]=h[p>>1],p>>=1);h[p]=e;}int del(heap_t& e){if (!n) return 0;for(e=h[p=1],c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n ]);h[p]=h[c],p=c,c<<=1);h[p]=h[n--];return 1;}};elem_t prim(int n,int* list,edge_t* buf,int* pre){heap h;heap_t e;elem_t min[MAXN],ret=0;int v[MAXN],i,j;for (i=0;i<n;i++)min[i]=inf,v[i]=0,pre[i]=-1;h.init();e.v=0,e.d=0,h.ins(e);while (h.del(e))if (!v[i=e.v])for (v[i]=1,ret+=e.d,j=list[i];j<list[i+1];j++)if(!v[buf[j].to]&&buf[j].len<min[buf[j].to])pre[buf[j].to]=i,min[e.v=buf[j].to]=e.d=buf[j].len,h.ins(e);return ret;}5. 最小生成树(prim+mapped_heap邻接表形式)//无向图最小生成树,prim算法+映射二分堆,邻接表形式,复杂度O(mlogn)//返回最小生成树的长度,传入图的大小n和邻接表list//可更改边权的类型,pre[]返回树的构造,用父结点表示,根节点(第一个)pre值为-1//必须保证图的连通的!#define MAXN 200#define inftypedef double elem_t;struct edge_t{int from,to;elem_t len;edge_t* next;};#define _cp(a,b) ((a)<(b))struct heap{elem_t h[MAXN+1];int ind[MAXN+1],map[MAXN+1],n,p,c;void init(){n=0;}void ins(int i,elem_t e){for(p=++n;p>1&&_cp(e,h[p>>1]);h[map[ind[p]=ind[p>>1]]=p]=h[p >>1],p>>=1);h[map[ind[p]=i]=p]=e;}int del(int i,elem_t& e){i=map[i];if (i<1||i>n) return 0;for(e=h[p=i];p>1;h[map[ind[p]=ind[p>>1]]=p]=h[p>>1],p>>=1);for(c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n]);h[map[i nd[p]=ind[c]]=p]=h[c],p=c,c<<=1);h[map[ind[p]=ind[n]]=p]=h[n];n--;return 1;}int delmin(int& i,elem_t& e){if (n<1) return 0;i=ind[1];for(e=h[p=1],c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n ]);h[map[ind[p]=ind[c]]=p]=h[c],p=c,c<<=1);h[map[ind[p]=ind[n]]=p]=h[n];n--;return 1;}};elem_t prim(int n,edge_t* list[],int* pre){heap h;elem_t min[MAXN],ret=0,e;edge_t* t;int v[MAXN],i;for (h.init(),i=0;i<n;i++)min[i]=(i?inf:0),v[i]=0,pre[i]=-1,h.ins(i,min[i]);while (h.delmin(i,e))for (v[i]=1,ret+=e,t=list[i];t;t=t->next)if (!v[t->to]&&t->len<min[t->to])pre[t->to]=t->from,h.del(t->to,e),h.ins(t->to,min[t->to]=t->l en);return ret; }6. 最小生成树(prim+mapped_heap正向表形式)//无向图最小生成树,prim算法+映射二分堆,正向表形式,复杂度O(mlogn)//返回最小生成树的长度,传入图的大小n和正向表list,buf//可更改边权的类型,pre[]返回树的构造,用父结点表示,根节点(第一个)pre值为-1//必须保证图的连通的!#define MAXN 200#define inftypedef double elem_t;struct edge_t{int to;elem_t len;};#define _cp(a,b) ((a)<(b))struct heap{elem_t h[MAXN+1];int ind[MAXN+1],map[MAXN+1],n,p,c;void init(){n=0;}void ins(int i,elem_t e){for(p=++n;p>1&&_cp(e,h[p>>1]);h[map[ind[p]=ind[p>>1]]=p]=h[p >>1],p>>=1);h[map[ind[p]=i]=p]=e;}int del(int i,elem_t& e){i=map[i];if (i<1||i>n) return 0;for(e=h[p=i];p>1;h[map[ind[p]=ind[p>>1]]=p]=h[p>>1],p>>=1);for(c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n]);h[map[i nd[p]=ind[c]]=p]=h[c],p=c,c<<=1);h[map[ind[p]=ind[n]]=p]=h[n];n--;return 1;}int delmin(int& i,elem_t& e){if (n<1) return 0;i=ind[1];for(e=h[p=1],c=2;c<n&&_cp(h[c+=(c<n-1&&_cp(h[c+1],h[c]))],h[n ]);h[map[ind[p]=ind[c]]=p]=h[c],p=c,c<<=1);h[map[ind[p]=ind[n]]=p]=h[n];n--;return 1;}};elem_t prim(int n,int* list,edge_t* buf,int* pre){heap h;elem_t min[MAXN],ret=0,e;int v[MAXN],i,j;for (h.init(),i=0;i<n;i++)min[i]=(i?inf:0),v[i]=0,pre[i]=-1,h.ins(i,min[i]);while (h.delmin(i,e))for (v[i]=1,ret+=e,j=list[i];j<list[i+1];j++)if (!v[buf[j].to]&&buf[j].len<min[buf[j].to]) pre[buf[j].to]=i,h.del(buf[j].to,e),h.ins(buf[j].to,min[buf[j].to ]=buf[j].len);return ret;}7. 最小生成树(prim邻接阵形式)//无向图最小生成树,prim算法,邻接阵形式,复杂度O(n^2)//返回最小生成树的长度,传入图的大小n和邻接阵mat,不相邻点边权inf//可更改边权的类型,pre[]返回树的构造,用父结点表示,根节点(第一个)pre值为-1//必须保证图的连通的!#define MAXN 200#define inftypedef double elem_t;elem_t prim(int n,elem_t mat[][MAXN],int* pre){elem_t min[MAXN],ret=0;int v[MAXN],i,j,k;for (i=0;i<n;i++)min[i]=inf,v[i]=0,pre[i]=-1;for (min[j=0]=0;j<n;j++){for (k=-1,i=0;i<n;i++)if (!v[i]&&(k==-1||min[i]<min[k]))k=i;for (v[k]=1,ret+=min[k],i=0;i<n;i++)if (!v[i]&&mat[k][i]<min[i])min[i]=mat[pre[i]=k][i];}return ret;}8. 最小树形图(邻接阵形式)//多源最小树形图,edmonds算法,邻接阵形式,复杂度O(n^3)//返回最小生成树的长度,构造失败返回负值//传入图的大小n和邻接阵mat,不相邻点边权inf//可更改边权的类型,pre[]返回树的构造,用父结点表示//传入时pre[]数组清零,用-1标出源点#include <string.h>#define MAXN 120#define inftypedef int elem_t;elem_t edmonds(int n,elem_t mat[][MAXN*2],int* pre){ elem_t ret=0;intc[MAXN*2][MAXN*2],l[MAXN*2],p[MAXN*2],m=n,t,i,j,k;for (i=0;i<n;l[i]=i,i++);do{memset(c,0,sizeof(c)),memset(p,0xff,sizeof(p));for (t=m,i=0;i<m;c[i][i]=1,i++);for (i=0;i<t;i++)if (l[i]==i&&pre[i]!=-1){for (j=0;j<m;j++)if(l[j]==j&&i!=j&&mat[j][i]<inf&&(p[i]==-1||mat[j][i]<mat[p[i]][i ]))p[i]=j;if ((pre[i]=p[i])==-1)return -1;if (c[i][p[i]]){for(j=0;j<=m;mat[j][m]=mat[m][j]=inf,j++);for (k=i;l[k]!=m;l[k]=m,k=p[k])for (j=0;j<m;j++)if (l[j]==j){if(mat[j][k]-mat[p[k]][k]<mat[j][m])mat[j][m]=mat[j][k]-mat[p[k]][k];if(mat[k][j]<mat[m][j])mat[m][j]=mat[k][j];}c[m][m]=1,l[m]=m,m++;}for (j=0;j<m;j++)if (c[i][j])for(k=p[i];k!=-1&&l[k]==k;c[k][j]=1,k=p[k]);}}while (t<m);for (;m-->n;pre[k]=pre[m])for (i=0;i<m;i++)if (l[i]==m){for (j=0;j<m;j++)if(pre[j]==m&&mat[i][j]==mat[m][j])pre[j]=i;if(mat[pre[m]][m]==mat[pre[m]][i]-mat[pre[i]][i])k=i;}for (i=0;i<n;i++)if (pre[i]!=-1)ret+=mat[pre[i]][i];return ret;}四.图论_网络流1. 上下界最大流(邻接表形式)//求上下界网络最大流,邻接表形式//返回最大流量,-1表示无可行流,flow返回每条边的流量//传入网络节点数n,容量mat,流量下界bf,源点source,汇点sink //MAXN应比最大结点数多2,无可行流返回-1时mat未复原! #define MAXN 100#define infint _max_flow(int n,int mat[][MAXN],int source,int sink,intflow[][MAXN]){int pre[MAXN],que[MAXN],d[MAXN],p,q,t,i,j,r;vector<int> e[MAXN];for (i=0;i<n;i++)for (e[i].clear(),j=0;j<n;j++)if (mat[i][j]) e[i].push_back(j),e[j].push_back(i);for (;;){for (i=0;i<n;pre[i++]=0);pre[t=source]=source+1,d[t]=inf;for (p=q=0;p<=q&&!pre[sink];t=que[p++])for (r=0;r<e[t].size();++r){i=e[t][r];if (!pre[i]&&(j=mat[t][i]-flow[t][i])) pre[que[q++]=i]=t+1,d[i]=d[t]<j?d[t]:j;else if (!pre[i]&&(j=flow[i][t]))pre[que[q++]=i]=-t-1,d[i]=d[t]<j?d[t]:j;}if (!pre[sink]) break;for (i=sink;i!=source;)if (pre[i]>0)flow[pre[i]-1][i]+=d[sink],i=pre[i]-1;elseflow[i][-pre[i]-1]-=d[sink],i=-pre[i]-1;}for (j=i=0;i<n;j+=flow[source][i++]);return j;}int limit_max_flow(int n,int mat[][MAXN],int bf[][MAXN],int source,int sink,int flow[][MAXN]){int i,j,sk,ks;if (source==sink) return inf;for(mat[n][n+1]=mat[n+1][n]=mat[n][n]=mat[n+1][n+1]=i=0;i<n;i+ +)for(mat[n][i]=mat[i][n]=mat[n+1][i]=mat[i][n+1]=j=0;j<n;j++) mat[i][j]-=bf[i][j],mat[n][i]+=bf[j][i],mat[i][n+1]+=bf[i][j];sk=mat[source][sink],ks=mat[sink][source],mat[source][sink ]=mat[sink][source]=inf;for (i=0;i<n+2;i++)for (j=0;j<n+2;flow[i][j++]=0);_max_flow(n+2,mat,n,n+1,flow);for (i=0;i<n;i++)if (flow[n][i]<mat[n][i]) return -1;flow[source][sink]=flow[sink][source]=0,mat[source][sink] =sk,mat[sink][source]=ks;_max_flow(n,mat,source,sink,flow);for (i=0;i<n;i++)for (j=0;j<n;j++)mat[i][j]+=bf[i][j],flow[i][j]+=bf[i][j];for (j=i=0;i<n;j+=flow[source][i++]);return j;}2. 上下界最大流(邻接阵形式)//求上下界网络最大流,邻接阵形式//返回最大流量,-1表示无可行流,flow返回每条边的流量//传入网络节点数n,容量mat,流量下界bf,源点source,汇点sink //MAXN应比最大结点数多2,无可行流返回-1时mat未复原! #define MAXN 100#define inf void _max_flow(int n,int mat[][MAXN],int source,int sink,int flow[][MAXN]){int pre[MAXN],que[MAXN],d[MAXN],p,q,t,i,j;for (;;){for (i=0;i<n;pre[i++]=0);pre[t=source]=source+1,d[t]=inf;for (p=q=0;p<=q&&!pre[sink];t=que[p++])for (i=0;i<n;i++)if (!pre[i]&&j=mat[t][i]-flow[t][i]) pre[que[q++]=i]=t+1,d[i]=d[t]<j?d[t]:j;else if (!pre[i]&&j=flow[i][t])pre[que[q++]=i]=-t-1,d[i]=d[t]<j?d[t]:j;if (!pre[sink]) break;for (i=sink;i!=source;)if (pre[i]>0)flow[pre[i]-1][i]+=d[sink],i=pre[i]-1;elseflow[i][-pre[i]-1]-=d[sink],i=-pre[i]-1;}}int limit_max_flow(int n,int mat[][MAXN],int bf[][MAXN],int source,int sink,int flow[][MAXN]){int i,j,sk,ks;if (source==sink) return inf;for(mat[n][n+1]=mat[n+1][n]=mat[n][n]=mat[n+1][n+1]=i=0;i<n;i+ +)for(mat[n][i]=mat[i][n]=mat[n+1][i]=mat[i][n+1]=j=0;j<n;j++) mat[i][j]-=bf[i][j],mat[n][i]+=bf[j][i],mat[i][n+1]+=bf[i][j];sk=mat[source][sink],ks=mat[sink][source],mat[source][sink ]=mat[sink][source]=inf;for (i=0;i<n+2;i++)for (j=0;j<n+2;flow[i][j++]=0);_max_flow(n+2,mat,n,n+1,flow);for (i=0;i<n;i++)if (flow[n][i]<mat[n][i]) return -1;flow[source][sink]=flow[sink][source]=0,mat[source][sink] =sk,mat[sink][source]=ks;_max_flow(n,mat,source,sink,flow);for (i=0;i<n;i++)for (j=0;j<n;j++)mat[i][j]+=bf[i][j],flow[i][j]+=bf[i][j];for (j=i=0;i<n;j+=flow[source][i++]);return j;}3. 上下界最小流(邻接表形式)//求上下界网络最小流,邻接阵形式//返回最大流量,-1表示无可行流,flow返回每条边的流量//传入网络节点数n,容量mat,流量下界bf,源点source,汇点sink //MAXN应比最大结点数多2,无可行流返回-1时mat未复原! #define MAXN 100#define inf。
杭电OJ:1089----1096(c++)(ACM入门第一步:所有的输入输出格式)
![杭电OJ:1089----1096(c++)(ACM入门第一步:所有的输入输出格式)](https://img.taocdn.com/s3/m/83ee535d2f3f5727a5e9856a561252d380eb20b8.png)
杭电OJ:1089----1096(c++)(ACM⼊门第⼀步:所有的输⼊输出格式)1089:输⼊输出练习的A + B(I)问题描述您的任务是计算a + b。
太容易了?!当然!我专门为ACM初学者设计了这个问题。
您⼀定已经发现某些问题与此标题具有相同的名称,是的,所有这些问题都是出于相同的⽬的⽽设计的。
输⼊项输⼊将由⼀系列由空格隔开的整数对a和b组成,每⾏⼀对整数。
输出量对于每对输⼊整数a和b,应该在⼀⾏中输出a和b的总和,并且在输⼊中每⾏输出⼀⾏。
样本输⼊1 5 10 20样本输出6 30题解:#include<cstdio>#include<iostream>using namespace std;int main(){int a, b,sum;while(cin >> a >> b){sum = a+b;cout << sum << endl;}return 0;}1090:投⼊产出练习的A + B(II)问题描述您的任务是计算a + b。
输⼊项输⼊的第⼀⾏包含⼀个整数N,然后是N⾏。
每⾏由⼀对整数a和b组成,每对之间⽤空格隔开,每⾏⼀对整数。
输出量对于每对输⼊整数a和b,应该在⼀⾏中输出a和b的总和,并且在输⼊中每⾏输出⼀⾏。
样本输⼊2 1 5 10 20样本输出6 30题解:#include<cstdio>#include<iostream>using namespace std;int a,b,n,sum;cin >> n;while (n){cin >> a >> b;sum = a + b;cout << sum << endl;n--;}return 0;}1091:投⼊产出练习的A + B(III)问题描述您的任务是计算a + b。
杭电acm题目水题英文题目、翻译及ac源代码
![杭电acm题目水题英文题目、翻译及ac源代码](https://img.taocdn.com/s3/m/b5ccc003f78a6529647d5345.png)
1040 As Easy As A+BTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 26015 Accepted Submission(s): 11054Problem DescriptionThese days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.Give you some integers, your task is to sort these number ascending (升序).You should know how easy the problem is now!Good luck!InputInput contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in the same line.It is guarantied that all integers are in the range of 32-int.OutputFor each case, print the sorting result, and one line one case.问题描述这些天来,我在思考一个问题,我怎样才能得到一个简单的问题,因为A + B?这是相当困难做这样的事情。
杭州电子科技大学acm答案
![杭州电子科技大学acm答案](https://img.taocdn.com/s3/m/a27f36757fd5360cba1adbe6.png)
else s1+=i*i*i; } cout<<s2<<" "<<s1<<endl; } return 0;
} 题解:输入的两个区间 大小不一定
2008 数值统计
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20378 Accepted Submission(s): 10783
正确代码:
#include<iostream> #include<cmath> #include<iomanip> #define PI 3.1415927 using namespace std; int main() {
double r,v; while(cin>>r) { v=4*PI*r*r*r/3;
Problem Description
统计给定的 n 个数中,负数、零和正数的个数。
Input
输入数据有多组,每组占一行,每行的第一个数是整数 n(n<100),表示需要统计的数值的个数,然 后是 n 个实数;如果 n=0,则表示输入结束,该行不做处理。
Output
对于每组输入数据,输出一行 a,b 和 c,分别表示给定的数据中负数、零和正数的个数。
Sample Input
6 0 1 2 3 -1 0 5 1 2 3 4 0.5 0
杭电OJ水题答案2
![杭电OJ水题答案2](https://img.taocdn.com/s3/m/def9fd12a8114431b90dd8fb.png)
Hdu 2000#include<stdio.h>void main(){char a,b,c,t;while(scanf("%c%c%c",&a,&b,&c)>0){if(a>b) t=a,a=b,b=t;if(a>c) t=c,c=a,a=t;if(c>a && c<b) t=b,b=c,c=t;scanf("%*c",&a);printf("%c %c %c\n",a,b,c);}}Hdu 2001#include <stdio.h>#include <math.h>int main(){double x1;double x2;double y1;double y2;while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF){double num=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));printf("%.2lf\n",num);}return 0;}Hdu 2002#include<stdio.h>int main(){double pi=3.1415927;double r;while (scanf("%lf",&r)==1)printf("%.3lf\n",((pi*r*r*r)*4)/3);}Hdu 2003#include <stdio.h>#include <math.h>int main(){double x;while (scanf("%lf",&x)==1)printf("%.2lf\n",fabs(x));return 0;}Hdu 2004#include<stdio.h>void main(){double x;while(scanf("%lf",&x)==1)if(x>100||x<0)printf("Score is error!\n");else if(0<x&&x<60) printf("E\n");else if(60<=x&&x<70) printf("D\n");else if(70<=x&&x<80)printf("C\n");else if(80<=x&&x<90)printf("B\n");elseprintf("A\n");}Hdu 2005#include<stdio.h>void main(){int y,m,d,sum=0;while(scanf("%d/%d/%d",&y,&m,&d)!=EOF){if((y%100==0&&y%400==0)||(y%100!=0&&y%4==0)){switch(m=13-m){case 1: sum=sum+30;case 2: sum=sum+31;case 3: sum=sum+30;case 4: sum=sum+31;case 5: sum=sum+31;case 6: sum=sum+30;case 7: sum=sum+31;case 8: sum=sum+30;case 9: sum=sum+31;case 10: sum=sum+29;case 11: sum=sum+31;}}else{switch(m=13-m){case 1: sum=sum+30;case 2: sum=sum+31;case 3: sum=sum+30;case 4: sum=sum+31;case 5: sum=sum+31;case 6: sum=sum+30;case 7: sum=sum+31;case 8: sum=sum+30;case 9: sum=sum+31;case 10: sum=sum+28;case 11: sum=sum+31;}}printf("%d\n",sum+d);sum=0;}}#include<stdio.h>void main(){int n,i,a,sum=1;while(scanf("%d",&n)!=EOF){for(i=1;i<=n;i++){scanf("%d",&a);if(a%2==1)sum*=a;}printf("%d\n",sum);sum=1;}}Hdu 2007#include<stdio.h>void main(){int a,b,x=0,y=0,t;while(scanf("%d%d",&a,&b)!=EOF){if(b<a) { t=a; a=b; b=t;goto m;}else{m:{ while(a<=b){if(a%2==0) { x=a*a+x;a++;}else { y=a*a*a+y; a++;}}}printf("%d %d\n",x,y);x=0; y=0;}}}#include<stdio.h>void main(){double a; int i,x=0,y=0,z=0,n;while(scanf("%d",&n)==1){if(n==0)break;else{while(n--){scanf("%lf",&a);if(a<0) {x++;}else if(a==0) {y++;}else {z++;}}}printf("%d %d %d\n",x,y,z);x=0;y=0;z=0;}}Hdu 2009#include<stdio.h>#include<math.h>void main(){double n,m;double sum=0;while (scanf("%lf%lf",&n,&m)==2){for(int i=0;i<m;i++){sum=sum+n;n=sqrt(n);}printf("%.2lf\n",sum);sum=0;}}Hdu 2010#include<stdio.h>void main(){int a,b,i,t,x,y,z,count=0;while(scanf("%d%d",&a,&b)!=EOF){if(a>b) {t=a;a=b,b=t;}if(a<100||b>999) goto m;for(i=a;i<=b;i++){x=(i%100)%10;y=(int(i/10))%10;z=int(i/100);if(x*x*x+y*y*y+z*z*z==i){count+=1;if(count==1)printf("%d",i);else printf(" %d",i);}}m: {if(count>=1) printf("\n");else { printf("no\n");x=0;y=0;z=0; }}count=0;}}Hdu 2011#include<stdio.h>#include<math.h>int main(){int n;double a,i=1.0;double sum=0,b=0;while(scanf("%d",&n)!=EOF){while(n--){scanf("%lf",&a);for(i=1;i<=a;i++){sum=sum+(1/i)*pow(-1.0,i+1);}printf("%.2lf\n",sum);sum=0;}}}Hdu 2012#include<stdio.h>#include<math.h>int fun1(int x){return x*x+x+41;}int fun2(int x){for(int i=2;i<x;i++){if(x%i==0) { return 1;}}return 0;}void main(){int a,b,m,n,t,sum=0;while(scanf("%d %d",&a,&b)!=EOF){if(a==0&&b==0)continue;else if(a>b){t=a;a=b;b=t;}{/*if(a>b) { c=a;a=b;b=c;}*/for(int i=a;i<=b;i++){m=fun1(i);n=fun2(m);sum+=n;}if(sum!=0){printf("Sorry\n");}else{printf("OK\n");}sum=0;}}}Hdu 2013#include<stdio.h>#include<math.h>int main(){int x,n;while(scanf("%d",&n)!=EOF){if(n==0) break;n=pow(2,n-1);printf("%d\n",3*n-2);}}Hdu 2014#include<stdio.h>int main(){int n,i;float a[100],sum,max,min;while(scanf("%d",&n)!=EOF){sum=0;for(i=0;i<n;i++)scanf("%f",&a[i]);max=min=a[0];for(i=0;i<n;i++){if(a[i]>max)max=a[i];if(a[i]<min)min=a[i];sum+=a[i];}printf("%.2f\n",(sum-min-max)/(n-2));}}Hdu 2016#include<stdio.h>void main(){int a[99],n,i,min,t=0;while(scanf("%d",&n)!=EOF){if(n==0) break;else{for(i=0;i<n;i++) scanf("%d",&a[i]);min=a[0];for(i=0;i<n;i++){if(a[i]<=min) {min=a[i]; t=i;}}a[t]=a[0]; a[0]=min;}printf("%d",a[0]);for(i=1;i<n;i++)printf(" %d",a[i]);t=0;printf("\n");}}Hdu 2017#include <stdio.h>void main(){int count=0,i,n;char a[1000];scanf("%d",&n);while(n--){ scanf("%s",a);getchar();for(i=0;a[i];i++) //为什么??????{if(a[i]>='0'&&a[i]<='9')count++;}printf("%d\n",count);count=0;}}Hdu 2018#include<stdio.h>int main(){int a[55]={1,2,3};int n,i;while(scanf("%d",&n)==1&&n!=0){for(i=3;i<55;i++)a[i]=a[i-1]+a[i-3];printf("%d\n",a[n-1]);}}Hdu 2019#include<stdio.h>int main(){int a[100];int n,i,k=0,m;while(scanf("%d%d",&n,&m)==2&&(n!=0&&m!=0)) {for(i=0;i<n;i++){scanf("%d",&a[i]);}if(m>=a[n-1]){for(i=0;i<n;i++){printf("%d ",a[i]);}printf("%d\n",m);}else if(m<=a[0]){printf("%d",m);for(i=0;i<n;i++){printf(" %d",a[i]);}printf("\n");}else{for(i=0;i<n;i++){if(a[i]>=m){k=i;break;}}for(i=0;i<k;i++){printf("%d ",a[i]);}printf("%d",m);for(i=k;i<n;i++){printf(" %d",a[i]);}printf("\n");}}}Hdu 2020#include<stdio.h>#include<math.h>int main (){int i,j,t,n,a[100];while(scanf("%d",&n)!=EOF&&n!=0){for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++){for(j=0;j<n-i-1;j++){if(abs(a[j])<abs(a[j+1])){t=a[j];a[j]=a[j+1];a[j+1]=t;}}}printf("%d",a[0]);for(i=1;i<n;i++)printf(" %d",a[i]);printf("\n");}}Hdu 2021#include<stdio.h>int fun(int x){int a=0,b=0,c=0,d=0,e=0,f=0;a=(int)(x/100);b=(int)((x-100*a)/50);c=(int) ((x-100*a-50*b)/10);d=(int)((x-100*a-50*b-10*c)/5);e=(int) ((x-100*a-50*b-10*c-5*d)/2);f=x-100*a-50*b-10*c-5*d-2*e;return a+b+c+d+e+f;}void main(){int n,a[100],sum;while(scanf("%d",&n)!=EOF){if(n==0) break;sum=0;for(int i=0;i<n;i++){scanf("%d",&a[i]);sum+=fun(a[i]);}printf("%d\n",sum);}}Hdu 2025#include<stdio.h>#include<string.h>int main(){char a[100],max;int i,l;while(scanf("%s",a)!=EOF){getchar();l=strlen(a);max=a[0];for(i=1;i<l;i++){if(a[i]>=max){max=a[i];}}for(i=0;i<l;i++){if(a[i]<max)printf("%c",a[i]);if(a[i]==max)printf("%c(max)",a[i]);}printf("\n");}}Hdu 2027#include <stdio.h>void main(){int n,i,a,b,c,d,e,k=0;char f[100];scanf("%d",&n);while(n--){a=b=c=d=e=k=0;scanf("%s",f);getchar();for(i=0;f[i];i++){if(f[i]=='a'||f[i]=='A')a++;if(f[i]=='e'||f[i]=='E')b++;if(f[i]=='i'||f[i]=='I')c++;if(f[i]=='o'||f[i]=='O')d++;if(f[i]=='u'||f[i]=='U')e++;}printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d\n",a,b,c,d,e);if(n) printf("\n"); //重要!!!!!!!!!!!!!!!!!!}}Hdu 2028#include<stdio.h>void main(){int a[100];int i,j,min,max,n,count=0;while(scanf("%d",&n)!=EOF){for(i=0;i<n;i++){min=a[0];max=a[0];scanf("%d",&a[i]);if(a[i]>=max)max=a[i];if(a[i]<=min)min=a[i];}for(j=max;;j++){count=0;for(i=0;i<n;i++)if(j%a[i]==0) count++;if(count==n) break;}printf("%d\n",j);}}Hdu 2029#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){int n,i,m=0,b,j;char a[1000];while(scanf("%d",&n)!=EOF){getchar();for(i=0;i<n;i++){gets(a);b=strlen(a);for(j=0;j<b/2;j++){if(a[j]!=a[b-j-1])m++;}if(m==0)printf("yes\n");elseprintf("no\n");m=0;}}return 0;}Hdu 2030#include<stdio.h>#include<string.h>int main(){int i,j,n,m,count,b;char a[5000];scanf("%d",&b);getchar();while(b--){gets(a); //用gets!!!!!!!count=0;j=strlen(a);for(i=0;i<j;i++){if(a[i]<0)count++;}printf("%d\n",count/2);}}Hdu 2033#include<stdio.h>void main(){int a1,b1,c1,n,i,a2,b2,c2,x,y,z,a3,b3,c3;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d%d%d%d%d%d",&a1,&b1,&c1,&a2,&b2,&c2);c3=(c1+c2)%60; x=(c1+c2-c3)/60;b3=(b1+b2+x)%60; y=(b1+b2+x-b3)/60;a3=a1+a2+y;printf("%d %d %d\n",a3,b3,c3);a1=a2=c1=b1=b2=c2=x=y=z=0;}}Hdu 2035#include <stdio.h>void main(){int n,m,t,i;while(scanf("%d%d",&n,&m)!=EOF){if(n==0&&m==0)break;t=1;for(i=0;i<m;i++){t=t*n;t=t%1000;}printf("%d\n",t);}}Hdu 2039#include<stdio.h>int main(){double a,b,c;int N;scanf("%d",&N);while (scanf("%lf %lf %lf",&a,&b,&c)==3){if(a+b>c&&a+c>b&&b+c>a&&a-b<c&&a-c<b&&b-c<a) printf("YES\n");elseprintf("NO\n");}return 0;}Hdu 2040#include<stdio.h>int fun(int x){int i,sum=0;for(i=1;i<x;i++){if(x%i==0){sum+=i;}}return sum;}int main(){int n,a,b;while(scanf("%d",&n)>0){while(n--){scanf("%d%d",&a,&b);if(fun(a)==b&&fun(b)==a)printf("YES\n");else printf("NO\n");}}}Hdu 2041#include<stdio.h>int main(){double f[40]={1,1};int n,m;for(int i=2;i<40;i++)f[i]=f[i-1]+f[i-2];while(scanf("%d",&n)!=EOF){for(int j=0;j<n;j++){scanf("%d",&m);printf("%.0lf\n",f[m-1]);}}}Hdu 2042#include<stdio.h>int main(){double f[31]={3};int n,m;for(int i=1;i<31;i++)f[i]=2*f[i-1]-2;while(scanf("%d",&n)!=EOF){for(int j=0;j<n;j++){scanf("%d",&m);printf("%.0lf\n",f[m]);}}}Hdu 2043#include<string.h>#include <stdio.h>void main(){int x=0,y=0,z=0,m=0,b,i,n;char a[50];scanf("%d",&n);while(n--){scanf("%s",a);getchar();b=strlen(a);if(strlen(a)>=8&&strlen(a)<=16){for(i=0;i<b;i++){if(a[i]>='A'&&a[i]<='Z')x=1;if(a[i]>='a'&&a[i]<='z')y=1;if(a[i]>='0'&&a[i]<='9')z=1;if(a[i]=='~'||a[i]=='!'||a[i]=='@'||a[i]=='#'||a[i]=='$'||a[i]=='%'||a[i]=='^')m=1;}if(x+y+z+m>=3)printf("YES\n");elseprintf("NO\n");x=y=z=m=0;}elseprintf("NO\n");}}Hdu 2044#include<stdio.h>int main (){__int64 a[50]={0,1,2};int i,n,c,b;while(scanf("%d",&n)!=EOF){while(n--){for(i=3;i<50;i++)a[i]=a[i-1]+a[i-2];scanf("%d%d",&c,&b);printf("%I64d\n",a[b-c]);}}}Hdu 2045#include<stdio.h>int main(){__int64 a[51]={3,6,6};int i,n;while(scanf("%d",&n)!=EOF){for(i=3;i<51;i++){ a[i]=a[i-1]+2*a[i-2]; }printf("%I64d\n",a[n-1]);}}Hdu 2046#include<stdio.h>int main(){double f[51]={1,2,3};int n;for(int i=3;i<51;i++)f[i]=f[i-1]+f[i-2];while(scanf("%d",&n)!=EOF){printf("%.0lf\n",f[n-1]);}return 0;}Hdu 2047#include<stdio.h>int main(){__int64 a[40]={3,8};int i,n;while(scanf("%d",&n)!=EOF){for(i=2;i<40;i++)a[i]=2*(a[i-2]+a[i-1]);printf("%I64d\n",a[n-1]);}}。
(完整word版)杭电ACM试题答案
![(完整word版)杭电ACM试题答案](https://img.taocdn.com/s3/m/d762793276c66137ee0619cb.png)
【杭电ACM1000】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 Output2# include <stdio.h>int main(){int a, b;while(scanf("%d%d", &a, &b)!=EOF)printf("%d\n", a+b);return 0;}【杭电ACM1001】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 Input1 100Sample Output1 5050# include <stdio.h>int main(){int n, i, sum = 0;while(scanf("%d", &n)!=EOF){for(i=1; i<=n; ++i)sum = sum + i;printf("%d\n\n", sum);sum = 0;}return 0;}【杭电ACM1002】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 Input2 1 2 112233445566778899 998877665544332211Sample OutputCase 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110#include<stdio.h>#include<string.h>int shu(char a){return (a-'0');}int main(){char a[1000],b[1000];int num[1001];int n,i,j=1,al,bl,k,t;scanf("%d",&n);while(n--){getchar();if(j!=1)printf("\n");scanf("%s",a);al=strlen(a);scanf("%s",b);bl=strlen(b);k=(al>bl)?al:bl;for(i=0;i<=k;i++)num[i]=0;t=k;for(k;al>0&&bl>0;k--){num[k]+=shu(a[--al])+shu(b[--bl]);if(num[k]/10){num[k-1]++;num[k]%=10;}}while(al>0){num[k--]+=shu(a[--al]);if(num[k+1]/10){num[k]++;num[k+1]%=10;}}while(bl>0){num[k--]+=shu(b[--bl]);if(num[k+1]/10){num[k]++;num[k+1]%=10;}}printf("Case %d:\n",j++);printf("%s + %s = ",a,b);for(i=0;i<=t;i++){if(i==0&&num[i]==0)i++;printf("%d",num[i]);}printf("\n");}return 0;}。
杭电OJ水题答案2
![杭电OJ水题答案2](https://img.taocdn.com/s3/m/5550264814791711cc7917a5.png)
杭电OJ水题答案2 Hdu 2000#include<stdio.h>void main(){char a,b,c,t;while(scanf("%c%c%c",&a,&b,&c)>0){if(a>b) t=a,a=b,b=t;if(a>c) t=c,c=a,a=t;if(c>a && c<b) t=b,b=c,c=t;scanf("%*c",&a);printf("%c %c %c\n",a,b,c);}}Hdu 2001#include <stdio.h>#include <math.h>int main(){double x1;double x2;double y1;double y2;while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF) {double num=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); printf("%.2lf\n",num);}return 0;}Hdu 2002#include<stdio.h>int main(){- 1 -double pi=3.1415927;double r;while (scanf("%lf",&r)==1)printf("%.3lf\n",((pi*r*r*r)*4)/3);}Hdu 2003#include <stdio.h>#include <math.h>int main(){double x;while (scanf("%lf",&x)==1)printf("%.2lf\n",fabs(x));return 0;}Hdu 2004#include<stdio.h>void main(){double x;while(scanf("%lf",&x)==1)if(x>100||x<0)printf("Score is error!\n");else if(0<x&&x<60) printf("E\n"); else if(60<=x&&x<70) printf("D\n"); else if(70<=x&&x<80)printf("C\n");else if(80<=x&&x<90)printf("B\n");elseprintf("A\n");}Hdu 2005#include<stdio.h>void main()- 2 -{int y,m,d,sum=0;while(scanf("%d/%d/%d",&y,&m,&d)!=EOF){if((y%100==0&&y%400==0)||(y%100!=0&&y%4==0)) {switch(m=13-m){case 1: sum=sum+30;case 2: sum=sum+31;case 3: sum=sum+30;case 4: sum=sum+31;case 5: sum=sum+31;case 6: sum=sum+30;case 7: sum=sum+31;case 8: sum=sum+30;case 9: sum=sum+31;case 10: sum=sum+29;case 11: sum=sum+31;}}else{switch(m=13-m){case 1: sum=sum+30; case 2: sum=sum+31; case 3: sum=sum+30; case 4: sum=sum+31; case 5: sum=sum+31; case 6: sum=sum+30; case 7: sum=sum+31; case 8: sum=sum+30; case 9: sum=sum+31; case 10: sum=sum+28; case 11: sum=sum+31; }}printf("%d\n",sum+d); sum=0;}}- 3 -Hdu 2006#include<stdio.h> void main(){int n,i,a,sum=1;while(scanf("%d",&n)!=EOF){for(i=1;i<=n;i++){scanf("%d",&a);if(a%2==1)sum*=a;}printf("%d\n",sum);sum=1;}}Hdu 2007#include<stdio.h>void main(){int a,b,x=0,y=0,t;while(scanf("%d%d",&a,&b)!=EOF) {if(b<a) { t=a; a=b; b=t;goto m;} else{m:{ while(a<=b){if(a%2==0) { x=a*a+x;a++;} else { y=a*a*a+y; a++;}}}printf("%d %d\n",x,y);x=0; y=0;}}}- 4 -Hdu 2008#include<stdio.h>void main(){double a; int i,x=0,y=0,z=0,n; while(scanf("%d",&n)==1){if(n==0)break;else{while(n--){scanf("%lf",&a);if(a<0) {x++;}else if(a==0) {y++;}else {z++;}}}printf("%d %d %d\n",x,y,z);x=0;y=0;z=0;}}Hdu 2009#include<stdio.h>#include<math.h>void main(){double n,m;double sum=0;while (scanf("%lf%lf",&n,&m)==2) {for(int i=0;i<m;i++){sum=sum+n;n=sqrt(n);}printf("%.2lf\n",sum);sum=0;- 5 -}}Hdu 2010#include<stdio.h>void main(){int a,b,i,t,x,y,z,count=0;while(scanf("%d%d",&a,&b)!=EOF){if(a>b) {t=a;a=b,b=t;}if(a<100||b>999) goto m;for(i=a;i<=b;i++){x=(i%100)%10;y=(int(i/10))%10;z=int(i/100); if(x*x*x+y*y*y+z*z*z==i){count+=1;if(count==1)printf("%d",i);else printf(" %d",i);}}m: {if(count>=1) printf("\n");else { printf("no\n");x=0;y=0;z=0; } }count=0;}}Hdu 2011#include<stdio.h>#include<math.h>int main(){int n;double a,i=1.0;double sum=0,b=0;- 6 -while(scanf("%d",&n)!=EOF){while(n--){scanf("%lf",&a);for(i=1;i<=a;i++){sum=sum+(1/i)*pow(-1.0,i+1);}printf("%.2lf\n",sum);sum=0;}}}Hdu 2012#include<stdio.h>#include<math.h>int fun1(int x){return x*x+x+41;} int fun2(int x) {for(int i=2;i<x;i++){if(x%i==0) { return 1;}}return 0;}void main(){int a,b,m,n,t,sum=0;while(scanf("%d %d",&a,&b)!=EOF) {if(a==0&&b==0)continue;else if(a>b){t=a;a=b;b=t;}{/*if(a>b) { c=a;a=b;b=c;}*/ for(int i=a;i<=b;i++){m=fun1(i);- 7 -n=fun2(m);sum+=n;}if(sum!=0){printf("Sorry\n");}else{printf("OK\n");}sum=0;}}}Hdu 2013#include<stdio.h> #include<math.h> int main() {int x,n;while(scanf("%d",&n)!=EOF){if(n==0) break;n=pow(2,n-1);printf("%d\n",3*n-2);}}Hdu 2014#include<stdio.h> int main(){int n,i;float a[100],sum,max,min;while(scanf("%d",&n)!=EOF){sum=0;- 8 -for(i=0;i<n;i++)scanf("%f",&a[i]);max=min=a[0];for(i=0;i<n;i++){if(a[i]>max)max=a[i];if(a[i]<min)min=a[i];sum+=a[i];}printf("%.2f\n",(sum-min-max)/(n-2));}}Hdu 2016#include<stdio.h>void main(){int a[99],n,i,min,t=0;while(scanf("%d",&n)!=EOF){if(n==0) break;else{for(i=0;i<n;i++) scanf("%d",&a[i]);min=a[0]; for(i=0;i<n;i++){if(a[i]<=min) {min=a[i]; t=i;}}a[t]=a[0]; a[0]=min;}printf("%d",a[0]);for(i=1;i<n;i++)printf(" %d",a[i]);t=0;printf("\n");}}- 9 -Hdu 2017#include <stdio.h>void main(){int count=0,i,n;char a[1000];scanf("%d",&n);while(n--){ scanf("%s",a);getchar();for(i=0;a[i];i++) //为什么,,,,,, {if(a[i]>='0'&&a[i]<='9')count++;}printf("%d\n",count);count=0;}}Hdu 2018#include<stdio.h>int main(){int a[55]={1,2,3};int n,i;while(scanf("%d",&n)==1&&n!=0) {for(i=3;i<55;i++)a[i]=a[i-1]+a[i-3];printf("%d\n",a[n-1]);}}Hdu 2019#include<stdio.h>int main(){- 10 -int a[100];int n,i,k=0,m;while(scanf("%d%d",&n,&m)==2&&(n!=0&&m!=0)) {for(i=0;i<n;i++){scanf("%d",&a[i]);}if(m>=a[n-1]){for(i=0;i<n;i++){printf("%d ",a[i]);}printf("%d\n",m);}else if(m<=a[0]){printf("%d",m);for(i=0;i<n;i++){printf(" %d",a[i]);}printf("\n");}else{for(i=0;i<n;i++) {if(a[i]>=m){k=i;break;}}for(i=0;i<k;i++) {printf("%d ",a[i]); }printf("%d",m);for(i=k;i<n;i++) {printf(" %d",a[i]); }printf("\n");}}- 11 -}Hdu 2020#include<stdio.h> #include<math.h>int main (){int i,j,t,n,a[100];while(scanf("%d",&n)!=EOF&&n!=0) {for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++){for(j=0;j<n-i-1;j++){if(abs(a[j])<abs(a[j+1])){t=a[j];a[j]=a[j+1];a[j+1]=t;}}}printf("%d",a[0]);for(i=1;i<n;i++)printf(" %d",a[i]);printf("\n");}}Hdu 2021#include<stdio.h>int fun(int x){int a=0,b=0,c=0,d=0,e=0,f=0;a=(int)(x/100);b=(int)((x-100*a)/50);c=(int) ((x-100*a-50*b)/10);d=(int)((x-100*a-50*b-10*c)/5);e=(int) ((x-100*a-50*b-10*c-5*d)/2); f=x-100*a-50*b-10*c-5*d-2*e;- 12 -return a+b+c+d+e+f; }void main(){int n,a[100],sum;while(scanf("%d",&n)!=EOF){if(n==0) break;sum=0;for(int i=0;i<n;i++){scanf("%d",&a[i]);sum+=fun(a[i]);}printf("%d\n",sum);}}Hdu 2025#include<stdio.h> #include<string.h> int main() {char a[100],max;int i,l;while(scanf("%s",a)!=EOF){getchar();l=strlen(a);max=a[0];for(i=1;i<l;i++){if(a[i]>=max){max=a[i];}}for(i=0;i<l;i++){if(a[i]<max)printf("%c",a[i]);if(a[i]==max)printf("%c(max)",a[i]); - 13 -}printf("\n");}}Hdu 2027#include <stdio.h>void main(){int n,i,a,b,c,d,e,k=0; char f[100];scanf("%d",&n);while(n--){a=b=c=d=e=k=0;scanf("%s",f);getchar();for(i=0;f[i];i++){if(f[i]=='a'||f[i]=='A') a++;if(f[i]=='e'||f[i]=='E') b++;if(f[i]=='i'||f[i]=='I')c++;if(f[i]=='o'||f[i]=='O')d++;if(f[i]=='u'||f[i]=='U')e++;}printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d\n",a,b,c,d,e);if(n) printf("\n"); //重要~~~~~~~~~~~~~~~~~~}}Hdu 2028#include<stdio.h>void main(){int a[100];int i,j,min,max,n,count=0;- 14 -while(scanf("%d",&n)!=EOF){for(i=0;i<n;i++){min=a[0];max=a[0];scanf("%d",&a[i]);if(a[i]>=max)max=a[i];if(a[i]<=min)min=a[i];}for(j=max;;j++){count=0;for(i=0;i<n;i++)if(j%a[i]==0) count++;if(count==n) break;}printf("%d\n",j);}}Hdu 2029#include <stdio.h>#include <stdlib.h> #include <string.h> int main() {int n,i,m=0,b,j;char a[1000];while(scanf("%d",&n)!=EOF){getchar();for(i=0;i<n;i++){gets(a);b=strlen(a);for(j=0;j<b/2;j++){if(a[j]!=a[b-j-1])- 15 -m++;}if(m==0)printf("yes\n");elseprintf("no\n");m=0;}}return 0;}Hdu 2030#include<stdio.h> #include<string.h> int main() {int i,j,n,m,count,b;char a[5000];scanf("%d",&b);getchar();while(b--){gets(a); //用gets~~~~~~~count=0;j=strlen(a);for(i=0;i<j;i++){if(a[i]<0)count++;}printf("%d\n",count/2);}}Hdu 2033#include<stdio.h> void main(){int a1,b1,c1,n,i,a2,b2,c2,x,y,z,a3,b3,c3; scanf("%d",&n);- 16 -for(i=0;i<n;i++){scanf("%d%d%d%d%d%d",&a1,&b1,&c1,&a2,&b2,&c2);c3=(c1+c2)%60; x=(c1+c2-c3)/60;b3=(b1+b2+x)%60; y=(b1+b2+x-b3)/60; a3=a1+a2+y;printf("%d %d %d\n",a3,b3,c3);a1=a2=c1=b1=b2=c2=x=y=z=0;}}Hdu 2035#include <stdio.h>void main(){int n,m,t,i;while(scanf("%d%d",&n,&m)!=EOF) {if(n==0&&m==0)break;t=1;for(i=0;i<m;i++){t=t*n;t=t%1000;}printf("%d\n",t);}}Hdu 2039#include<stdio.h>int main(){double a,b,c;int N;scanf("%d",&N);while (scanf("%lf %lf %lf",&a,&b,&c)==3) {if(a+b>c&&a+c>b&&b+c>a&&a-b<c&&a-c<b&&b-c<a) printf("YES\n");else- 17 -printf("NO\n");}return 0;}Hdu 2040#include<stdio.h> int fun(int x){int i,sum=0;for(i=1;i<x;i++){if(x%i==0){sum+=i;}}return sum;}int main(){int n,a,b;while(scanf("%d",&n)>0){while(n--){scanf("%d%d",&a,&b);if(fun(a)==b&&fun(b)==a) printf("YES\n");else printf("NO\n");}}}Hdu 2041#include<stdio.h> int main() {double f[40]={1,1};int n,m;- 18 -for(int i=2;i<40;i++)f[i]=f[i-1]+f[i-2];while(scanf("%d",&n)!=EOF) {for(int j=0;j<n;j++){scanf("%d",&m);printf("%.0lf\n",f[m-1]); }}}Hdu 2042#include<stdio.h>int main(){double f[31]={3};int n,m;for(int i=1;i<31;i++)f[i]=2*f[i-1]-2;while(scanf("%d",&n)!=EOF) {for(int j=0;j<n;j++){scanf("%d",&m);printf("%.0lf\n",f[m]);}}}Hdu 2043#include<string.h>#include <stdio.h>void main(){int x=0,y=0,z=0,m=0,b,i,n;char a[50];scanf("%d",&n);while(n--){scanf("%s",a);- 19 -getchar();b=strlen(a);if(strlen(a)>=8&&strlen(a)<=16) {for(i=0;i<b;i++){if(a[i]>='A'&&a[i]<='Z')x=1;if(a[i]>='a'&&a[i]<='z')y=1;if(a[i]>='0'&&a[i]<='9')z=1;if(a[i]=='~'||a[i]=='!'||a[i]=='@'||a[i]=='#'||a[i]=='$'||a[i]=='%'| |a[i]=='^')m=1;}if(x+y+z+m>=3)printf("YES\n");elseprintf("NO\n");x=y=z=m=0;}elseprintf("NO\n");}}Hdu 2044#include<stdio.h>int main (){__int64 a[50]={0,1,2};int i,n,c,b;while(scanf("%d",&n)!=EOF) {while(n--){for(i=3;i<50;i++)a[i]=a[i-1]+a[i-2];scanf("%d%d",&c,&b);printf("%I64d\n",a[b-c]); }}}- 20 -Hdu 2045#include<stdio.h>int main(){__int64 a[51]={3,6,6};int i,n;while(scanf("%d",&n)!=EOF) {for(i=3;i<51;i++){ a[i]=a[i-1]+2*a[i-2]; }printf("%I64d\n",a[n-1]); }}Hdu 2046#include<stdio.h>int main(){double f[51]={1,2,3};int n;for(int i=3;i<51;i++)f[i]=f[i-1]+f[i-2];while(scanf("%d",&n)!=EOF) {printf("%.0lf\n",f[n-1]); }return 0;}Hdu 2047#include<stdio.h>int main(){__int64 a[40]={3,8};int i,n;while(scanf("%d",&n)!=EOF){for(i=2;i<40;i++)a[i]=2*(a[i-2]+a[i-1]); - 21 -printf("%I64d\n",a[n-1]); }}- 22 -。
[生活]杭电oj部分水题c语言源代码
![[生活]杭电oj部分水题c语言源代码](https://img.taocdn.com/s3/m/6d0a3d37dc36a32d7375a417866fb84ae45cc39d.png)
杭电oj部分水题 c语言源代码1000和1089 A+B for Input-Output Practice (I) #include<stdio.h>int main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF){printf("%d\n",a+b);}return 0;}1001#include<stdio.h>int main(){int i,n,sum;while(scanf("%d",&n)!=EOF){sum=0;for(i=1;i<=n;i++)sum=sum+i;printf("%d\n",sum);printf("\n");}return 0;}1091 A+B for Input-Output Practice (III) #include<stdio.h>int main(){int a,b;while(scanf("%d%d",&a,&b)){if(a==0&&b==0)break;else printf("%d\n",a+b);}return 0;}1092 A+B for Input-Output Practice (IV)#include<stdio.h>int main(){int a,n,i,sum;while(scanf("%d",&n)){if(n==0)break;sum=0;for(i=0;i<n;i++){scanf("%d",&a);sum=sum+a;}printf("%d\n",sum);}return 0;}1093 A+B for Input-Output Practice (V) #include<stdio.h>int main(){int a,n,i,m,j,sum;scanf("%d",&m);j=0;for(j=0;j<m;j++){scanf("%d",&n);sum=0;for(i=0;i<n;i++){scanf("%d",&a);sum=sum+a;}printf("%d\n",sum);}return 0;}1094 A+B for Input-Output Practice (VII)#include <stdio.h>int main(void){int a,n,i,sum;while (scanf("%d", &n) != EOF){ sum=0;for(i=0; i<n;i++ ) {scanf("%d",&a);sum=sum+a;}printf("%d\n", sum);}return 0;}1095 A+B for Input-Output Practice (VII) #include<stdio.h>int main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF) {printf("%d\n", a+b);printf("\n");}return 0;}1096 A+B for Input-Output Practice (VIII) #include<stdio.h>int main(){int a,n,i,j,m,sum;scanf("%d",&m);for(j=0;j<m;j++){scanf("%d",&n);sum=0;for(i=0;i<n;i++){scanf("%d",&a);sum=sum+a;}printf("%d\n",sum);if(j!=m-1)printf("\n");}return 0;}1090 A+B for Input-Output Practice (II) #include<stdio.h>int main(){int a,b,n,i;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d%d",&a,&b);printf("%d\n",a+b);}return 0;}2001 计算两点间的距离#include <stdio.h>#include <math.h>int main(void){double x1,y1,x2,y2;while (scanf("%lf%lf%lf%lf", &x1,& y1, &x2,& y2) != EOF)printf("%.2f\n", sqrt((x1-x2)*(x1-x2) +(y1-y2)*(y1-y2)));return 0;}2002 计算球体积#include <stdio.h>#include <math.h>#define PI 3.1415927int main(void){double r;while (scanf("%lf", &r) != EOF)printf("%.3lf\n", 4.0*PI*r*r*r/3.0);return 0;}2003 求绝对值#include <stdio.h>#include <math.h>int main(void){double a,b;while (scanf("%lf", &a) != EOF){b=fabs(a);printf("%.2lf\n", b);}return 0;}2004 成绩转换#include <stdio.h>int main(void){int x;while (scanf("%d", &x) != EOF){ if(x<0)printf("Score is error!\n"); else if(x<=59)printf("E\n");else if(x<=69)printf("D\n");else if(x<=79)printf("C\n");else if(x<=89)printf("B\n");else if(x<=100)printf("A\n");elseprintf("Score is error!\n");}return 0;}2006 求奇数的乘积#include <stdio.h>int main(void){int i,n,m,product;while (scanf("%d", &n) != EOF){ for(product=1,i=1;i<=n;i++){scanf("%d",&m);if(m%2!=0)product=product*m;}printf("%d\n",product);}return 0;}2007 平方和与立方和#include <stdio.h>#include<math.h>int main(void){int m, n, i;double a,b,x,y;while (scanf("%d%d", &m, &n) != EOF) {if (m > n){i = n;n = m;m = i;}x = y = 0;for (i = m ; i <= n ; i++){if(i%2==0){ a=pow(i,2);x=x+a;}else{ b=pow(i,3);y=y+b;}}printf("%.0lf %.0lf\n", x, y);}return 0;}output limit exceeded2008 数值统计output limit exceededint main(void){int m, n, i,a,b,c;while (scanf("%d", &n) != EOF) {if(n==0)break;a=b=c=0;for (i = 1 ; i <= n ; i++){ scanf("%d",&m);if(m>0){c=c+1;}else if(m==0){ b=b+1;}else{ a=a+1;}}printf("%d %d %d\n", a,b,c);}return 0;}output limit exceeded#include <stdio.h>int main(void){int n, i, a, b, c;double x;while (scanf("%d", &n) , n){a =b =c = 0;for (i = 0 ; i < n ; i++){scanf("%lf", &x);if (x > 0) c++;else if (x < 0) a++;else b++;}printf("%d %d %d\n", a, b, c);}return 0;}2009 求数列的和#include <stdio.h>#include <math.h>int main(void){int i,n;double x, s;while (scanf("%lf%d", &x, &n) != EOF) {for(s = 0.0,i=0; i<n;i++ ){s=s+x; x = sqrt(x);}printf("%.2lf\n", s);}return 0;}2010 水仙花数#include<stdio.h>int main(void){int i,flag,n,m,a,b,c,x;while(scanf("%d%d",&m,&n)!=EOF){for(i=m,flag=0;i<=n;i++){a=i/100;b=i/10%10;c=i%10;x=a*a*a+b*b*b+c*c*c;if(x==i){if(flag>0) printf(" %d",i); else printf("%d",i);flag++;}}if(flag==0) printf("no");printf("\n");}}2011 多项式求和#include <stdio.h>int main(void){int m,n,i,x;double sum,a,b;while (scanf("%d", &n) != EOF) {for(i=0; i<n;i++ ) { sum=0;scanf("%d",&m);for(x=1;x<=m;x++){if(x%2==0){a=1.0/x*(-1);b=0;}else{b=1.0/x; a=0;}sum=a+b+sum;}printf("%.2lf\n", sum);}}return 0;}2013蟠桃记#include <stdio.h>#include <math.h>int main(void){int n;while (scanf("%d", &n) != EOF)printf("%.0f\n", 3 * pow(2, n - 1) - 2);return 0;}2021 发工资咯#include <stdio.h>int main(void){int n, i, x, sum;while (scanf("%d", &n), n){sum = 0;for (i = 0 ; i < n ; i++) {scanf("%d", &x);sum += x / 100;x %= 100;sum += x / 50;x %= 50;sum += x / 10;x %= 10;sum += x / 5;x %= 5;sum += x / 2;x %= 2;sum += x;}printf("%d\n", sum);}return 0;}#include <stdio.h>int main(void){int n, i, x, sum;while (scanf("%d", &n), n){sum = 0;for (i = 0 ; i < n ; i++){scanf("%d", &x);sum =sum+ x / 100;x = x%100;sum =sum+ x / 50;x = x% 50;sum =sum+x / 10;x = x% 10;sum =sum+ x / 5;x = x% 5;sum =sum+x / 2;x = x% 2;sum =sum+x;}printf("%d\n", sum);}return 0;}2005 第几天?#include <math.h>#include <stdio.h>#define lev(n) (n % 4 == 0 && (n % 100 != 0 || n % 400 == 0))int main(void){int y, m, d, i, s;int month[2][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} };while (scanf("%d/%d/%d", &y, &m, &d) != EOF){for (s = 0, i = 1 ; i < m ; i++)s =s+ month[lev(y)][i];s =s+ d;printf("%d\n", s);}return 0;}2000 ASCII码#include <stdio.h>int main(){char a,b,c,d,x,y,z;while(scanf("%c%c%c%c",&a,&b,&c,&d) != EOF){if(a<b)x=a;elsex=b;if(x<c)x=x;elsex=c;if(a>b)z=a;elsez=b;if(z>c)z=z;elsez=c;y=a+b+c-x-z;printf("%c %c %c\n",x,y,z);}}2012 素数判定#include<stdio.h>#include<math.h>int main(){int x,y;int n,i,t,num;while(scanf("%d%d",&x,&y),x!=0||y!=0) { num=0;for (i=x;i<=y;i++){ t=i*i+i+41;for (n=2;n<=sqrt(t);n++)if(t%n==0){num++;break;}}if(num>0)printf("Sorry\n");else printf("OK\n");}}2014 青年歌手大奖赛_评委会打分#include <stdio.h>int main(void){int n, i;double min, max;double x, y;while (scanf("%d", &n) != EOF){scanf("%lf", &x);min = max = x;for (i = 1 ; i < n ; i++){scanf("%lf", &y);x =x+ y;if (y > max) max = y;if (y < min) min = y;}printf("%.2lf\n", (x - min - max) / (n - 2)); }return 0;}2015 偶数求和#include<stdio.h>int main(){int m,n,i,num,x,sum;while(scanf("%d%d",&n,&m)!=EOF){num=0;x=2;sum=0;while (n){sum=sum+x;num++;if(n==1) {printf("%d\n",sum/num);} else if(num==m) {printf("%d",sum/num);sum=0;num=0;}x=x+2;n=n-1;}}return 0;}2016 数据的交换输出#include<stdio.h>int main(void){int i,index,n,temp;int a[10];while(scanf("%d",&n) && n){for(i=0;i<n;i++)scanf("%d",&a[i]);index=0;for(i=1;i<n;i++){if(a[i]<a[index])index=i;}temp=a[index];a[index]=a[0];a[0]=temp;for(i=0;i<n;i++){if(i==0)printf("%d",a[i]);else printf(" %d",a[i]);} printf("\n");}return 0;}2017#include <stdio.h>#include <string.h>main(){char a[100],b[100];int m,n,i,j,k;while(scanf("%d",&n)!=EOF){m=0;gets(b);for(i=0;i<n;i++){gets(a);k=strlen(a);for(j=0;j<k;j++)if(a[j]>='0' && a[j]<='9')m=m+1;printf("%d\n",m);m=0;}}}2018 母牛的故事#include <ctype.h>#include <stdio.h>int main(void){int n, i;int fab[55]={1,2,3,4,6};for(i=5;i<55;i++)fab[i]=fab[i-1]+fab[i-3];while(scanf("%d",&n),n){printf("%d\n", fab[n-1]);}return 0;}2022 海选女主角#include<stdio.h>#include<math.h>int main(void){int i,j,n,m,x,y;double a,t;while(scanf("%d%d",&n,&m)!=EOF){a=x=y=0;for(i=0;i<n;i++){for(j=0;j<m;j++){scanf("%lf",&t);if(fabs(t)>fabs(a)){a=t;x=i;y=j;}}}printf("%d %d %.0f\n",x+1,y+1,a); }return 0;}2025 查找最大元素#include <stdio.h>int main(void){char t[128],max;int i;while(gets(t)){for(max=i=0;t[i];i++){if(t[i]>max)max=t[i];}for(i=0;t[i];i++){putchar(t[i]);if (t[i]==max)printf("%s","(max)"); }putchar('\n');}return 0;}2026 首字母变大写#include<stdio.h>int main(){char a[100];int i;while(gets(a)){a[0]=a[0]-32;for(i=1;a[i];i++)if(a[i-1]==' ')a[i]=a[i]-32;puts(a);}return 0;}2039 三角形#include<stdio.h>int main(void){int n;double a,b,c;scanf("%d",&n);while(n--&&scanf("%lf%lf%lf",&a,&b,&c)) puts(a+b>c&&a+c>b&&b+c>a?"YES":"NO");return 0;}2055 An easy problem#include <stdio.h>int main(){int n,a;char c;scanf("%d%*c", &n);while(n--&&scanf("%c%d%*c",&c,&a))if(c<97)printf("%d\n",a+c-'A'+1);elseprintf("%d\n",a+'a'-c-1);return 0;}2044 一只小蜜蜂...#include <stdio.h>int main(void){int i, j, n;__int64 d[51] = {1, 1, 2,};for (i = 3; i < 51; i++)d[i] = d[i-1] + d[i-2];scanf("%d", &n);while (n-- && scanf("%d%d", &i, &j) != EOF) printf("%I64d\n", i > j ? 0 : d[j-i]);return 0;}2160母猪的故事#include<stdio.h>int main(){int i,j,a[20],n,x;a[0]=1;a[1]=2;a[2]=3;scanf("%d",&x);for(j=0;j<x;j++){scanf("%d",&n);for(i=3;i<20;i++)a[i]=a[i-1]+a[i-2];printf("%d\n",a[n-1]); }}2046 骨牌铺方格#include <stdio.h>#include <math.h>int main(void){int i;__int64 a[51] = {1, 1, 2,};for(i=3;i<51;i++)a[i]=a[i-1]+a[i-2];while(scanf("%d", &i)!=EOF) printf("%I64d\n",a[i]);return 0;}2050折线分割平面#include <stdio.h>int main(void){int n, i;scanf("%d", &i);while (i-- && scanf("%d", &n))printf("%d\n", 2*n*n-n+1);return 0;}2201 熊猫阿波的故事#include<stdio.h>int main(){double n,m;while(scanf("%lf %lf",&n,&m)!=EOF) {printf("%0.2f\n",(1.0/n));}return 0;}2101 A + B Problem Too#include<stdio.h>int main(){int a,b,n;while(scanf("%d%d",&a,&b)!=EOF) {n=a+b;if((n%86)==0)printf("yes\n");elseprintf("no\n");}return 0;}2091 空心三角形#include <stdio.h>int main(void){char c;int i = 0, n;while ((c = getchar()) != '@'){scanf("%d", &n);if(i!=0)printf("\n%*c\n" , n, c);elseprintf("%*c\n", n, c);if (n == 1){i = 1;continue;}for (i = 1; i + 1 < n; i++)printf("%*c%*c\n", n - i, c, i * 2, c); for (i = 0; i < 2 * n - 1; i++) putchar(c);putchar('\n');}return 0;}2091 空心三角形有错误#include <stdio.h>int main(void){char c;int i = 0, n;while ((c = getchar()) != '@'){scanf("%d", &n);if(i!=0)printf("\n%*c\n" , n, c);elseprintf("%*c\n", n, c);if (n == 1){i = 1;continue;}for (i = 1; i + 1 < n; i++)printf("%*c%*c\n", n - i, c, i * 2, c); for (i = 0; i < 2 * n - 1; i++) putchar(c);putchar('\n');}return 0;}2149#include "stdio.h"int main(){int n,m,i;while(scanf("%d%d",&n,&m)!=EOF){if(n<=m){for(i=n;i<m;i++){printf("%d ",i);}printf("%d\n",i);}else{if(n%(m+1)){printf("%d\n",n%(m+1));}elseprintf("none\n");}}}2304#include<stdio.h>int main(){int n,m,i,a[11],sum;scanf("%d",&n);while(n--){sum=0;scanf("%d",&m);for(i=1;i<=m;i++){scanf("%d",&a[i]);sum+=a[i];}printf("%d\n",sum-m+1);}}2317Nasty Hacks肮脏的黑客#include<stdio.h>int main(){int n,a,b,c;scanf("%d",&n);while(n--){scanf("%d %d %d",&a,&b,&c);if(a<(b-c))printf("advertise\n");if(a==(b-c))printf("does not matter\n");if(a>(b-c))printf("do not advertise\n");}return 0;}2464A Pair of Graphs2404置换回收2105The Center of GravityTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3585 Accepted Submission(s): 2034Problem DescriptionEveryone know the story that how Newton discovered the Universal Gravitation. One day, Newton walkedleisurely, suddenly, an apple hit his head. Then Newton discovered the Universal Gravitation.From thenon,people have sovled many problems by the the theory of the Universal Gravitation. What's more, wo alsohave known every object has its Center of Gravity.Now,you have been given the coordinates of three points of a triangle. Can you calculate the centerof gravity of the triangle?InputThe first line is an integer n,which is the number of test cases.Then n lines follow. Each line has 6 numbersx1,y1,x2,y2,x3,y3,which are the coordinates of three points. The input is terminated by n = 0.OutputFor each case, print the coordinate, accurate up to 1 decimal places.问题描述每个人都知道这个故事,牛顿发现了万有引力。
ACM常用算法及其相应的练习题
![ACM常用算法及其相应的练习题](https://img.taocdn.com/s3/m/f5a3bb06e87101f69e3195e2.png)
ACM常用算法及其相应的练习题2007-12-03 23:48OJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3 094)初期:一.基本算法:(1)枚举. (poj1753,poj2965)(2)贪心(poj1328,poj2109,poj2586)(3)递归和分治法.(4)递推.(5)构造法.(poj3295)(6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法:(1)图的深度优先遍历和广度优先遍历.(2)最短路径算法(dijkstra,bellman-ford,floyd,heap+dijkstra)(poj1860,poj3259,poj1062,poj2253,poj1125,poj2240)(3)最小生成树算法(prim,kruskal)(poj1789,poj2485,poj1258,poj3026)(4)拓扑排序 (poj1094)(5)二分图的最大匹配 (匈牙利算法) (poj3041,poj3020)(6)最大流的增广路算法(KM算法). (poj1459,poj3436)三.数据结构.(1)串 (poj1035,poj3080,poj1936)(2)排序(快排、归并排(与逆序数有关)、堆排) (poj2388,poj2299)(3)简单并查集的应用.(4)哈希表和二分查找等高效查找法(数的Hash,串的Hash)(poj3349,poj3274,POJ2151,poj1840,poj2002,poj2503)(5)哈夫曼树(poj3253)(6)堆(7)trie树(静态建树、动态建树) (poj2513)四.简单搜索(1)深度优先搜索 (poj2488,poj3083,poj3009,poj1321,poj2251)(2)广度优先搜索(poj3278,poj1426,poj3126,poj3087.poj3414)(3)简单搜索技巧和剪枝(poj2531,poj1416,poj2676,1129)五.动态规划(1)背包问题. (poj1837,poj1276)(2)型如下表的简单DP(可参考lrj的书 page149):1.E[j]=opt{D+w(i,j)} (poj3267,poj1836,poj1260,poj2533)2.E[i,j]=opt{D[i-1,j]+xi,D[i,j-1]+yj,D[i-1][j-1]+zij} (最长公共子序列)(poj3176,poj1080,poj1159)3.C[i,j]=w[i,j]+opt{C[i,k-1]+C[k,j]}.(最优二分检索树问题)六.数学(1)组合数学:1.加法原理和乘法原理.2.排列组合.3.递推关系.(POJ3252,poj1850,poj1019,poj1942)(2)数论.1.素数与整除问题2.进制位.3.同余模运算.(poj2635, poj3292,poj1845,poj2115)(3)计算方法.1.二分法求解单调函数相关知识.(poj3273,poj3258,poj1905,poj3122)七.计算几何学.(1)几何公式.(2)叉积和点积的运用(如线段相交的判定,点到线段的距离等).(poj2031,poj1039)(3)多边型的简单算法(求面积)和相关判定(点在多边型内,多边型是否相交)(poj1408,poj1584)(4)凸包. (poj2187,poj1113)中级:一.基本算法:(1)C++的标准模版库的应用. (poj3096,poj3007)(2)较为复杂的模拟题的训练(poj3393,poj1472,poj3371,poj1027,poj2706)二.图算法:(1)差分约束系统的建立和求解. (poj1201,poj2983)(2)最小费用最大流(poj2516,poj2516,poj2195)(3)双连通分量(poj2942)(4)强连通分支及其缩点.(poj2186)(5)图的割边和割点(poj3352)(6)最小割模型、网络流规约(poj3308, )三.数据结构.(1)线段树. (poj2528,poj2828,poj2777,poj2886,poj2750)(2)静态二叉检索树. (poj2482,poj2352)(3)树状树组(poj1195,poj3321)(4)RMQ. (poj3264,poj3368)(5)并查集的高级应用. (poj1703,2492)(6)KMP算法. (poj1961,poj2406)四.搜索(1)最优化剪枝和可行性剪枝(2)搜索的技巧和优化 (poj3411,poj1724)(3)记忆化搜索(poj3373,poj1691)五.动态规划(1)较为复杂的动态规划(如动态规划解特别的施行商问题等)(poj1191,poj1054,poj3280,poj2029,poj2948,poj1925,poj3034)(2)记录状态的动态规划. (POJ3254,poj2411,poj1185)(3)树型动态规划(poj2057,poj1947,poj2486,poj3140)六.数学(1)组合数学:1.容斥原理.2.抽屉原理.3.置换群与Polya定理(poj1286,poj2409,poj3270,poj1026).4.递推关系和母函数.(2)数学.1.高斯消元法(poj2947,poj1487, poj2065,poj1166,poj1222)2.概率问题. (poj3071,poj3440)3.GCD、扩展的欧几里德(中国剩余定理) (poj3101)(3)计算方法.1.0/1分数规划. (poj2976)2.三分法求解单峰(单谷)的极值.3.矩阵法(poj3150,poj3422,poj3070)4.迭代逼近(poj3301)(4)随机化算法(poj3318,poj2454)(5)杂题.(poj1870,poj3296,poj3286,poj1095)七.计算几何学.(1)坐标离散化.(2)扫描线算法(例如求矩形的面积和周长并,常和线段树或堆一起使用).(poj1765,poj1177,poj1151,poj3277,poj2280,poj3004)(3)多边形的内核(半平面交)(poj3130,poj3335)(4)几何工具的综合应用.(poj1819,poj1066,poj2043,poj3227,poj2165,poj3429)高级:一.基本算法要求:(1)代码快速写成,精简但不失风格(poj2525,poj1684,poj1421,poj1048,poj2050,poj3306)(2)保证正确性和高效性. poj3434二.图算法:(1)度限制最小生成树和第K最短路. (poj1639)(2)最短路,最小生成树,二分图,最大流问题的相关理论(主要是模型建立和求解)(poj3155,poj2112,poj1966,poj3281,poj1087,poj2289,poj3216,poj2446(3)最优比率生成树. (poj2728)(4)最小树形图(poj3164)(5)次小生成树.(6)无向图、有向图的最小环三.数据结构.(1)trie图的建立和应用. (poj2778)(2)LCA和RMQ问题(LCA(最近公共祖先问题) 有离线算法(并查集+dfs) 和在线算法(RMQ+dfs)).(poj1330)(3)双端队列和它的应用(维护一个单调的队列,常常在动态规划中起到优化状态转移的目的). (poj2823)(4)左偏树(可合并堆).(5)后缀树(非常有用的数据结构,也是赛区考题的热点).(poj3415,poj3294)四.搜索(1)较麻烦的搜索题目训练(poj1069,poj3322,poj1475,poj1924,poj2049,poj3426)(2)广搜的状态优化:利用M进制数存储状态、转化为串用hash表判重、按位压缩存储状态、双向广搜、A*算法.(poj1768,poj1184,poj1872,poj1324,poj2046,poj1482)(3)深搜的优化:尽量用位运算、一定要加剪枝、函数参数尽可能少、层数不易过大、可以考虑双向搜索或者是轮换搜索、IDA*算法.(poj3131,poj2870,poj2286)五.动态规划(1)需要用数据结构优化的动态规划.(poj2754,poj3378,poj3017)(2)四边形不等式理论.(3)较难的状态DP(poj3133)六.数学(1)组合数学.1.MoBius反演(poj2888,poj2154)2.偏序关系理论.(2)博奕论.1.极大极小过程(poj3317,poj1085)2.Nim问题.七.计算几何学.(1)半平面求交(poj3384,poj2540)(2)可视图的建立(poj2966)(3)点集最小圆覆盖.(4)对踵点(poj2079)八.综合题.(poj3109,poj1478,poj1462,poj2729,poj2048,poj3336,poj3315,poj214 8,poj1263)--------------------------------------------------------------------以及补充Dp状态设计与方程总结1.不完全状态记录<1>青蛙过河问题<2>利用区间dp2.背包类问题<1> 0-1背包,经典问题<2>无限背包,经典问题<3>判定性背包问题<4>带附属关系的背包问题<5> + -1背包问题<6>双背包求最优值<7>构造三角形问题<8>带上下界限制的背包问题(012背包)3.线性的动态规划问题<1>积木游戏问题<2>决斗(判定性问题)<3>圆的最大多边形问题<4>统计单词个数问题<5>棋盘分割<6>日程安排问题<7>最小逼近问题(求出两数之比最接近某数/两数之和等于某数等等)<8>方块消除游戏(某区间可以连续消去求最大效益)<9>资源分配问题<10>数字三角形问题<11>漂亮的打印<12>邮局问题与构造答案<13>最高积木问题<14>两段连续和最大<15>2次幂和问题<16>N个数的最大M段子段和<17>交叉最大数问题4.判定性问题的dp(如判定整除、判定可达性等)<1>模K问题的dp<2>特殊的模K问题,求最大(最小)模K的数<3>变换数问题5.单调性优化的动态规划<1>1-SUM问题<2>2-SUM问题<3>序列划分问题(单调队列优化)6.剖分问题(多边形剖分/石子合并/圆的剖分/乘积最大)<1>凸多边形的三角剖分问题<2>乘积最大问题<3>多边形游戏(多边形边上是操作符,顶点有权值)<4>石子合并(N^3/N^2/NLogN各种优化)7.贪心的动态规划<1>最优装载问题<2>部分背包问题<3>乘船问题<4>贪心策略<5>双机调度问题Johnson算法8.状态dp<1>牛仔射击问题(博弈类)<2>哈密顿路径的状态dp<3>两支点天平平衡问题<4>一个有向图的最接近二部图9.树型dp<1>完美服务器问题(每个节点有3种状态)<2>小胖守皇宫问题<3>网络收费问题<4>树中漫游问题<5>树上的博弈<6>树的最大独立集问题<7>树的最大平衡值问题<8>构造树的最小环枚举法,常常称之为穷举法,是指从可能的集合中一一枚举各个元素,用题目给定的约束条件判定哪些是无用的,哪些是有用的。
杭电OJ水题答案
![杭电OJ水题答案](https://img.taocdn.com/s3/m/9d173925ed630b1c58eeb501.png)
Hdu1000,1090#include<stdio.h>int main(){int a,b;while (scanf("%d %d",&a,&b)==2)printf("%d\n",a+b);return 0;}Hdu1008#include<stdio.h>int main(){int n,i,j;int t;while(scanf("%d",&n)!=EOF){t=5*n;j=0;if(n==0)break;while(n--){scanf("%d",&i);if(i>j)t+=(i-j)*6;if(i<j)t+=(j-i)*4;j=i;}printf("%d\n",t);}}Hdu1021#include <stdio.h>int main(){int n;while(scanf("%d",&n)!=EOF){n=n%8;if(n==2||n==6)printf("yes\n");elseprintf("no\n");}return 0;}Hdu1040#include<stdio.h>int main(){int i,j,n,m,a[2000],t;scanf("%d",&n);while(n--){scanf("%d",&m);for(i=0;i<m;i++)scanf("%d",&a[i]);for(i=0;i<m;i++)for(j=0;j<m-1-i;j++)if(a[j]>a[j+1]){t=a[j];a[j]=a[j+1];a[j+1]=t;}printf("%d",a[0]);for(i=1;i<m;i++)printf(" %d",a[i]);printf("\n");}}Hdu1076#include<stdio.h>int main(){int count=0,i,n,j,a,b;while(scanf("%d",&n)!=EOF){for(i=0;i<n;i++){scanf("%d %d",&a,&b);for(j=a;;j++){if((j%100==0&&j%400==0)||(j%100!=0&&j%4==0)){ count++; }if(count==b) break;}printf("%d\n",j);count=0;}}}Hdu1091#include<stdio.h>int main(){double a;double b;while(scanf("%lf %lf",&a,&b))if(a==0 && b==0)break;elseprintf("%.0lf\n",a+b);return 0;}Hdu1092#include<stdio.h>void main(){int n,i,a,sum=0;while(scanf("%d",&n)!=EOF){if(n==0)continue;elsefor(i=1;i<=n;i++){scanf("%d",&a);sum+=a;}printf("%d\n",sum);sum=0;}}}Hdu1093#include<stdio.h>int main(){int n,i,j,a,sum=0;scanf("%d",&j);for(int b=0;b<j;b++){while(scanf("%d",&n)!=EOF){for(i=1;i<=n;i++){scanf("%d",&a);sum+=a;}printf("%d\n",sum);sum=0;}}}Hdu1094#include<stdio.h>int main(){int n,i,a,sum=0;while(scanf("%d",&n)!=EOF) {for(i=1;i<=n;i++)scanf("%d",&a);sum+=a;}printf("%d\n",sum);sum=0;}}Hdu1095#include<stdio.h>int main(){int a,b;while (scanf("%d %d",&a,&b)==2)printf("%d\n\n",a+b);return 0;}Hdu1096#include<stdio.h>int main(){int N;scanf("%d",&N);while(N--){int M,i,a,sum=0;scanf("%d",&M);for(i=0;i<M;i++){scanf("%d",&a);sum+=a;}if(N!=0)printf("%d\n\n",sum);elseprintf("%d\n",sum);}}Hdu1108#include<stdio.h>void main (){unsigned int b, a, i=1;while(scanf("%d %d",&a,&b)!=EOF){for(i=1;;i++){if(i%a==0&&i%b==0){printf("%d\n",i);break;}}}}Hdu1201#include<stdio.h>void main(){int a,b,c,i,n,count1,count2,sum;while(scanf("%d",&n)!=EOF){while(n--){scanf("%d-%d-%d",&a,&b,&c);if(b==2&&c==29){ printf("-1\n"); }else{count1=0;sum=0;for(i=a;i<a+18;i++){if((((i%100!=0&&i%4==0)||(i%400==0))&&b<=2)||((((i+1)%100!=0&&(i+1)%4==0)||((i+1) %400==0))&&b>2))sum+=366;elsesum+=365;}printf("%d\n",sum);}}}}Hdu1235#include<stdio.h>void main(){int a,b,c,i,n,f[1000],count=0;while(scanf("%d",&n)>0){if(n==0) break;for(i=0;i<n;i++)scanf("%d",&f[i]);scanf("%d",&c);for(i=0;i<n;i++){if(f[i]==c)count++;}printf("%d\n",count);count=0;}}Hdu1046#include<stdio.h>int f(int x){int j,sum=0;for(j=1;j<x;j++){if(x%j==0)sum+=j;}if(x==sum)return 1;else return 0;sum=0;}void main(){unsigned int i,n,a,b,t,x,count=0;while(scanf("%d",&n)>0){while(n--){scanf("%d%d",&a,&b);if(a>b) {t=a;a=b;b=t; }for(i=a;i<=b;i++){x=f(i);if(x==1) //1是完数count++;}printf("%d\n",count);count=0;}}}。
杭州电子科技大学acm题目分类
![杭州电子科技大学acm题目分类](https://img.taocdn.com/s3/m/c413f1f5ba0d4a7302763afb.png)
杭州电子科技大学acm题目分类1002 简单的大数1003 DP经典问题,最大连续子段和1004 简单题1005 找规律(循环点)1006 感觉有点BT的题,我到现在还没过1007 经典问题,最近点对问题,用分治1008 简单题1009 贪心1010 搜索题,剪枝很关键10111012 简单题1013 简单题(有个小陷阱)1014 简单题1015 可以看作搜索题吧1016 经典的搜索1017 简单数学题1018 简单数学题1019 简单数学题1020 简单的字符串处理1021 找规律的数学题1022 数据结构的题(栈的应用)1023 特殊的数(Catalan Number)1024 经典DP,最大M子段和1025 经典DP,最长递增子序列(要用NLogN的方法过)1026 搜索1027 数学题(或用STL)1028 经典问题,整数拆分,用母函数做1029 简单题(一般方法容易超时)1030 简单题,可用模拟过1031 简单题1032 简单题1033 模拟题1034 Candy Sharing Game1035 模拟题1036 简单题1037 简单题,不是一般的简单1038 简单题1039 字符串处理1040 简单题,排序1041 简单题,用大数1042 大数1043 经典搜索题,八数码问题1044 稍微有点麻烦的搜索题1045 搜索题,可用匹配做1046 简单题1047 简单的大数1048 简单字符串处理1049 简单题1050 贪心1051 经典贪心,也可以用DP1052 贪心1053 贪心,关于Huffman编码1054 二分匹配1055 二分匹配1056 简单题1057 模拟题1058 经典问题,丑数,DP1059 经典问题,可以用母函数或DP(不针对题目优化都会超时)1060 数学题1061 数学题1062 简单字符串处理1063 模拟大数1064 简单题1065 简单题1066 数学题,找规律10671068 经典二分匹配1069 经典DP1070 简单题1071 简单数学题1072 搜索1073 字符串处理1074 DP1075 字典树1076 简单题10771078 DP1079 博弈(DP)1080 DP1081 经典DP1082 简单题1083 二分匹配1084 简单题1085 母函数1086 简单几何题1087 简单DP1088 字符串处理1089~1096 (练习输入输出的8个题目)1097 简单数学题1098 数学题,注意找规律1099 数学题模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 1202 1205 1209 1212(大数取模) 1216(链表)1218 1219 1225 1228 1229 1230 1234 1235 1236 1237 1239 12501256 1259 1262 1263 1265 1266 1276 1279 1282 1283 1287 1296 13021303 1304 1305 1306 1309 1311 1314复杂模拟搜索,递归求解1010 1016 1026 1043(双广) 1044 (BFS+DFS) 1045 1067 1072 1104 1175 1180 1195 1208 1226 1238 1240 1241 1242 1258 1271 1312 1317 博奕1079动态规划1003 1024 1025 1028 1051 1058 1059 1069 1074 1078 1080 1081 1085 1087 1114 1158 1159 1160 1171 1176 1181 1203 1224 1227 1231 1244 1248 1253 1254 1283 1300数学,递推,规律1005 1006 1012 1014 1018 1019 1021 1023 1027 1030 1032 1038 1041 1046 1059 1060 1061 1065 1066 1071(微积分) 1097 1098 1099 1100 1108 1110 1112 1124 1130 1131 1132 1134 1141 1143 1152 1155(物理题) 1163 1165 1178 1194 1196(lowbit) 1210 1214 1200 1221 1223 1249 1261 1267 1273 1290 1291 1292 1294 1297 1313 1316数论1164 1211 1215 1222 1286 1299计算几何1086 1115 1147贪心1009 1052 1055 1257并查集1198 1213 1232 1272线段树,离散化1199 1255图论最短路相关的问题1142 1162 1217 1301二分图问题1054 1068 1150 1151 1281其他1053 (huffman) 1102(MST) 1116(欧拉回路)1233(MST) 1269(强连通)数据结构1103(堆+模拟)1166(数状树组)1247 1251 1285(Topol)1298汉诺塔系列1207最近顶点对10071500 DP1501 DP1502 DP or 记忆化1503 DP1504 模拟1505 DP1506 DP1507 2分匹配1508 记忆化容易点1509 模拟1510 DP1511 搜索可以过1512 左偏树1513 DP1514 DP1515 DFS1516 DP1517 博奕1518 搜索1519 DP(不确定)1520 树状DP1521 数学题,母函数什么的。
杭电ACM100题
![杭电ACM100题](https://img.taocdn.com/s3/m/5f8603820129bd64783e0912a216147917117e25.png)
杭电ACM100题题号 2000 ASCII 码排序 2002 计算球体积 2004 成绩转换 2006 求奇数的乘积 2008 数值统计 2010 水仙花数 2012 素数判定题名题号2001 计算两点间的距离2003 求绝对值2005 第几天?2007 平方和与立方和 2009 求数列的和 2011 多项式求和 2013 蟠桃记 2015 偶数求和 2017 字符串统计 2019 数列有序! 2021 发工资咯:)2023 求平均成绩 2025 查找最大元素 2027 统计元音题名2014 青年歌手大奖赛_评委会打分 2016 数据的交换输出 2018 母牛的故事 2020 绝对值排序 2022 海选女主角 2024 C 语言合法标识符2026 首字母变大写 2028 Lowest Common Multiple Plus 2030 汉字统计2032 杨辉三角2034 人见人爱A-B 2036 改革春风吹满地2038 test 2040 亲和数2042 不容易系列之二2044 一只小蜜蜂... 2046 骨牌铺方格 2048 神、上帝以及老天爷 2050 折线分割平面 2052 Picture 2054 A == B n 2056 Rectangles 2058 The sum problem 2060 Snooker 2062 Subset sequence 2064 汉诺塔 III 2066 一个人的旅行2068 RPG 的错排2070 Fibbonacci Number 2072 单词数2074 叠筐 2076 夹角有多大(题目已修改,注意读题) 2078 复习时间2029 Palindromes _easy version 2031 进制转换 2033 人见人爱A+B 2035 人见人爱 A^B 2037 今年暑假不 AC 2039 三角形 2041 超级楼梯 2043 密码 2045 不容易系列之(3)—— LELE 的 RPG 难题 2047 阿牛的EOF 牛肉串2049 不容易系列之(4)——考新郎2051 Bitset 2053 Switch Game 2055 An easy problem 2057 A + B Again 2059 龟兔赛跑 2061 Treasure the new start, freshmen! 2063 过山车 2065 "红色病毒"问题2067 小兔的棋盘2069 Coin Change 2071 Max Num 2073 无限的路 2075 A|B? 2077 汉诺塔 IV 2079 选课时间(题目已修改,注意读题)2080 夹角有多大 II 2082 找单词 2084 数塔 2086 A1 = n 2088 Box of Bricks 2090 算菜价 2092 整数解 2094 产生冠军 2096 小明A+B 2098 分拆素数和2081 手机短号 2083 简易版之最短距离 2085 核反应堆 2087 剪花布条2089 不要62 2091 空心三角形2093 考试排名2095 find your present (2) 2097 Sky 数 2099 整除的尾数。
acm试题及答案
![acm试题及答案](https://img.taocdn.com/s3/m/3052485d02d8ce2f0066f5335a8102d277a2616b.png)
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项。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。
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;
Input
输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。
Output
对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。
Sample Input
1 3
2 5
Sample Output
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 69615 Accepted Submission(s): 12678
Problem Description
sum2 = 0;
if(x > y)
{
temp = x;
x = y;
y = temp;
}
for(; x <= y; x++)
{
if( x % 2 == 0)
{
sum1 += x * x;
}
else
sum2 += x * x * x;
}
printf("%d %d\n", sum1, sum2);
}
return 0;
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The 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.
Author
Ignatius.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);
count++;
}
}
if(count == 0)
printf("no\n");
else
printf("\n");
}
return 0;
}
2012素数判定
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Output
对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
Sample Input
100 120
300 380
{
k1 = m / 100;
k2 = (m - 100 * k1) / 10;
k3 = (m -100 * k1 -10 * k2);
if(m == k1*k1*k1 + k2*k2*k2 + k3*k3*k3)
{
if(count != 0)
{
printf(" ");
}
printf("%d", m);
Font Size: ← →
Problem Description
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。
现在要求输出所有在m和n范围内的水仙花数。
Input
输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。
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");
Output
For 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.
lcy
Source
C语言程序设计练习(二)
Statistic|Submit|Back
#include <stdio.h>
int main()
{
int x, y, sum, i, count, n;
while(scanf("%d %d", &x, &y) != EOF && (x!=0 || y!= 0))
Sample Input
56
67
100
123
Sample Output
E
D
A
Score is error!
Author
lcy
Source
C语言程序设计练习(一)
Recommend
JGShining
#include <stdio.h>
int main(){
int n, k;
while(scanf("%d", &n) != EOF){
1001
#include <stdio.h>
int main()
{
int i,a,j;double sum;
while(scanf("%d",&a)!=EOF)
{
sum=0;
for(j=1;j<=a;j++)
{
sum+=j;
}
printf("%.0lf\n\n",sum);
}
return 0;
}
1002A + B Problem II
else
len_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);
Input
输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
Output
对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
Sample Input
0 1
0 0
Sample Output
OK
Author
if(n < 0 || n >100)
printf("Score is error!\n");