自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(65)
  • 收藏
  • 关注

原创 图灵leetcode真题解析

B站链接一、链表反转(206)解法一:迭代需要有三个变量分别来存储上一个元素的指针,当前元素的指针以及下一个元素的指针。以第一次反转为例, 第一步:先把当前元素的下一个元素指针存到next,这步只单纯为了备份当前的下一元素,即使第二步对curr.next进行修改也无妨,第四步就可以用到该备份的值。 第二步:把当前元素的的下一个元素指针置为上一个元素的指针, 第三步:把当前元素赋为上一元素。 ...

2021-08-16 00:20:26 314

原创 LeetCode动态规划简答题合集

一、爬楼梯(70)1.确定dp[i]的含义: 爬到第i层楼梯,有dp[i]种方法。2.确定递推公式:dp[i-1]向上一个台阶就是dp[i],dp[i-2]向上两个台阶也是dp[i],所以dp[i]=dp[i-1]+dp[i-2]。3.dp数组的初始化:dp[1] = 1,dp[2] = 24.确定遍历顺序:从dp[i]=dp[i-1]+dp[i-2]可以看出,一定是从前往后遍历。5.举例推导dp数组:当n=4时,结果应为5。dp[3]=dp[1]+d...

2021-08-14 23:33:13 155

原创 LeetCode树简单题合集(104、111、100、101、144、94、145)

