hdu 1005

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

思路:找规律题

 1 #include<stdio.h>
 2 main()
 3 {
 4     int s[100];
 5     int a,b,n,i;
 6     while(scanf("%d%d%d",&a,&b,&n)!=EOF&&(a||b||n))
 7     {
 8         s[1]=1;
 9         s[2]=1;
10         for(i=3;i<=49;i++)
11         {
12             s[i]=(a*s[i-1]+b*s[i-2])%7;
13         }
14         printf("%d\n",s[n%49]);
15     }
16     return 0;
17 }
18  
时间: 2024-08-04 08:07:59

hdu 1005的相关文章

HDU 1005()

HDU 1005 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 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 val

HDU 1005 Number Sequence (数学规律)

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 104190    Accepted Submission(s): 25232 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A

HDU 1005 A计划

Problem Description 可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验.魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老.年迈的国王正是心急如焚,告招天下勇士来拯救公主.不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出. 现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用*表示,平地用.表示.骑士们一进入时空传输机就会被转到另一层的相对位

hdu 1005 数论 循环

给定 ab 与飞 f1 f2 求f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 分析: 1 因为mod7   0<=f(n)  &&f(n)<=6  有7种取值 2 f(n-1) 与f(n-2) 共有49种组合 所以找到循环取值即可 Problem : 1005 ( Number Sequence ) Judge Status : Accepted RunId : 9085676 Language : G++ Author : xiaon

HDU 1005 Number Sequence(数论)

HDU 1005 Number Sequence(数论) Problem Description: 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). Input The input consists of multiple

HDU - 1005 Number Sequence(简单矩阵快速幂)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 题意:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 就是这道题目,然而找了一晚上的错误 \("▔□▔)/\("▔□▔)/\("▔□▔)/. 1 #include <iostream> 2 #include <cstring> 3 using namespace std;

HDU 1005 Number Sequence (循环节)

首先暴力打表就很容易发现有循环节,于是一开始的写法是直接暴力找循环节,结果一直WA, 原因是有的循环并不是从1,1开始的,详细有证明戳这里:http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=19818&messageid=1&deep=0 于是借鉴了大神的思路,因为%7,故可用v[7][7]来记录 f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.这个状态.若出现相同的状态,则证明出现

HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 175657    Accepted Submission(s): 43409 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A

HDU 1005 Number Sequence 矩阵乘法 Fib数列

原题: http://acm.hdu.edu.cn/showproblem.php?pid=1005 题目大意: 按规律求出第n项. 由矩阵乘法我们可以知道: 所以对于fib数列我们可以用矩阵来求,由于矩阵可以左乘右乘,所以我们可以用快速幂来优化. #include<iostream> #include"string.h" #include<stdio.h> using namespace std; const int bc=2; const int mod =