zoukankan      html  css  js  c++  java
  • bzoj 4002: [JLOI2015]有意义的字符串

      这个题。。。

      

     1 #include <bits/stdc++.h>
     2 #define rep(i, a, b) for (int i = a; i <= b; i++)
     3 #define drep(i, a, b) for (int i = a; i >= b; i--)
     4 #define REP(i, a, b) for (int i = a; i < b; i++)
     5 #define mp make_pair
     6 #define pb push_back
     7 #define clr(x) memset(x, 0, sizeof(x))
     8 #define xx first #define yy second
     9 using namespace std;
    10 typedef pair<int, int> pii;
    11 typedef unsigned long long ll;
    12 const int inf = 0x3f3f3f3f;
    13 const ll INF = 0x3f3f3f3f3f3f3f3fll;
    14 //************************************************
    15  
    16 const ll mod = 7528443412579576937LL;
    17 ll mul(ll base, ll num) {
    18     ll ret(0);
    19     while (num) {
    20         if (num & 1) ret = (ret + base) % mod;
    21         base = (base + base) % mod;
    22         num >>= 1;
    23     }
    24     return ret;
    25 }
    26 struct matrix {
    27     ll s[3][3]; matrix () { clr(s); }
    28     matrix operator * (const matrix &B) const {
    29         matrix A = *this, C;
    30         rep(i, 1, 2) rep(j, 1, 2) rep(k, 1, 2)
    31             C.s[i][j] = (C.s[i][j] + mul(A.s[i][k], B.s[k][j]) % mod) % mod;
    32         return C;
    33     }
    34 } ori;
    35  
    36 matrix POW(matrix base, ll num) {
    37     matrix ret = ori;
    38     while (num) {
    39         if (num & 1) ret = ret * base;
    40         base = base * base;
    41         num >>= 1;
    42     }
    43     return ret;
    44 }
    45  
    46 int main() {
    47     ll b, d, n; scanf("%llu%llu%llu", &b, &d, &n);
    48     ll a = b, c = (d - b * b) >> 2;
    49     ori.s[1][1] = ori.s[2][2] = 1;
    50     matrix base; base.s[1][1] = a, base.s[2][1] = c, base.s[1][2] = 1;
    51     matrix ans;
    52     ans.s[1][2] = 2, ans.s[1][1] = b;
    53     ans = ans * POW(base, n);
    54     if (d != b * b && n % 2 == 0) ans.s[1][2]--;
    55     printf("%llu
    ", ans.s[1][2]);
    56 }
    View Code
  • 相关阅读:
    数据结构 图的接口定义与实现分析(超详细注解)
    数据结构-优先队列 接口定义与实现分析
    什么是梯度?
    javascript当中火狐的firebug如何单步调试程序?
    给出一个javascript的Helloworld例子
    lvs dr 模型配置详解
    数据库连接池
    JDBC事务管理
    JDBC工具类:JDBCUtils
    详解JDBC对象
  • 原文地址:https://www.cnblogs.com/y7070/p/5183768.html
Copyright © 2011-2022 走看看