llllmz

导航

上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 35 下一页

2024年2月21日

128. 最长连续序列C

摘要: o(n)现在水平不够。 采用先快排序,再找。O(nlogn),注意每次划分枢纽选择中间节点(中间节点和首节点互换) int divide(int* nums,int head,int tail){ int x=nums[(head+tail)/2]; nums[(head+tail)/2]=nums 阅读全文

posted @ 2024-02-21 19:56 神奇的萝卜丝 阅读(35) 评论(0) 推荐(0)

49. 字母异位词分组c++

摘要: 刷力扣还有点不太习惯,主要是C++只学了皮毛。 看了官方活用map就是好啊。 把字母都排好序 然后判断就好了。 map<string,vector<string>> m; for(int i=0;i<strs.size();i++){ string tem=strs[i]; sort(tem.beg 阅读全文

posted @ 2024-02-21 18:40 神奇的萝卜丝 阅读(19) 评论(0) 推荐(0)

1. 两数之和C

摘要: 原本想排下序的,但要求返回下标,又感觉要添加其他东西了,太麻烦了。暴力找就好了。 阅读全文

posted @ 2024-02-21 15:03 神奇的萝卜丝 阅读(10) 评论(0) 推荐(0)

2024年2月19日

DP19 最长公共子序列(一)C

摘要: 建议直接网上看思路.... #include<stdio.h> int max(int i,int j){ if(i>j) return i; return j; } int maxlength[1001][1001]; int main(){ int n,m; while(scanf("%d %d 阅读全文

posted @ 2024-02-19 15:39 神奇的萝卜丝 阅读(15) 评论(0) 推荐(0)

KY78 最大上升子序列和C++

摘要: 这个解决问题的思路使用动态规划,即用已知状态去得到未知状态。 思路逻辑是这样 sum[i]记录以A[i]为末上升子序列的和的最大值 然后从j 从 0-i-1 遍历 如果A[j]<A[i] 那么 sum[i]=sum[j]+A[i]; 然后找出sum[i]中的的最大值,就是以A[i]为末上升子序列的和 阅读全文

posted @ 2024-02-19 14:24 神奇的萝卜丝 阅读(26) 评论(0) 推荐(0)

2024年2月18日

KY22 最大序列和C

摘要: 题目例子给的很好,还有不要遗漏全是负数的情况。 #include<stdio.h> #include<math.h> int main(){ long long n=0; while(scanf("%ld",&n)!=EOF){ long long sum=0; long long max=0; i 阅读全文

posted @ 2024-02-18 18:37 神奇的萝卜丝 阅读(133) 评论(0) 推荐(0)

KY225 N阶楼梯上楼问题C++

摘要: #include<iostream> using namespace std; int main(){ int n=0; int f[90]; f[1]=1; f[2]=2; while(cin >> n){ for(int i=3;i<=n;i++){ f[i]=f[i-1]+f[i-2]; } 阅读全文

posted @ 2024-02-18 18:07 神奇的萝卜丝 阅读(18) 评论(0) 推荐(0)

畅通工程续C

摘要: 考迪杰斯特拉算法。 #include<stdio.h> struct node{ int n1; int n2; int weight; }; typedef struct node edge; edge e[1000]; void init_dist(int dist[],int n){ for( 阅读全文

posted @ 2024-02-18 17:15 神奇的萝卜丝 阅读(10) 评论(0) 推荐(0)

KY148 还是畅通工程C++

摘要: 求图的最小生成树。克鲁斯卡尔算法来解决。就是选择n-1条最小边且无回路。 回路判断用并查集就行。 即要加入的边(两个节点)具有相同的父节点说明如果这两个节点本来就存在路径,再加入一条边就会产生回路,舍去。 #include<iostream> #include<algorithm> using na 阅读全文

posted @ 2024-02-18 16:29 神奇的萝卜丝 阅读(27) 评论(0) 推荐(0)

2024年2月15日

KY175 连通图C

摘要: 最近实在是太偷懒了,再这样下去复试直接寄。要努努力了。 简单一点可以用并查集,不嫌麻烦DFS/BFS都可以判断是否连通。 #include<stdio.h> void swap(int* x,int* y){ if(*x >*y){ int t=*x; *x=*y; *y=t; } } int fa 阅读全文

posted @ 2024-02-15 15:04 神奇的萝卜丝 阅读(22) 评论(0) 推荐(0)

上一页 1 ··· 25 26 27 28 29 30 31 32 33 ··· 35 下一页