codeforces 450B. Jzzhu and Sequences 解题报告
题目链接:http://codeforces.com/problemset/problem/450/B
题目意思:给出 f1 和 f2 的值,以及n,根据公式:fi = fi-1 + fi+1,求出fn是多少。
这题通过手工模拟,可以发现它有一个周期的:以6为周期!
f1 = f1, f2 = f2, f3 = f2 - f1
f4 = -f1, f5 = -f2, f6 = -f2 + f1
以前从来不知道负数的模怎么求,这题刚好考到!其实根据第二个test约莫猜到,就是要加上要mod的那个数,即1e9+7,可恨的是,一开始 mod多少没有搞清楚(写成n mod 7了),mod 7 = 0,即f[7]其实是等于f[1]的;然后改了之后又把while写成if(这个while结束的条件是被除数 > 0为止)被人hack了,还全然不知呢,最后查不出来......唉,经验还是很不够啊,继续努力!!!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; typedef long long ll;
ll f[+];
ll x, y, n; int main()
{
while (scanf("%lld%lld%lld", &x, &y, &n) != EOF)
{
ll MOD = 1e9+;
f[] = x;
f[] = y;
f[] = y - x;
f[] = -x;
f[] = -y;
f[] = x - y;
n %= ;
if (n == ) // 因为没有f[0]的定义!f[k*6] 是等于 f[6]的!
{
while (f[] < )
f[] += MOD;
printf("%lld\n", f[]%MOD);
}
else
{
while (f[n] < )
f[n] += MOD;
printf("%lld\n", f[n]%MOD);
}
}
return ;
}
codeforces 450B. Jzzhu and Sequences 解题报告的更多相关文章
- CodeForces 450B Jzzhu and Sequences (矩阵优化)
CodeForces 450B Jzzhu and Sequences (矩阵优化) Description Jzzhu has invented a kind of sequences, they ...
- CodeForces - 450B Jzzhu and Sequences —— 斐波那契数、矩阵快速幂
题目链接:https://vjudge.net/problem/CodeForces-450B B. Jzzhu and Sequences time limit per test 1 second ...
- CodeForces 450B Jzzhu and Sequences 【矩阵快速幂】
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- codeforces 450C. Jzzhu and Chocolate 解题报告(449A)
题目链接:http://codeforces.com/contest/450/problem/C 题目意思:给出一个 n * m 大小的chocolate bar,你需要在这个bar上切 k 刀,使得 ...
- codeforces 447C. DZY Loves Sequences 解题报告(446A)
题目链接:http://codeforces.com/problemset/problem/447/C 题目意思:给出 一个 包含 n 个数的序列你,从中需要找出这个序列的最长子串,满足在里面只修改其 ...
- CodeForces 450B Jzzhu and Sequences 费波纳茨数列+找规律+负数MOD
题目:Click here 题意:给定数列满足求f(n)mod(1e9+7). 分析:规律题,找规律,特别注意负数取mod. #include <iostream> #include &l ...
- CodeForces 450B Jzzhu and Sequences
矩阵快速幂. 首先得到公式 然后构造矩阵,用矩阵加速 取模函数需要自己写一下,是数论中的取模. #include<cstdio> #include<cstring> #incl ...
- CodeForces 450B Jzzhu and Sequences(矩阵快速幂)题解
思路: 之前那篇完全没想清楚,给删了,下午一上班突然想明白了. 讲一下这道题的大概思路,应该就明白矩阵快速幂是怎么回事了. 我们首先可以推导出 学过矩阵的都应该看得懂,我们把它简写成T*A(n-1)= ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
随机推荐
- *LOJ#6227. 「网络流 24 题」最长k可重线段集问题
$n \leq 500$条平面上的线段,问一种挑选方法,使得不存在直线$x=p$与挑选的直线有超过$k$个交点,且选得的直线总长度最长. 横坐标每个点开一个点,一条线段就把对应横坐标连一条容量一费用( ...
- keepalived学习
HA集群 keepalived heartbeat corosync cman 功能实现 vrrp协议在Linux主机上以守护进程方式, 能够根据配置文件自动生成ipvs规则 对各RS健康状态检测 组 ...
- LeetCode OJ--Partition List
http://oj.leetcode.com/problems/partition-list/ 链表的处理 #include <iostream> using namespace std; ...
- 你还在为移动端选择器picker插件而捉急吗?
http://www.cnblogs.com/jingh/p/6381079.html 开题:得益于项目的上线,现在终于有时间来写一点点的东西,虽然很浅显,但是我感觉每经历一次项目,我就学到了很多的东 ...
- PR物料KFF弹出LOV - WHERE条件重写
PROCEDURE event (event_name VARCHAR2)IS---- This procedure allows you to execute your code at specif ...
- android 获得SDCard信息
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...
- Mysql 性能优化20个原则(3)
12. Prepared Statements Prepared Statements很像存储过程,是一种运行在后台的SQL语句集合,我们可以从使用 prepared statements 获得很多好 ...
- iOS 合并.a文件,制作通用静态库
lipo -create SQY/iOS/iphoneos/libGamePlusAPI.a SQY/iOS/iphonesimulator/libGamePlusAPI.a - output ...
- Android 最新控件 Toolbar
之前Android的ActionBar好像做项目从没用过.除了google自己,并没有多少人用,究其原因,主要是由于ActionBar不够灵活,不可以随心所欲的定制,后来Goole也发现了这一点,然后 ...
- vimrc 避免中文乱码配置
et smsyntax onset ts=4set sts=4set sw=4set hlsearchset rulerset backspace=indent,eol,startset encodi ...