HDU 1005 F(Contest #1)
题意:
已知f[1] = f[2] = 1,输入三个数a,b,n,求f[n] = (a*f[n-1]+b*f[n-2])%7的结果
分析:
f[n-1]和f[n-2]最多为7种情况(0,1,2,3,4,5,6),则它们的组合最多为49,即周期为49.
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <ctime>
#include <cmath>
#include <cstdlib>17:19:592016-07-25
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <iterator>
#include <vector> using namespace std; #define LL long long
#define INF 0x3f3f3f3f
#define MON 1000000007
#define MAXN 10000010
#define MAXM 1000010 const int maxn = ;
int f[maxn]; int main()
{
int a, b, n;
while(scanf("%d%d%d", &a, &b, &n)==&&a&&b&&n)
{
int i;
f[] = f[] = ;
for(i = ; i < ; i++ )
f[i] = (a*f[i-]+b*f[i-])%;
printf("%d\n", f[n%]);
} return ;
}
HDU 1005 F(Contest #1)的更多相关文章
- HDU 1005 Number Sequence(数列)
HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- HDU 1005(周期问题)
HDU 1005 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descript ...
- HDU 2802 F(N)(简单题,找循环解)
题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- HDU - 2802 F(N) (周期)
题目链接:HDU 2009-4 Programming Contest 分析:具有一定的周期性——4018处理下就可以A了 Sample Input Sample Output AC代码: #incl ...
- HDU 1005 Number Sequence(数论)
HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...
- HDU - 1005 Number Sequence 矩阵快速幂
HDU - 1005 Number Sequence Problem Description A number sequence is defined as follows:f(1) = 1, f(2 ...
- 【数位DP】 HDU 4734 F(x)
原题直通车:HDU 4734 F(x) 题意:F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1, 求0.....B中F[x]<=F[A ...
- HDU 1005 Number Sequence【斐波那契数列/循环节找规律/矩阵快速幂/求(A * f(n - 1) + B * f(n - 2)) mod 7】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- a error of misunderstanding
Last summer vacation, a classmate contacted with me and we finished a intelligent car project with i ...
- CentOS6.5安装Nginx
1.安装prce(重定向支持)和openssl(https支持,如果不需要https可以不安装.) yum -y install pcre* yum -y install openssl* 2.下载n ...
- eclipse代码自动补全[转]
一.每次输入都自动提示 设置Window->preferences->Java->Editor->Content Assist 再右下角Auto activation trig ...
- Linux启动/停止/重启Mysql数据库的方法
1.查看mysql版本 方法一:status; 方法二:select version(); 2.Mysql启动.停止.重启常用命令 a.启动方式 1.使用 service 启动: [root@loca ...
- linux下可执行程序的装载和启动
张雨梅 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-10000 1.c文件的编译 图中显示了c ...
- Too Many Connections: How to Increase the MySQL Connection Count To Avoid This Problem
1.问题描述 在启动使用mysql数据库的项目时,遇到一个报错,如下: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConn ...
- Mac环境brew安装
curl -L https://get.rvm.io | bash -s stable //RVM安装 source ~/.rvm/scripts/rvm rvm -v //版本检测 rvm list ...
- CentOS 安装 lamp(转)
一般情况下,安装的都是最新的正式版,除非你有特殊需求,要安装指定的版本,本文暂不讨论.从最基础的开始,一点点完成一个可用的 Linux 主机.这里就开始介绍如何在 CentOS 6.0 上安装 LAM ...
- Ajax些成绩批量录入
1.jsp,ajax的循环调用,必须要递归,否则会出错. <%@ page language="java" import="java.util.*" pa ...
- Ajax回调函数返回的中文字符串乱码问题
通过ajax提交请求,返回的response所带的中文字符串一直显示为乱码,写了如下代码也无效: response.setCharacterEncoding("UTF-8"); r ...