hdu 1005(找规律--循环节)
2014-04-01 21:53
316 查看
题目链接:点击打开链接
题目大意:A number sequence is defined as follows:
f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.
Given A, B, and n, you are to calculate the value of f(n).
题目分析:一般数学题:1.结论问题;
2.递推
3.打表找规律
这道题之前还去用过递推,解方程,但是由于f【n】和F【n-1】等是有关系的,所以完全可以找循环节(即前后连着的与某个位置的前后两个位置相同这一定是循环节),再则相邻2个数之间的搭配(7*7=49 )种,所以完全不用担心循环节的长度
题目总结:姿势要优美,一般正确的代码一定是简洁干净的
题目大意:A number sequence is defined as follows:
f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.
Given A, B, and n, you are to calculate the value of f(n).
题目分析:一般数学题:1.结论问题;
2.递推
3.打表找规律
这道题之前还去用过递推,解方程,但是由于f【n】和F【n-1】等是有关系的,所以完全可以找循环节(即前后连着的与某个位置的前后两个位置相同这一定是循环节),再则相邻2个数之间的搭配(7*7=49 )种,所以完全不用担心循环节的长度
题目总结:姿势要优美,一般正确的代码一定是简洁干净的
#include<algorithm> #include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<cmath> using namespace std; int f[105]; int main() { int a,b,n,flag=1,i,j,start,end; while(1) { scanf("%d%d%d",&a,&b,&n); if(!a||!b||!n) break; f[1]=f[2]=1; flag=0; for(i=3; i<=n&&!flag; i++) { f[i]=(a*f[i-1]+b*f[i-2])%7; // printf("n:%d %xbd\n",i,f[i]); for(j=2; j<i-1; j++) { if(f[j]==f[i]&&f[j-1]==f[i-1]) { flag=1;start=j,end=i; break; } } } if(flag) n=(n-start)%(end-start)+start; printf("%d\n",f ); } return 0; }
相关文章推荐
- hdu 1005 (规律 循环节)
- HDU 1005 循环节(找规律题目)
- HDU1005 规律题
- HDU 1005 Number Sequence(循环节) *
- [规律] hdu 1005 Number Sequence#坑爹一水
- HDU——1005(找规律)
- HDU 1005 Number Sequence 打表找循环节
- hdu 4588Count The Carries(循环节 规律题目)
- hdu 1005 找规律(循环点)
- hdu1005 Number Sequence寻找规律题
- HDU 1005 Number Sequence (数学规律)
- hdu 3524 Perfect Squares(找规律,循环节,快速幂取模)
- HDU 1005 Number Sequence【循环节(取模)】
- HDU 1005 Number Sequence (寻找循环节)
- HDU 1005题解,这种题目关键在于寻找循环节,这很重要1,很容易找到循环环节是49,AC就是理所当然
- HDU 1005 找规律
- HDU-1005(规律题)
- Number Sequence_hdu_1005(规律)
- hdu 1005 循环节
- HDU 1005 循环节查找