一、104二叉树最大深度解法一:递归 public int maxDepth(TreeNode root) { if (root == null) { return 0; } int leftDepth = maxDepth(root.left); int rightDepth = maxDepth(root.right); return Math.max(leftDepth, right

2021-08-14 12:17:11 151

原创 LeetCode数组简单合集 (20)、(69)、(26)、(118、119)、(121、122)、88、136

一、有效的括号有效字符串需满足:左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。解法一:栈(常规解法) public static boolean isValid(String s) { Stack<Character>stack = new Stack<Character>(); for(char c: s.toCharArray()){ if(c=='(')stack.push

2021-08-13 13:06:12 100

原创 LeetCode双指针合集 移除元素(27)、环形链表(141)、删除有序数组中的重复项(26)

一、移除元素最暴力的就是多余的元素直接删除,数组的元素在内存地址中是连续的,删除一个元素后面所有的元素都得前移动,很明显暴力解法的时间复杂度是O(n^2)。解法:双指针法(快慢指针法)通过一个快指针和慢指针在一个for循环下完成两个for循环的工作public static int removeElement(int[] nums, int val) { int j = 0; for(int i = 0;i < nums.length...

2021-08-13 00:55:37 100

原创 LeetCode两数之和(1)、整数反转(7)、回文数(9)

1.两数之和解法一:暴力解决由于数组已经是有序,所以j初始值为i+1。public static int[] twoSum(int[] nums, int target) { for (int i = 0; i < nums.length-1; i++) { for (int j = i+1; j < nums.length; j++) { if (nums[i] + nums[j] == target) {

2021-08-12 22:34:21 82

原创 JS实现随机五位验证码与密码隐藏

<!DOCTYPE html><head> <meta charset="UTF-8"> <title>Document</title> <style> #code{ width: 180px; height: 60px; background-color: lightblue; font-size: 44px; lett.

2020-09-27 14:47:04 256

原创 统计文件中字符的个数

/*编写一个函数int charnum(char fn[10]),该函数以只读方式打开文件fn,,通过统计,返回文件中字符的个数,请使用while循环实现计数功能。注意:(1)部分源程序已存在文件中。(2)请勿修改主函数main和其他函数中的任何内容,仅在函数charnum的花括号中填写若干语句。(3)文件中的字符请使用ASCII字符。 */#include<iostream...

2020-04-24 17:10:09 5142

原创 给文本文件每一行加行号

/*打开指定的一个文本文件,在每一个行前加行号。 */#include<iostream>#include<fstream>#include<stdlib.h>#include<iomanip> //cout<<setw() 输出格式控制using namespace std;int main(){ /*(1)打开输...

2020-04-24 16:37:44 6416 6

原创 写出数据到文件中

#include<iostream>#include<fstream>using namespace std;void main(){ ofstream outfile;//L1 outfile.open("test1.txt");//outfile.open("test1.txt",ios::out); //默认方式//L2 //往"test1.txt...

2020-04-24 16:32:32 315 1

原创 HDU杭电ACM2203 //成长日记

#include&lt;stdio.h&gt;#include&lt;string.h&gt;main(){ char a[100000],b[100000],c[100000]; while(gets(a)) { gets(b); strcpy(c,a); strcat(c,a); if(strstr(c,b)!=NULL)...

2019-02-14 22:25:35 184

原创 HDU杭电ACM1097 //成长日记

#include&lt;algorithm&gt;#include&lt;string&gt;#include&lt;cstdio&gt;#include&lt;iostream&gt;using namespace std;int main(){ int a, b; while(cin &gt;&gt;a&gt;&gt;b) { int i...

2019-02-14 17:11:24 115 1

原创 HDU杭电ACM1018 //成长日记

#include&lt;stdio.h&gt;#include&lt;math.h&gt;int main(){ int T; int i,j; int n; double result; scanf("%d",&amp;T); for(i=1;i&lt;=T;i++) { result=0; scanf("%d",&amp;n); for(j=1;j&lt;...

2019-02-05 15:07:05 130

原创 HDU杭电ACM1009 //成长日记

struct加贪心,性价比高的先加。#include&lt;stdio.h&gt;#include&lt;algorithm&gt;using namespace std;struct node{ double j; double f; double x;}a[1005];int cmp(node a,node b){ return a.x&gt;b.x;}int ma...

2019-02-04 14:02:32 129

原创 HDU杭电ACM1005 //成长日记

#include&lt;stdio.h&gt;int main(){ int a,b,n,i,arr[48]; while(scanf("%d %d %d",&amp;a,&amp;b,&amp;n),a||b||n){ arr[1]=1; arr[2]=1; for(i=3;i&lt;48;i++) a...

2019-02-03 22:32:25 134

原创 HDU杭电ACM1003 //成长日记

#include&lt;stdio.h&gt;int main(){ int N; int count=1; scanf("%d",&amp;N); while(N--){ int n,i; int a[100002]; scanf("%d",&amp;n); ...

2019-02-03 22:27:26 103

原创 HDU杭电ACM1397 //成长日记

#include&lt;stdio.h&gt;#include&lt;math.h&gt;int a[100005];int main(){ int i,j,n,sum; for(i=0;i&lt;=100000;i++) { for(j=2;j&lt;=sqrt((double)i);j++) if(i%j==0) break; if(j&...

2019-02-03 14:25:18 144

原创 HDU杭电ACM1395 //成长日记

#include &lt;stdio.h&gt;int main() { int n, x, s; while (~scanf("%d", &amp;n)) { s = 1; if (n % 2 == 0 || n == 1) printf("2^? mod %d = 1\n", n); else { for (x = 1; ; x++) { s *= 2...

2019-02-03 14:06:26 133

原创 杭电ACM1393 //成长日记

#include&lt;stdio.h&gt;int main(){ int n,m,i,j; while(scanf("%d%d",&amp;n,&amp;m)) { if(n==0&amp;&amp;m==0) break; for(j=1;;j++) { if((n+m*n)%60==0) { printf("%d\n",j); br...

2019-02-02 21:50:44 192

原创 杭电ACM1391 //成长日记

#include &lt;iostream&gt;#include &lt;cstdio&gt;using namespace std;int main(){ int n, x, y; cin &gt;&gt; n; while(n--) { cin &gt;&gt; x &gt;&gt; y; if(x == y || x == y + 2) printf("%d...

2019-02-02 21:41:54 97

原创 杭电ACM1390 //成长日记

#include&lt;stdio.h&gt;int a[100];int main(){ int n,j,k,d; scanf("%d",&amp;d); while(d--) { scanf("%d",&amp;n); int i=0; while(n) { a[i+...

2019-02-02 21:41:13 409

原创 杭电ACM1334 //成长日记

#include &lt;stdio.h&gt;#include &lt;stdlib.h&gt;#define MAX 200int main(int argc, char *argv[]){ int a,b,c,d; for(a=6;a&lt;=MAX;a++) { for(b=2;b&lt;a;b++) { for(c=b;c&lt;a;c++) { ...

2019-02-02 21:40:42 105

原创 HDU杭电ACM1330 //成长日记

#include &lt;iostream&gt;#include &lt;cstdio&gt;using namespace std;int main(){ int n; cout&lt;&lt;"# Cards Overhang"&lt;&lt;endl; while((cin&gt;&gt;n)&gt;0) { double su..

2019-02-02 21:40:11 133

原创 HDU杭电ACM1339 //成长日记

#include&lt;stdio.h&gt;#include&lt;math.h&gt;int main(){ int c,n,o,p,i,k; while(scanf("%d",&amp;c)!=EOF&amp;&amp;c!=0) { for(i=0;i&lt;c;i++) { scanf("%d",&amp;n); for(p=0;

2019-02-02 21:39:44 126

原创 HDU杭电ACM1326 //成长日记

#include&lt;stdio.h&gt;int main(){ int n; int dex=1; int a[1000]; while(~scanf("%d",&amp;n)&amp;&amp;n) { printf("Set #%d\n",dex); int sum=0,i; for(i=0;i&lt;n;i++) { scanf("%d",&a

2019-02-02 21:38:50 190

原创 HDU杭电ACM1248 //成长日记

#include &lt;stdio.h&gt;int main(void){ int n; scanf("%d",&amp;n); while(n--) { int min=32777,money,temp; scanf("%d",&amp;money); for(int i=0;i&lt;=money/150;i++) { for(int j=0;j&lt...

2019-02-02 14:47:27 114

原创 HDU杭电ACM1235 //成长日记

桶排#include &lt;stdio.h&gt;#include &lt;string.h&gt;int a[101];int main(int argc, char const *argv[]){ int num,tmp; while(~scanf("%d",&amp;num),num){ memset(a,0,sizeof(a)); for(int i=0;i&lt...

2019-02-02 14:20:46 110

原创 HDU杭电ACM1234 //成长日记

#include&lt;stdio.h&gt;#include&lt;string.h&gt;struct p{ char a[20],b[8],c[8];}p[100];int main(){ int t,i,j,n,k,g; scanf("%d",&amp;t); while(t--) { k=g=0; scanf("%d",&amp;n); for(i=0...

2019-02-02 14:18:31 143

原创 HDU杭电ACM2537 //成长日记

#include&lt;stdio.h&gt;int main(){ int n,d,p,flag,i,j; char s[105]; while(scanf("%d",&amp;n)) { if(n==0)break; scanf(" %s",s); flag=0; d=p=0; for(i=0;s[i];i++) { if(s[i]==...

2019-02-01 15:32:26 131

原创 HDU杭电ACM2521 //成长日记

#include&lt;stdio.h&gt;int main(){ int m,n,a,b,i,j,k; int max,sum; scanf("%d",&amp;m); while(m--) { scanf("%d%d",&amp;a,&amp;b); max=-1; for(i=a;i&lt;=b;i++) { sum=0; for(j=1;j&l...

2019-02-01 13:58:39 114

原创 HDU杭电2519 //成长日记

#include&lt;iostream&gt;#include&lt;cstdio&gt;using namespace std;int main(void){ int m,n,t; _int64 sum; cin&gt;&gt;t; while(t--) { cin&gt;&gt;n&gt;&gt;m; sum=1; for...

2019-02-01 13:12:07 139

原创 HDU杭电ACM2523

#include&lt;stdio.h&gt;#include&lt;math.h&gt;int a[10005],b[10005];int main(){ int m,n,s,i,j,k,c; while(scanf("%d",&amp;m)!=EOF) { while(m--) { for(i=0;i&lt;10000;i++) b[i]=0; s=...

2019-02-01 13:07:29 136

原创 HDU杭电ACM2304 //成长日记

注意题目中的几个单词 power strips 插座板,我们家里用的。electrical outlet插座板上的插头。弄清楚这个就很清楚了,题目意思就是叫你,墙上只有一个插座空,然后要满足很多用电器的使用,怎么办呢?插座连插座嘛,很简单,所以问题就出来了,这样除了插座板自己有的一个插头要插到上一个去,这样一来还剩多少个孔给其他用电器来用呢??? ...

2019-01-31 16:47:26 123

原创 HDU杭电ACM2212 //成长日记

#include &lt;stdio.h&gt;int main(){ printf("1\n2\n145\n40585\n");}#include &lt;stdio.h&gt;int jieceng(int a){ int s,i; s=1; for(i=2;i&lt;=a;i++) s*=i; return s;}int weishu(int a)...

2019-01-31 16:37:47 115

原创 HDU杭电ACM2201 //成长日记

首先这是个数学问题,求n位乘客中第m位坐到正确位置的概率。我们假设有10位乘客,那么就有10个座位。首先熊猫坐了一个,要使第m位乘客能坐到正确的座位,那么熊猫肯定不能坐在那位乘客的位置上,于是得出了一个概率是9/10。假设m=2,那么除开熊猫的第一位乘客也不能坐在第2位乘客的位置上,而且是从剩下的9个位置中选取座位,得出概率8/9。那么第2位乘客就必须从剩下的8...

2019-01-31 16:23:34 146

原创 杭电ACM2200 //成长日记

#include&lt;stdio.h&gt;#include&lt;math.h&gt;int main(){ __int64 s,d; int m; while(scanf("%d",&amp;m)!=EOF) { s=pow(2,m-1); d=s*(m-2)+1; printf("%I64d\n",d); } return 0;} 

2019-01-31 16:12:24 218

原创 杭电ACM2192 //成长日记

求出现次数最多的数的数量#include&lt;iostream&gt;#include&lt;algorithm&gt;int s[10005];using namespace std;int main(){ int m,n,min,max,sum,i; cin&gt;&gt;m; while(m--) { cin&gt;&gt;n; for(i=0;i&lt;n...

2019-01-31 11:46:05 117

原创 杭电ACM2186 //成长日记

#include&lt;stdio.h&gt;int main(){ int m,n,sum,a,b,c; while(scanf("%d",&amp;m)!=EOF) { while(m--) { sum=0; scanf("%d",&amp;n); a=n/2; b=(n-a)*2/3; c=n-a-b; if(a%10&gt;0) ...

2019-01-31 00:08:53 135

原创 杭电ACM2156 //成长日记

直接暴力找规律,n=3 1/2有4个,1/3有2个;                             n=4 1/2有6个,1/3有4个,1/4有2个;                              n=4 1/2有8个,1/3有6个,1/4有4个,1/5有2个;由此得出规律,最后不要忘加上n个1;#include&lt;stdio.h&gt;int mai...

2019-01-30 23:07:02 186

原创 杭电ACM2153 //成长日记

#include&lt;stdio.h&gt;int a[11][11];int main(){ int n,i,j,temp; while(scanf("%d",&amp;n)!=EOF) { for(i=0;i&lt;11;i++) for(j=0;j&lt;11;j++) a[i][j]=0; temp=n; for(j=0;j&lt;n;j++) ...

2019-01-30 22:22:42 114

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除