算法LeetCode
包括刷Pat、LeetCode等算法题的笔记
程序员德鲁
Stay hungry,stay foolish.
展开
-
LeetCode125. 验证回文串
持续更新中,已经完成排序算法、《代码随想录》Go版代码,现在开始刷LeetCode等!欢迎一起学习和交流!原创 2022-11-07 17:01:15 · 126 阅读 · 1 评论 -
LeetCode221. 最大正方形-中等(Golang)
Go语言学习者,为了便于阅读和整理,本文代码已开源放在:持续更新中,已经完成排序算法、《代码随想录》Go版代码,现在开始刷LeetCode等!欢迎一起学习和交流!原创 2022-11-03 12:44:34 · 119 阅读 · 0 评论 -
Shuffling Machine
题目贴在最后。解析:1.第一步读懂题,英语太渣,自己就在网上多看些解析或源码2.看别人代码,原理理解,自己手写。有点惨,忽略很多细节,导致编译或提交失败多次,如for循环嵌套时,第二个for条件j打成i,导致报数组越界异常,后来调试多次才发现;再如最后输出时,减一是否必要,自己的算式到底如何,要学会理解 #include<cstdio>/*洗牌程序 首先牌初始化,按顺序排放...原创 2019-04-01 15:44:19 · 969 阅读 · 1 评论 -
素数对猜想
题目或题解在最后。代码:#include<cstdio> #include<cmath> //质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数 bool isPrime(int n) { if (n == 1 || n == 0) { return false; } if (n == 2) ...原创 2019-03-31 10:49:18 · 798 阅读 · 0 评论 -
打印沙漏
题目放在最后。代码:#include<cstdio>#include<cmath>/*题解发现公式:2*n^2-1*/int main() { int N,n,t; //符号数N,层数n,余数t char c; scanf("%d %c", &N, &c); n = sqrt((N + 1) / 2); t = N - (2 * n...原创 2019-03-31 10:47:06 · 139 阅读 · 0 评论 -
数组元素循环右移问题 (20 分)
题目放在最后。简单的思路:原始数组是ab, 我的目的是将这个数组变成ba第一步:将整个长度为N的数组倒置,得到 b-1a-1 .第二步:将 b-1 数组和 a-1 数组分别倒置, 得到 ba数组.其他:DEV-C++使用的编译器是GCC,它允许使用变量作为数组的长度定义数组。VC的编译器不是GCC,它不允许你这样做。方法1:使用动态内存分配,new和delete操作符int num...原创 2019-03-31 10:44:31 · 1071 阅读 · 0 评论 -
柳神PAT甲级真题目录
PAT甲级真题目录(按题型整理)转自https://www.liuchuo.net/archives/2502?tdsourcetag=s_pcqq_aiomsg最短路径1003. Emergency (25)-PAT甲级真题(Dijkstra算法)1018. Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS)1030. Travel ...转载 2019-02-15 19:51:19 · 4028 阅读 · 2 评论 -
PatB1001 卡拉兹(Callatz)猜想
1001 害死人不偿命的(3n+1)猜想 (15 分)卡拉兹(Callatz)猜想:对任何一个正整数 n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把 (3n+1) 砍掉一半。这样一直反复砍下去,最后一定在某一步得到 n=1。卡拉兹在 1950 年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业,一心只证 (3n+...原创 2019-02-03 09:46:25 · 264 阅读 · 0 评论 -
Rabbit的字符串
链接:https://ac.nowcoder.com/acm/contest/328/A来源:牛客网题目描述:Rabbit得到了一个字符串,她的好朋友xxx可以给这个字符串施加一次魔法。魔法可以选择字符串的任一位置,并将该位置后面的所有字符水平拼接到串首。例如:对于字符串abcde,可以通过施加魔法得到cdeab。如果xxx通过施加魔法将字符串的字典序变得严格比之前的小,那么他将拿走这...原创 2019-01-16 22:25:28 · 741 阅读 · 2 评论 -
Sign In and Sign Out
题目描述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 records of signing in’s and out’...原创 2019-01-21 22:33:26 · 248 阅读 · 0 评论 -
Spell It Right
Spell It Right (20)时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)题目描述Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit o...原创 2019-01-18 22:47:02 · 124 阅读 · 0 评论 -
RationSum
题目描述Given N rational numbers in the form “numerator/denominator”, you are supposed to calculate their sum.输入描述:Each input file contains one test case. Each case starts with a positive integer N (&l...原创 2019-01-17 22:48:42 · 106 阅读 · 0 评论 -
Pat A+B Format
1001 A+B Format (20 分)Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Specif...原创 2019-01-04 15:01:39 · 213 阅读 · 0 评论