随笔分类 -  算法训练

摘要://连续正整数的和 #include<stdio.h> int main(){ int n,i=1,j,sum=0; scanf("%d",&n); while(i < n/2+1){ sum = i; for(j=i+1;j<n;j++){ sum += j; if(sum>=n) break; 阅读全文
posted @ 2020-02-04 08:05 Hqx_curiosity 阅读(257) 评论(0) 推荐(0)
摘要://求先序排列 //已知中序和后序,求先序,递归 #include<stdio.h> #include<string.h> #define MAXN 8 //5个参数 中序序列,后序序列,根位置,开始下标,结束下标 void pre(char infixOrder[],char rearOrder[ 阅读全文
posted @ 2020-02-02 17:27 Hqx_curiosity 阅读(344) 评论(0) 推荐(0)
摘要://区间K大数查询 #include<stdio.h> int main(){ int n,m,l,r,k,index = 0; scanf("%d",&n); int a[n]; for(int i=1;i<=n;i++) scanf("%d",&a[i]); scanf("%d",&m); wh 阅读全文
posted @ 2020-02-02 17:07 Hqx_curiosity 阅读(164) 评论(0) 推荐(0)
摘要://确定元音字母位置 #include<stdio.h> #include<string.h> #define MAXN 100 int main(){ char str[MAXN]; scanf("%s",str); int length = strlen(str); for(int i=1;i< 阅读全文
posted @ 2020-02-02 11:24 Hqx_curiosity 阅读(355) 评论(0) 推荐(0)
摘要://入学考试 //01背包问题 动态规划 dp[i][j]表示当前剩余容量为j,已判定了i个物品,背包的最优情况 #include<stdio.h> #include<string.h> int max(int a,int b){ return a>b?a:b; } int main(){ int 阅读全文
posted @ 2020-02-02 09:21 Hqx_curiosity 阅读(301) 评论(0) 推荐(0)
摘要://删除数组零元素 #include<stdio.h> int main(){ int i,n,count; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++){ if(a[i] != 0){ 阅读全文
posted @ 2020-02-01 15:02 Hqx_curiosity 阅读(152) 评论(0) 推荐(0)
摘要://输出米字型 #include<stdio.h> #include<string.h> int main(){ int n,i; scanf("%d",&n); char s[25][51]; //A与A之间点的个数 n-2 for(i=0;i<n-1;i++){ memset(s[i],'.', 阅读全文
posted @ 2020-01-31 20:15 Hqx_curiosity 阅读(652) 评论(0) 推荐(0)
摘要://数的统计 #include<stdio.h> #include<stdlib.h> int comp(const void *a,const void *b){ return *(int*)a - *(int*)b; } int main(){ int i,N,num=0; scanf("%d" 阅读全文
posted @ 2020-01-31 13:46 Hqx_curiosity 阅读(185) 评论(0) 推荐(0)
摘要://数对 #include<stdio.h> int main(){ int n,i,j; scanf("%d",&n); for(i=1;i<=n;i++){ for(j=n;j>=1;j--){ if(i*j == n) printf("%d*%d = %d\n",i,j,n); } } ret 阅读全文
posted @ 2020-01-31 13:07 Hqx_curiosity 阅读(140) 评论(0) 推荐(0)
摘要://数组查找及替换 #include<stdio.h> #include<stdlib.h> int comp(const void *a,const void *b){ return *(int*)a - *(int*)b; } int main(){ int N,b; int a[101]; s 阅读全文
posted @ 2020-01-31 09:26 Hqx_curiosity 阅读(291) 评论(0) 推荐(0)
摘要://数组排序去重 #include<stdio.h> #include<stdlib.h> int comp(const void*a,const void*b)//用来做比较的函数。 { return *(int*)a - *(int*)b; } int main(){ int a[10]; fo 阅读全文
posted @ 2020-01-30 20:12 Hqx_curiosity 阅读(204) 评论(0) 推荐(0)
摘要://素因子去重 #include<stdio.h> int num[4000000] = {0}; int main(){ long long n,ans; scanf("%d",&n); if(n==2){ printf("%d",n); return 0; } for(int k=2;k<=n; 阅读全文
posted @ 2020-01-30 19:59 Hqx_curiosity 阅读(157) 评论(1) 推荐(0)
摘要://特殊的数字四十 #include<stdio.h> int main(){ int i,sum,n; for(i=1000;i<10000;i++){ sum = 0; n = i; while(n>0){ sum += n%10; n /= 10; } if(sum == 10) printf 阅读全文
posted @ 2020-01-30 17:46 Hqx_curiosity 阅读(344) 评论(0) 推荐(0)
摘要:#include<stdio.h> #include<string.h> int main(){ int i,count=0,length; char str[101]; scanf("%s",str); length = strlen(str); for(i=0;i<length;i++){ if 阅读全文
posted @ 2020-01-30 17:13 Hqx_curiosity 阅读(168) 评论(0) 推荐(0)
摘要://未名湖边的烦恼 //递归 #include<stdio.h> int fun(int m,int n){ if(m<n) //还鞋数小于租鞋数 return 0; if(n==0) return 1; return (fun(m-1,n) + fun(m,n-1)); } int main(){ 阅读全文
posted @ 2020-01-30 17:04 Hqx_curiosity 阅读(108) 评论(0) 推荐(0)
摘要://斜率计算 #include<stdio.h> int main(){ int x1,x2,y1,y2,k; scanf("%d%d\n%d%d",&x1,&y1,&x2,&y2); if(x2-x1 == 0) printf("INF"); else{ k = (y2-y1)/(x2-x1); 阅读全文
posted @ 2020-01-29 23:26 Hqx_curiosity 阅读(250) 评论(0) 推荐(0)
摘要://学做菜 #include<stdio.h> int main(){ int a,b,c,d,num = 0; scanf("%d\n%d\n%d\n%d",&a,&b,&c,&d); while(1){ if(a>=2 && b>=1 && d >=2){ //可以做菜品1 num++; a-= 阅读全文
posted @ 2020-01-29 16:21 Hqx_curiosity 阅读(260) 评论(0) 推荐(0)
摘要://寻找数组中的最大值 #include<stdio.h> int main(){ int i,n,max,index; scanf("%d\n",&n); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); max = a[0]; index = 0; fo 阅读全文
posted @ 2020-01-29 14:00 Hqx_curiosity 阅读(186) 评论(0) 推荐(0)
摘要://一元三次方程求解 //直接枚举 #include<stdio.h> #include<math.h> double a,b,c,d,x; double f(double x){ return a*x*x*x + b*x*x + c*x + d; } int main(){ scanf("%lf% 阅读全文
posted @ 2020-01-29 13:50 Hqx_curiosity 阅读(355) 评论(0) 推荐(0)
摘要://整除问题 #include<stdio.h> int main(){ int min,max,factor; scanf("%d %d %d",&min,&max,&factor); for(int i=min;i<=max;i++){ if(i%factor == 0) printf("%d 阅读全文
posted @ 2020-01-28 22:01 Hqx_curiosity 阅读(217) 评论(0) 推荐(0)