
算法学习笔记
EOLIFE
秃秃秃
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
子字符串匹配
子字符串匹配 给定两个字符串s和t,其中t是s的子字符串,s的子字符串是字符串都取自s,并且保持在s的位置的相对顺序,但不需要是连续的。比如,s="abcdef", t="bd" 要求找出t在s中匹配的字符串数量 Input: s="rabbbit" t="rabbit" Output:3 题解 这道题类似于求最长公共子序列(lcs) 类似:不需要连续,只需要相对顺序相同 不同: lcs是子序列不确定,找相同序列的最长长度; 此题是子序列已定,母串必须包括字串的全部,问的是个数 lcs /** *原创 2021-03-10 23:09:54 · 618 阅读 · 0 评论 -
hdu2059
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; double dp[150] = {0}; int p[105] = {0}; int n, c, t; int vr, vt1, vt2; double tr; int l; int main() { while(~scanf...原创 2020-02-05 19:13:17 · 218 阅读 · 0 评论 -
hdu2058
#include <stdio.h> #include <math.h> int main() { int N, M; while(scanf("%d%d", &N, &M)) { if(N == 0 && M == 0) break; int an = (int)sqrt(M*2.0); ...原创 2020-01-27 15:32:27 · 140 阅读 · 0 评论 -
hdu2057
第一种 #include <stdio.h> void print(long long n) //10# --> 16# { int a[20]; int flag = 0; if(n < 0) {flag = 1; n = -n;} if(n == 0) printf("0"); int i = 0; while(n !=...原创 2020-01-27 13:42:13 · 370 阅读 · 0 评论 -
hdu2055
#include <cstdio> int main() { int t; char ch; int a; scanf("%d", &t); getchar(); while(t--) { scanf("%c%d", &ch, &a); if(ch >= 'a' &&...原创 2020-01-18 13:31:21 · 342 阅读 · 0 评论 -
hdu2053
#include <cstdio> #include <cmath> using namespace std; bool isInt(double x) { long int y=(long int) x; //if ((x-y)!=0)//这段代码可能会丢失精度 if((x-y)<=0.0000001&&(x-y)>=-...原创 2020-01-17 15:54:32 · 142 阅读 · 0 评论 -
hdu2049
#include <stdio.h> long long f[25] = {0, 0, 1}; long long a[25][25]; int fun() { for(int i = 3; i <= 20; i++) f[i] = (i - 1)*(f[i - 1] + f[i - 2]); } int sum() { for(int i =...原创 2020-01-06 15:38:54 · 699 阅读 · 0 评论 -
hdu2048
#include <stdio.h> long long a[25] = {0, 0, 1}; long long f[25] = {0, 1}; void fun() { for(int i = 3; i <= 20; i++) a[i] = (i - 1)*a[i - 1] + (i - 1)*a[i - 2]; } void sum() { ...原创 2020-01-02 16:29:10 · 1108 阅读 · 1 评论 -
hdu2047
#include <stdio.h> long long a[45] = {0, 2}, b[45] = {0, 1}, t[45] = {0, 3}; void fun() { for(int i = 2; i <= 40; i++) { a[i] = (a[i - 1] + b[i - 1])*2; b[i] = a[i - ...原创 2020-01-01 15:08:44 · 218 阅读 · 0 评论 -
hdu2046
#include <stdio.h> long long a[55] = {0, 1, 2}; void fun() { for(int i = 3; i <= 50; i++) a[i] = a[i - 1] + a[i - 2]; } int main() { fun(); int N; while(scanf("%d", &...原创 2020-01-01 13:32:34 · 217 阅读 · 0 评论 -
hdu2045
#include <stdio.h> long long a[55] = {0, 3, 6, 6}; void fun() { for(int i = 4; i <= 50; i++) a[i] = a[i - 1] + a[i - 2]*2; } int main() { fun(); int N; while(scanf("%...原创 2020-01-01 12:52:31 · 158 阅读 · 0 评论 -
hdu044
#include <stdio.h> long long t[55]; int fun() { t[1] = 1, t[2] = 2; for(int i = 3; i <=50; i++) t[i] = t[i - 1] + t[i - 2]; } int main() { int N; int a, b; fu...原创 2019-12-30 15:52:03 · 159 阅读 · 0 评论 -
hdu 2036
#include <stdio.h> struct Node { int x, y; }node[105]; //(x0,y0), (x1,y1), (x2, y2)是逆时针返回值为正,顺时针返回值为负 double proportion(Node a, Node b, Node c) { return 0.5*(a.x*b.y + b.x*c.y + c.x*a.y...原创 2019-12-30 13:25:17 · 148 阅读 · 0 评论 -
hdu2034
#include <stdio.h> int getIndex(int a[], int low, int high) { int tmp = a[low]; while(low < high) { while(low < high && a[high] >= tmp) high--; ...原创 2019-12-28 23:58:24 · 360 阅读 · 0 评论 -
hdu 2030
#include <stdio.h> int length(char a[]) //要善用指针 { char *ch = a; int c = 0; while(*ch != '\0') { c++; ch++; } return c; } int main() { int n; ch...原创 2019-12-27 22:25:12 · 100 阅读 · 0 评论 -
hdu2029
#include <stdio.h> int length(char a[]) //要善用指针 { char *ch = a; int c = 0; while(*ch != '\0') { c++; ch++; } return c; } bool judge(char a[], int n) { ...原创 2019-12-26 16:22:48 · 192 阅读 · 0 评论 -
hdu2028
#include <stdio.h> int gcd(int a, int b) //辗转相除法求得最大公约数 { if(a == 0) return b; else return gcd(b % a, a); } int Sort(int a[], int n) //冒泡排序 { for(int i = 0; i &l...原创 2019-12-26 15:38:57 · 251 阅读 · 0 评论 -
hdu2021
#include <stdio.h> int a[10] = {100, 50, 10, 5, 2, 1}; int fun(int t) { int cnt = 0, i; for(i = 0; i < 6; i++) { if(t >= a[i]) { cnt += t / a[i]; t ...原创 2019-12-25 13:18:17 · 180 阅读 · 0 评论 -
hdu2014
#include <stdio.h> int a[35]; int cal(int n) //记忆化 { a[n] = 1; for(int i = n - 1; i >= 1; i--) a[i] = (a[i + 1] + 1) * 2; } int cal2(int n) //递推 { if(n == 1) r...原创 2019-12-25 10:03:15 · 128 阅读 · 0 评论 -
hdu2000 ASCII码排序
#include <stdio.h> void sortAscll(char &a, char &b) { char tmp; if(a > b) { tmp = a; a = b; b = tmp; } } int main() { char a, b, c; w...原创 2019-12-23 22:30:20 · 129 阅读 · 0 评论