简单算法笔记
穷举法:暴力破解
迭代法:1.确定迭代对象;
2.建立迭代关系式;
3.对迭代过程进行控制;
平方根:n,a.b;
while(math.abs(a-b)>1E-15)
a=(a+b)/2;
b=n/a;
不知道几位数的情况下需要得到各个位数:
while(n!=0)
{
sum=sum+n%10;
n=n/10;
}
判断N个数字互不相同的函数:
int is_ok(int n){
int[] v=new int[10]={0};
int i=0,sum=0,c=0;
while(n>0)
v[n%10]=1; n=n/10; c++
for(i=0;i<10;i++)
sum+=v[i];
if(sum==c)
return 1;
else
return 0;
}
递归
组合数递归:从n个中选r个人组合=在n-1个人中选r个人+在n-1个人中选r-1个人