码迷,mamicode.com
首页 > 其他好文 > 详细

hdu1005 超规模>>找规律>>有限次数循环

时间:2017-08-09 19:11:39      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:.text   post   pop   算法优化   func   lines   line   ade   ack   

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005

//由于题目有两项在变,一项有7种可能,全部共同拥有49种情况。
/*
超规模>>算法优化
     >>找规律>>规律变化
            >>有限次数内循环>>找到变化范围
*/
int main()
{
    int f[51]={49,1,1};
    int a,b,n,i;
    while( cin>>a>>b>>n,a+b+n){
         for(int i=3;i<=50;i++)
          f[i]=(a*f[i-1]+b*f[i-2])%7;
         cout<<f[n%49]<<endl;
   }
}

hdu1005 超规模&gt;&gt;找规律&gt;&gt;有限次数循环

标签:.text   post   pop   算法优化   func   lines   line   ade   ack   

原文地址:http://www.cnblogs.com/ljbguanli/p/7327065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!