codeforces 450 B Jzzhu and Sequences

题意:给出f1=x,f2=y,f(i)=f(i-1)+f(i+1),求f(n)模上10e9+7

因为 可以求出通项公式:f(i)=f(i-1)-f(i-2)

然后

f1=x;

f2=y;

f3=y-x;

f4=-x;

f5=-y;

f6=-y+x;

f7=x; 发现是以6为循环的

还有注意下余数为正,就每次加上一个mod再模上mod

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include <cmath>
 5 #include<stack>
 6 #include<vector>
 7 #include<map>
 8 #include<set>
 9 #include<queue>
10 #include<algorithm>
11 using namespace std;
12
13 typedef long long LL;
14 const int INF = (1<<30)-1;
15 const int mod=1000000007;
16 const int maxn=100005;
17
18 LL a[15];
19
20 int main(){
21     LL x,y,n;
22     cin>>x>>y;
23     cin>>n;
24     a[1]=(x+mod)%mod;
25     a[2]=(y+mod)%mod;
26     a[3]=(y-x+2*mod)%mod;
27     a[4]=(-x+mod)%mod;
28     a[5]=(-y+mod)%mod;
29     a[0]=(-y+x+2*mod)%mod;
30     cout<<a[n%6]<<"\n";
31     return 0;
32 }

时间: 2024-08-29 00:07:34

codeforces 450 B Jzzhu and Sequences的相关文章

Codeforces 450 C. Jzzhu and Chocolate

//area=(n*m)/ ((x+1)*(k-x+1)) //1: x==0; //2: x=n-1 //3: x=m-1 # include <stdio.h> long long max(long long x,long long y) { return x>y?x:y; } int main() { long long n,m,k,sum,t,ans; scanf("%lld%lld%lld",&n,&m,&k); sum=n+m-2;

Codeforces Round 450 Div2 B.Jzzhu and Sequences

B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has invented a kind of sequences, they meet the following property: ![](https://codeforces.com/predownloaded/55/

Codeforces Round #258 (Div. 2) B. Jzzhu and Sequences(矩阵快速幂)

题目链接:http://codeforces.com/problemset/problem/450/B ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

【矩阵快速幂 】Codeforces 450B - Jzzhu and Sequences (公式转化)

[题目链接]click here~~ [题目大意] Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo1000000007(109?+?7). [解题思路] /*A - Jzzhu and Sequences Codeforces 450B - Jzzhu and Sequences ( 矩阵快速幂 )

[2016-04-13][codeforces][447][C][DZY Loves Sequences]

时间:2016-04-13 23:39:47 星期三 题目编号:[2016-04-13][codeforces][447][C][DZY Loves Sequences] 题目大意:给定一串数字,问改变其中一个数字之和,最长能得到多长的严格增加的子串 分析: 维护每个数字往左和往右能延续多长(严格减,增),然后枚举每个点, 如果这个点已经在一个严格增加的序列中,那么ans =min(n, max(ans , l[i] + r[i] + 1)) 即左右两边延伸之后,改变后面非递增的一个数字 注意这

Codeforces 449D:Jzzhu and Numbers

Codeforces 449D:Jzzhu and Numbers 题目链接:http://codeforces.com/problemset/status?friends=on 题目大意:给出$n$个数,求有多少种组合使得$a_{i_1}\&a_{i_2}\&...\&a_{i_k}=0(0 \leqslant i < n)$,答案对$10^9+7$取模. 容斥原理+DP 设位与$(\&)$后二进制表示中有$k$个$1$的组合数为$A_k$,则有, $A_0=$所有

Codeforces 450(#257 (Div. 2) ) 解题报告

A: 1 // File Name: a.cpp 2 // Author: darkdream 3 // Created Time: 2014年07月19日 星期六 21时01分28秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<set> 9 #include<deque> 10 #include<stack> 11 #include<bits

codeforces#FF(div2) DZY Loves Sequences

n个数,可以任意改变其中一个数,求最长的上升子区间长度 思路:记录一个from[i]表示从位置i的数开始最长的上升区间长度 记录一个to[i]表示到位置i的数所能达到的最长上升区间长度 枚举要改变的数的位置i,此时能达到的长度为to[i - 1] + from[i + 1] + 1,取最大值 //#pragma comment(linker, "/STACK:102400000,102400000") //HEAD #include <cstdio> #include &l

CodeForces 425C Sereja and Two Sequences

题意: 两组数字a和b  如果a[i]等于b[j]  则可将a[i]和b[j]前所有数字删掉  这种操作花费e体力  得到1元钱  或者一次删掉所有数字  这种操作花费等于曾经删除的所有数字个数  做完后得到所有钱  问 一共s体力 可以得到多少钱 思路: dp+二分 由数据可知最多拿到300元钱  因此可以定义  dp[i][j]表示有i元钱时  b串删除到了j处时  a串删到的位置 状态转移为 dp[i][j] = lower_bound ( a[j] , dp[i-1][j-1] + 1