SDUT_基本算法

problem 1:贪心,我二了。。。

problem 2:对这题表示无语,我担心快速幂函数会超,所以10^6一次分开幂的,WA了,直接用快速幂函数算就对了,我无语了。。。

快速幂函数:

int exp_mod(int a,int n,int b)
{
int t;
if(n==0) return 1%b;
if(n==1) return a%b;
t=exp_mod(a,n/2,b);
t=t*t%b;
if((n&1)==1) t=t*a%b;
return t;
}

 problem 3:母函数模板题。

 problem 4:按速度排序,然后枚举所有的路,直到find(start) == find(end)结束。然后用最大值减去最小值,求其差,取差最小。并查集最好写状态压缩,虽然有时候是没必要的。

posted @ 2011-11-22 21:22  AC_Von  阅读(252)  评论(0编辑  收藏  举报