思路:找规律发现这个数是斐波那契第2*k+3项-1,数据较大矩阵快速幂搞定.
 
快速幂入门第一题QAQ
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <ctype.h>
//******************************************************
#define lrt (rt*2)
#define rrt (rt*2+1)
#define LL long long
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define exp 1e-8
//***************************************************
#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 2e18
#define LL long long
#define ULL unsigned long long
#define PI acos(-1.0)
#define pb push_back
#define mk make_pair #define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SQR(a) ((a)*(a))
#define Unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define Iterator(a) __typeof__(a.begin())
#define rIterator(a) __typeof__(a.rbegin())
//#define FastRead ios_base::sync_with_stdio(0);cin.tie(0)
#define FastRead ios::sync_with_stdio(false);
#define CasePrint pc('C'); pc('a'); pc('s'); pc('e'); pc(' '); write(qq++,false); pc(':'); pc(' ')
#define vi vector <int>
#define vL vector <LL>
#define For(I,A,B) for(int I = (A); I < (B); ++I)
#define FOR(I,A,B) for(int I = (A); I <= (B); ++I)
#define rFor(I,A,B) for(int I = (A); I >= (B); --I)
#define Rep(I,N) For(I,0,N)
#define REP(I,N) FOR(I,1,N)
using namespace std;
const int maxn=1e5+10;
#define mod 998244353 struct Matirx {
int h,w;
LL a[5][5];
}ori,res,it;
LL f[5]={0,1,1};
void iint(){
it.w=2;it.h=1;it.a[1][1]=1;it.a[1][2]=0;
res.w=res.h=2;
memset(res.a,0,sizeof(res.a));
res.a[1][1]=res.a[2][2]=1;
ori.w=ori.h=2;
memset(ori.a,0,sizeof(ori.a));
ori.a[1][1]= 1;ori.a[1][2]= 1;
ori.a[2][1]= 1;ori.a[2][2]= 0;
}
Matirx multy(Matirx x,Matirx y){
Matirx z;z.w=y.w;z.h=x.h;
memset(z.a,0,sizeof(z.a));
for(int i=1;i<=x.h;i++){
for(int k=1;k<=x.w;k++){
if(x.a[i][k]==0) continue;
for(int j=1;j<=y.w;j++)
z.a[i][j]=(z.a[i][j]+x.a[i][k]*y.a[k][j]%mod)%mod;
}
}
return z;
} LL Matirx_mod(LL n){
if(n<2) return f[n];
else n-=1;
while(n){
if(n&1) res=multy(ori,res);
ori=multy(ori,ori);
n>>=1;
}
res=multy(it,res);
return res.a[1][1]%mod;
} int main()
{
LL n;
while(scanf("%I64d",&n)!=EOF)
{
iint();
printf("%I64d\n",Matirx_mod(2*n+3)-1);
}
return 0;
}

HDU 6198(2017 ACM/ICPC Asia Regional Shenyang Online)的更多相关文章

  1. hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】

    hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组 ...

  2. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  3. 2017 ACM/ICPC Asia Regional Shenyang Online(部分题解)

    HDU 6197 array array array 题意 输入n和k,表示输入n个整数和可以擦除的次数k,如果至多擦除k次能是的数组中的序列是不上升或者是不下降序列,就是魔力数组,否则不是. 解题思 ...

  4. 2017 ACM/ICPC Asia Regional Shenyang Online:number number number hdu 6198【矩阵快速幂】

    Problem Description We define a sequence F: ⋅ F0=0,F1=1;⋅ Fn=Fn−1+Fn−2 (n≥2). Give you an integer k, ...

  5. HDU 6205(尺取法)2017 ACM/ICPC Asia Regional Shenyang Online

    题目链接 emmmm...思路是群里群巨聊天讲这题是用尺取法.....emmm然后就没难度了,不过时间上3000多,有点.....盗了个低配本的读入挂发现就降到2800左右, 翻了下,发现神犇Clar ...

  6. HDU - 6215 2017 ACM/ICPC Asia Regional Qingdao Online J - Brute Force Sorting

    Brute Force Sorting Time Limit: 1 Sec  Memory Limit: 128 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  7. 2017 ACM/ICPC Asia Regional Shenyang Online array array array

    2017-09-15 21:05:41 writer:pprp 给出一个序列问能否去掉k的数之后使得整个序列不是递增也不是递减的 先求出LIS,然后倒序求出最长递减子序列长度,然后判断去k的数后长度是 ...

  8. 2017 ACM/ICPC Asia Regional Shenyang Online card card card

    题意:看后面也应该知道是什么意思了 解法: 我们设置l,r,符合条件就是l=起始点,r=当前点,不符合l=i+1 学习了一下FASTIO #include <iostream> #incl ...

  9. 2017 ACM/ICPC Asia Regional Shenyang Online transaction transaction transaction

    Problem Description Kelukin is a businessman. Every day, he travels around cities to do some busines ...

随机推荐

  1. 修改python ide的主题,颜色

    1.找到这个名叫config-highlight.cfg文件后接下来就需要编辑它了 2. 贴上: [Obsidian] definition-foreground = #678CB1 error-fo ...

  2. Proximal Algorithms

    1. Introduction Much like Newton's method is a standard tool for solving unconstrained smooth minimi ...

  3. Android系统root破解原理分析

    http://dengzhangtao.iteye.com/blog/1543494 root破解过程的终极目标是替换掉系统中的su程序.但是要想替换掉系统中su程序本身就是需要root权限的,怎样在 ...

  4. 判断PC机大小端

    判断PC机大小端 #include<stdio.h> #include<stdlib.h> int main() { short a = 0x0102; char *p = ( ...

  5. java.lang.NoClassDefFoundError Could not initialize class 异常的处理

    class,forname的配置文件出问题核对url数据库中的名字和bean中名字不同没有把jar包变成build path

  6. python cov()

    在PCA中涉及到了方差var和协方差cov,下面详细了解这两个函数的用法.numpy中var和cov函数求法和MATLAB中var和cov函数求法类似. 首先均值,样本方差,样本协方差公式分别为 其中 ...

  7. AE IRasterCursor 获取栅格图层像素值

    在编写使用栅格图层的代码时,常常要获取栅格图层的像素值(PixelValue).如果想获取某一点的像素值,可以使用IRaster2中的getPixelValue方法.但如果想要获得的是图层中的某一块甚 ...

  8. idea 优化

    http://www.iyunv.com/thread-348537-1-1.html

  9. hdu 4956

    http://acm.hdu.edu.cn/showproblem.php?pid=4956 首先给出一个范围 [l, r],问能否从中找到一个数证明 Hanamichi's solution 的解法 ...

  10. hdu 5003 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5003 记得排序后输出 #include <cstdio> #include <cstring& ...