- 博客(9)
- 收藏
- 关注
原创 《算法笔记》贪心
贪心法是求解一类最优划问题的方法,它总是考虑在当前状态下局部最优(较优)的策略,来使得全局的结果达到最优(较优) 举例 销售月饼 #include <cstdio> #include <algorithm> using namespace std; struct mooncake{ double store; double sell; double price; }cake[1010]; bool cmp(mooncake a,mooncake b){
2021-11-29 09:26:55
369
原创 《算法笔记》散列
散列(hash) 思想:空间换时间 引例:M个整数中查找N个数 遍历N次,时间复杂度O(MN) 改进:直接用让数组下标=整数 查找时实现时间复杂度O(1) 字符串均由大写字母A~Z组成 (0~25) int hashFunc(char s[],int len){ int id=0; for(int i=0;i<len;i++){ id=id*26+(s[i]-'A'); //二十六进制转换为十进...
2021-11-28 16:46:42
127
原创 《算法笔记》排序
void selectsort(){ for (int i = 1; i <=n; i++) { int k=i; for (int j = i; j <=n; j++) { if(A[j]<A[K]){ k=j; } } int temp=A[i]; A[i]=A[k]; A[k]=temp; } }
2021-11-28 14:42:56
123
原创 《算法笔记》说反话
#include <cstdio> #include <cstring> int main() { char str[90]; gets(str); int len=strlen(str),r=0,h=0; char ans[90][90]; for(int i=0;i<len;i++){ if(str[i]!=' '){ ans[r][h++]=str[i]; }else{ .
2021-11-27 23:22:25
464
原创 《算法笔记》回文串
#include <cstdio> #include <cstring> const int max=256; bool judge(char str[]){ int len= strlen(str); for(int i=0;i<len/2;i++){ if(str[i]!=str[len-1-i]){ return false; } } return true; } int main.
2021-11-27 22:38:08
411
原创 《算法笔记》A+B进制转换
#include <cstdio> int main() { int a,b,d; scanf("%d%d%d",&a,&b,&d); int sum=a+b; int ans[31],num=0; do{ ans[num++]=sum%d; sum/=d; } while(sum!=0); for (i.
2021-11-27 18:31:01
66
原创 《算法笔记》日期差值
#include <cstdio> int month[13][2]={{0,0}, {31,31}, {28,29}, {31,31}, {30,30}, {31,31}, {30,30}, {31,31}, .
2021-11-27 18:16:07
70
原创 《算法笔记》
学习目标: 提示:这里可以添加学习目标 例如:一周掌握 Java 入门知识 学习内容: 构造函数 重新定义了函数,定义结构体变量前须初始化 #include <stdio.h> struct Point{ int x; int y; Point(){}; //用以不经初始化定义Pt[10] Point(int _x,int _y):x(_x),y(_y){} //用以提供x、y的初始化 }Pt[10]; int main(){ in
2021-11-26 19:50:47
241
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人