摘要:1 #include<math.h> 2 #include<stdio.h> 3 #define Z 1e-6 //因为实数是否为0的判断不能用'==',而取而代之的是判断其是否小于一个很小的数,这里用10^(-6) 4 double a[4];//必须是double型的,我刚开始是用float,结果贡献了几个WA 5 bool f(int n) 6 { 7 if(n==1){//最后处理完毕,即到达解答树叶子节点 8 if(fabs(a[0]-24)<Z) return 1;//假如最后结果==24,则返回1 9 else return 0;..
阅读全文
摘要:1 #include<stdio.h> 2 #include<stdlib.h> 3 double exp() 4 { 5 char a[10]; 6 scanf("%s",a); 7 switch(a[0]) 8 { 9 case '+': return exp()+exp();10 case '-': return exp()-exp();11 case '*': return exp()*exp();12 case '/': return exp()/exp();13 def...
阅读全文
摘要:1 #include<stdio.h> 2 int n,a[20]; 3 int cnt(int i,int sum) 4 { 5 if(!sum) return 1;//如果sum等于0,说明前面已经找到一种成功的组合方式,返回1, 6 if(i==n||sum<0) return 0;//i==n,说明找遍了数组a,但没找到符合的,返回0,如果sum<0,此路径不符合,返回0。 7 return cnt(i+1,sum-a[i])+cnt(i+1,sum); 8 } 9 int main()10 {11 scanf("%d",&n);12
阅读全文