
算法学习
逃课去学习:)
读万卷书,行万里路。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PAT甲级真题(字符串)——1005 Spell It Right (20 分)
1005 Spell It Right (20 分)Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file co...原创 2019-01-03 15:47:38 · 286 阅读 · 0 评论 -
PAT(排序)——1025 PAT Ranking (25 分)
1025 PAT Ranking (25 分)Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several pla...原创 2019-01-17 16:18:43 · 204 阅读 · 0 评论 -
PAT甲级真题(并查集)——1004 Counting Leaves (30 分)
1004 Counting Leaves (30 分)A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file contains one t...原创 2019-01-03 11:57:30 · 471 阅读 · 0 评论 -
HDOJ(bfs+优先队列)——1026 Ignatius and the Princess I
题目大意:迷宫问题,已知出发点和终点,求两点之间时间最短的路径,要注意,迷宫中有怪物,走到有怪物的格子要击败怪物,用时等于怪物的血量。题目解析:迷宫问题,马上想到用dfs或bfs,像这种求一条最短路线的就用bfs,由于涉及到不同血量的怪物,我们采用优先队列可以解决这个问题。题目要求输出走过的节点,我们可以定义结构体node,每次记下前驱结点,到终点用一个dfs函数输出沿线坐标;也可以从终点出...原创 2019-01-14 16:53:17 · 257 阅读 · 0 评论 -
EOJ(排序)——4. Nth Largest Value
4. Nth Largest ValueFor this problem, you will write a program that prints the Nth largest value in a fixed sized array of integers. To make things simple, N will be 3 and the array will always be ha...原创 2019-01-08 19:58:36 · 245 阅读 · 0 评论 -
EOJ(排序)——15. Mr. Frog and big news
15. Mr. Frog and big news作为一名资深记者,青蛙先生非常讨厌时不时蹦出来的大新闻。偏偏最近大新闻还特别多。青蛙先生觉得应该做一点小小的贡献,把新闻的「雨声」尽可能地变得「小」一点。青蛙先生手上有 N 条国内新闻和 N 条国外新闻。这 N 条国内新闻的大小为 a1,a2…aN,N 条国外新闻的大小为 b1,b2…bN。他决定每天报道任意一条没有报道过的国内新闻和国外新闻。...原创 2019-01-08 20:27:18 · 267 阅读 · 0 评论 -
EOJ(排序)——37. 奇怪的排序题
37. 奇怪的排序题所有数据在内存中都是以二进制形式存放的,其中有一些位是 1,而另一些位是 0。例如,整数 100 的二进制表示为 1100100,其中 1 的位数是 3;整数 15 的二进制表示为 1111,其中 1 的位数是 4;整数 -15 的 64 位二进制表示为 1111111111111111111111111111111111111111111111111111111111110...原创 2019-01-08 21:06:21 · 509 阅读 · 1 评论 -
EOJ(排序)——97. 邮件地址排序
97. 邮件地址排序现接收到一大批电子邮件,邮件地址格式为:用户名@主机域名,要求把这些电子邮件地址做主机域名的字典序升序排序,如果主机域名相同,则做用户名的字典序降序排序。输入第一行输入一个正整数 n,表示共有 n 个电子邮件地址需要排序。接下来 n 行,每行输入一个电子邮件地址(保证所有电子邮件地址的长度总和不超过 106)。对于 50% 的数据,保证 n⩽100,|si|⩽100。...原创 2019-01-09 10:19:47 · 1138 阅读 · 0 评论 -
EOJ(排序)——1072. 小强的单词本
1072. 小强的单词本大二的小强马上就要英语四级考试了,小强不想像别人一样拿着四级词汇书背啊背,于是他决定每天阅读几篇英语文章,并把其中需要记忆的单词写到 notobook 上,一周之后问题来了,单词太乱了,现在小强决定请学计算机的同学你帮他解决这个问题。输入第一行为一个数字 N ( 0 < n <= 1000 ), 接下来的 N 行中,每行只含有一个单词 (连续的小写英语字...原创 2019-01-09 12:40:39 · 284 阅读 · 0 评论 -
PAT(进制转换)——1015 Reversible Primes (20 分)
1015 Reversible Primes (20 分)A reversible prime in any number system is a prime whose “reverse” in that number system is also a prime. For example in the decimal system 73 is a reversible prime becau...原创 2019-01-14 22:37:10 · 154 阅读 · 0 评论 -
EOJ(排序)——1829. 发愁
1829. 发愁大家来到小强家,发现小强正发愁,原来小强正为 “ACM 足球超级联赛 ” 的排名而发愁。既然过生日,就应该开开心心的,所以作为超级程序员的你应当挺身而出!所以请你,天才程序员帮下忙,写个程序根据比赛情况计算出各队排名。输入有多组测试数据。每组数据先输入两个整数 n (0≤n≤10) 和 m (0≤m≤2∗n∗n),n 代表球队数量,m 代表比赛场数。接下来 m 行,每...原创 2019-01-09 18:55:03 · 589 阅读 · 0 评论 -
EOJ(排序)——1852. Ordered Fractions
1852. Ordered FractionsConsider the set of all reduced fractions between 0 and 1 inclusive with denominators less than or equal to N.Here is the set when N=5:0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5...原创 2019-01-09 20:08:02 · 302 阅读 · 0 评论 -
EOJ(排序)——1182. Relative Relatives
1182. Relative RelativesToday is Ted’s 100th birthday. A few weeks ago, you were selected by the family to contact all of Ted’s descendants and organize a surprise party. To make this task easier, yo...原创 2019-01-09 17:15:38 · 315 阅读 · 0 评论 -
EOJ(排序)——2015. 自修室
2015. 自修室一直不去自修室的 Rocker 最近迫于学习压力决定每天都要去自修,鉴于自修室多多,何必与人争挤,所以 Rocker 要坐在左右一个座位都没人,如果不是第一排,那么他的前面一个座位也没有人的位置上,当然 Rocker 也可以坐在墙边但前面或左边或右边有座位的话要没有人才可以。Rocker 眼力异常好,只要在门口瞟一眼就可以知道哪个位置上有人哪个没有人,但 Rocker 大脑毕...原创 2019-01-09 21:28:34 · 357 阅读 · 1 评论 -
Bailian——4074积水量
凹凸不平的地面每当下雨的时候总会积水。假设地面是一维的,每一块宽度都为1,高度是非负整数,那么可以用一个数组来表达一块地面。例如[0,1,0,2,1,0,1,3,2,1,2,1]可以用来表示下图地面:当下过雨后,地面就会积水,上图中蓝色的区域就是积水区域。现在给你一个数组表示地面,求下过雨后这块地面有多少积水量(假设不蒸发、不渗透)。Input第一行是一个整数m,表示有m组试样例,不超过10...原创 2019-03-14 11:33:05 · 358 阅读 · 0 评论 -
HackerRank——max-sum-subarray(最大子序列和)
You are given an array of integers.You need to find the contiguous subarray of the maximum sum in . The subarray should not contain the number . Please find the maximum sum that is possible.Note 1...原创 2019-03-14 20:43:04 · 569 阅读 · 0 评论 -
PAT(模拟)——1017 Queueing at Bank (25 分)
1017 Queueing at Bank (25 分)Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait...原创 2019-01-17 11:09:06 · 296 阅读 · 0 评论 -
HDOJ(递归)——1012.u Calculate e
Problem DescriptionA simple mathematical formula for e iswhere n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.OutputOu...原创 2019-01-11 16:02:37 · 403 阅读 · 0 评论 -
PAT甲级真题(图/连通分量)——1013. Battle Over Cities (25)
1013. Battle Over Cities (25)It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We m...原创 2019-01-06 11:32:00 · 189 阅读 · 0 评论 -
PAT甲级真题(字符串)——1006 Sign In and Sign Out (25 分)
1006 Sign In and Sign Out (25 分)At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the recor...原创 2019-01-03 16:26:53 · 259 阅读 · 0 评论 -
PAT甲级真题(动态规划)——1007 Maximum Subsequence Sum (25 分)
1007 Maximum Subsequence Sum (25 分)Given a sequence of K integers { N1, N2 , …, NK }. A continuous subsequence is defined to be { Ni, Ni+1, …, Nj} where 1≤i≤j≤K. The Maximum Subsequence is the c...原创 2019-01-03 19:43:35 · 448 阅读 · 0 评论 -
PAT甲级真题——1008 Elevator (20 分)
1008 Elevator (20 分)The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified ...原创 2019-01-03 19:57:39 · 444 阅读 · 0 评论 -
PAT甲级真题——1009. Product of Polynomials
1009. Product of PolynomialsThis time, you are supposed to find A*B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and eac...原创 2019-01-03 20:42:42 · 351 阅读 · 0 评论 -
PAT甲级真题(二分)——1010 Radix (25 分)
1010 Radix (25 分)Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is “yes”, if 6 is a decimal number and 110 is a binary number.Now for any pa...原创 2019-01-04 11:34:40 · 309 阅读 · 0 评论 -
PAT甲级真题——1011 World Cup Betting (20 分)
1011 World Cup Betting (20 分)With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World ...原创 2019-01-04 12:03:02 · 378 阅读 · 0 评论 -
PAT甲级真题(结构体排序)——1012. The Best Rank (25)
1012. The Best Rank (25)To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C – C Programming Language, M – Mathematics (Calculus or Lin...原创 2019-01-04 16:35:35 · 255 阅读 · 0 评论 -
EOJ(排序)——2031. 绝对值排序
2031. 绝对值排序给你 n(n⩽100) 个数,要求你把这 n 个数按照绝对值从小到大排序。多 Case,处理直到文件结束。输入输入一个数 n,接下来一行是 n 个整数 (−10000<n<10000)。输出排序后按照绝对值从小到大输出 n 个数,输出一行,每两个数字之间有个空格,最后一个数字后面没空格。样例input4-3 -4 1 2110output...原创 2019-01-10 15:26:18 · 516 阅读 · 0 评论 -
EOJ(排序)——2572. Sort it…
2572. Sort it…There is a database,partychen want you to sort the database’s data in the order from the least up to the greatest element,then do the query: “Which element is i-th by its value?”- with ...原创 2019-01-10 16:37:38 · 464 阅读 · 0 评论 -
EOJ(排序)——2844. 排序去重
2844. 排序去重有 n 个 1 到 1000 之间的整数 (1≤n≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉。然后再按照指定的排序方式把这些数排序。输入第 1 行为字母 A 或 D,A 表示按照升序排序,D 表示按照降序排序。第 2 行开始有若干个用一个空格或换行符分隔的正整数。输出相互之间用一个空格分隔的经去重和排序后的正整数。最后一个数后没有空格。样例i...原创 2019-01-10 21:12:43 · 774 阅读 · 0 评论 -
EOJ(排序)——2849. 成绩排序
2849. 成绩排序有 n(1⩽n⩽100)个学生的成绩记录,其中包含学号和成绩两项。按照成绩从高到低顺序输出成绩及格(⩾60)学生的学号和成绩。成绩相同时按照学号从小到大顺序输出。输入第 1 行:输入一个整数 n,表示学生记录数。第 2 行 ~ n+1 行:每行是学号(11 位数字)及成绩(0 到 100 之间的整数)。学号和成绩之间有一个空格。输出按要求输出结果,每行输出一个空格...原创 2019-01-10 21:41:34 · 722 阅读 · 0 评论 -
刷算法题常用C++知识
刷算法题常用C++知识写在前面本文适合具备c语言基础,想快速上手c++刷题的人,如有不足之处,欢迎各位评论。1.输入(cin)char a,b; cin&amp;amp;amp;amp;gt;&amp;amp;amp;amp;gt;a&amp;amp;amp;amp;gt;&amp;amp;amp;amp;gt;b; cout&amp;amp;amp;amp;lt;&amp;amp;amp;amp;lt;原创 2019-01-01 15:32:10 · 2014 阅读 · 0 评论 -
EOJ(排序)——2878. 字串排序
2878. 字串排序在 2010 年百度公司的一次校园招聘笔试中,要求应聘者设计一个 strnumcmp 函数。对比普通的 strcmp 函数,差别在于,当字符串中包含数字时,比较数字大小。数字大小相同或不含数字时,仍然沿用原来的 strcmp 方式。所有不含数字的字符串均小于含数字的字符串。每个字符串的长度范围为 1 ~ 30,而其中包含的数字个数范围为 0 ~ 8,且数字在一个字符串中是连续...原创 2019-01-11 09:49:07 · 870 阅读 · 1 评论 -
EOJ(排序)——2890. 询问队员身高
2890. 询问队员身高ECNU 篮球队教练陈老师选拔了一批篮球队员。对于篮球运动,队员身高是重要因素之一,陈老师的记忆力不好,他经常会向助理教练询问身高第 i 高的人是谁。助理教练不胜其烦,想请你帮忙写个程序回答陈老师的询问。备注:每个队员的身高都各不相同。输入第一行是一个整数 t,表示测试数据组数。对于每组测试数据:第一行是两个整数 n,m (1≤n≤50,1≤m≤50),n 表示...原创 2019-01-11 10:08:26 · 615 阅读 · 0 评论 -
EOJ(排序)——2945. Search Web Pages
2945. Search Web Pages有 N 个 Web 页面,给每个 Web 页面分配一个相关系数 Vi (Vi为正整数),输出具有最大相关系数的页面,如果具有最大相关系数的页面有多个,那么将这些页面全部输出。输入第 1 行:一个正整数 N(0<N⩽20)第 2 行 ∽ N+1 行:每行包含一个字符串和一个整数 Vi,两者之间用一个空格分隔。字符串表示 Web 页面的 URL...原创 2019-01-11 12:39:26 · 501 阅读 · 0 评论 -
CSU - 1335 高桥和低桥
有个脑筋急转弯是这样的:有距离很近的一高一低两座桥,两次洪水之后高桥被淹了两次,低桥却只被淹了一次,为什么?答案是:因为低桥太低了,第一次洪水退去之后水位依然在低桥之上,所以不算“淹了两次”。举例说明:假定高桥和低桥的高度分别是5和2,初始水位为1第一次洪水:水位提高到6(两个桥都被淹),退到2(高桥不再被淹,但低桥仍然被淹)第二次洪水:水位提高到8(高桥又被淹了),退到3。没错,文字游戏...原创 2019-03-14 21:17:25 · 182 阅读 · 0 评论