• 比赛-Round 2 (11 Jul)


    这是 hzwer 巨佬的一场训练赛。

    1. 榴莲罐头

    单调队列或者纯贪心都是 O(n) ,后者空间是 O(1) 更好……

     1 #include <cstdio>
     2 #include <deque>
     3 
     4 using namespace std;
     5 
     6 typedef long long LL;
     7 
     8 const LL MOD = 100000007LL;
     9 const int _N = 1200000;
    10 
    11 deque<LL> Q;
    12 
    13 LL W[_N];
    14 
    15 void getnum(LL &num)
    16 {
    17     char tt;
    18     while ((tt = getchar()) < '0' || tt > '9');
    19     num = tt-'0';
    20     while ((tt = getchar()) >= '0' && tt <= '9')
    21         num = num*10+tt-'0';
    22     return;
    23 }
    24 
    25 int main()
    26 {
    27     LL N, K, i, ans;
    28     getnum(N), getnum(K);
    29     ans = 0;
    30     for (i = 1; i <= N; ++i) {
    31         LL need;
    32         getnum(W[i]), getnum(need);
    33         while (!Q.empty() && W[Q.back()] >= W[i])
    34             Q.pop_back();
    35         while (!Q.empty() && W[Q.front()]+(i-Q.front())*K >= W[i])
    36             Q.pop_front();
    37         Q.push_back(i);
    38         ans = (ans+need*((W[Q.front()]+(i-Q.front())*K%MOD)%MOD)%MOD)%MOD;
    39     }
    40     printf("%lld
    ", ans);//m
    41     return 0;
    42 }
    View Code

    2. 榴莲迷宫

    打表找规律。a = min(n, m), b = max(n, m), ans = C(n+m+1, a) + b 。

     1 #include <cstdio> 
     2 #include <algorithm>
     3 
     4 using namespace std;
     5 
     6 typedef long long LL;
     7 
     8 const LL MOD = 1000000007LL;
     9 
    10 LL Mont(LL t0, LL t1)
    11 {
    12     LL t = 1;
    13     t0 %= MOD;
    14     while (t1) {
    15         if (t1 & 1) t = t*t0%MOD;
    16         t1 >>= 1, t0 = t0*t0%MOD;
    17     }
    18     return t;
    19 }
    20 
    21 LL C(LL dn, LL up)
    22 {
    23     if (dn-up < up) up = dn-up;
    24     if (up < 0) return 0;
    25     if (up == 0) return 1;
    26     LL tmp1 = 1, tmp2 = 1;
    27     for (LL i = 1; i <= up; ++i) {
    28         tmp1 = tmp1*(dn-i+1)%MOD;
    29         tmp2 = tmp2*i%MOD;
    30     }
    31     return tmp1*Mont(tmp2, MOD-2)%MOD;
    32 }
    33 
    34 LL Lucas(LL dn, LL up)
    35 {
    36     if (dn-up < up) up = dn-up;
    37     if (up < 0) return 0;
    38     if (up == 0) return 1;
    39     return Lucas(dn/MOD, up/MOD)*C(dn%MOD, up%MOD)%MOD;
    40 }
    41 
    42 int main()
    43 {
    44     LL a, b;
    45     scanf("%lld%lld", &a, &b);
    46     printf("%lld
    ", (max(a, b)%MOD+Lucas(a+b+1, min(a, b)))%MOD);
    47     return 0;
    48 }
    View Code

    3. 榴莲……(忘了

    HNOI2015 弹飞绵羊,被强制禁止使用 LCT (其实也不会写)。 

    写在另一篇题解里 https://www.cnblogs.com/ghcred/p/9297934.html

  • 相关阅读:
    poj 2325 Persistent Numbers (贪心+高精度)
    迷宫 (BFS)
    poj1087 A Plug for UNIX & poj1459 Power Network (最大流)
    hdu 3549 Flow Problem (最大流)
    CodeForces Round #179 (295A)
    poj 1328 Radar Installation
    HTML 网页游戏 2048
    图论加边算法--链式向前星
    c语言 字符版 简易2048
    POJ 2115 C Looooops(扩展欧几里得)
  • 原文地址:https://www.cnblogs.com/ghcred/p/9297975.html
Copyright © 2020-2023  润新知