2020 Multi-University Training Contest 1(待补

2020 Multi-University Training Contest 1

1004 Distinct Sub-palindromes

  • __思路:思维题 \(n<4\)时,\(ans=26^n\)\(n\ge4\)时,\(ans=26*25*24\) __
  • AC代码

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const ll mod = 998244353;

int t;
ll n;

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t -- ){
        cin >> n;
        if (n == 1)
            cout << 26 << "\n";
        else if (n == 2)
            cout << 26 * 25 + 26 * 1 << "\n";
        else if (n == 3)
            cout << 26 * 25 * 24 + 26 * 1 * 25 * 3 + 26 << "\n";
        else
            cout << 26 * 25 * 24 << "\n";
    }
    return 0;
}

1005 Fibonacci Sum

  • 思路:比赛时被疯狂卡常 卡到自闭(太菜了

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <assert.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

inline ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

inline ll pow_mod(int a, int b, int p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = 1ll * res * a % p;
        a = 1ll * a * a % p;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int mod = 1e9 + 9;
const int K = 2e5 + 10;
const int l = 691504013;
const int r = 308495997;
const int s = 276601605;

int t, k, ans, L_, R_;
int L[K], R[K], fac[K], inv[K];
ll n, c;

inline int C(int n, int m){
    return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}

inline void init(){
    fac[0] = 1, inv[0] = 1;
    for (int i = 1; i < K; i ++ ){
        fac[i] = 1ll * fac[i - 1] * i % mod;
        inv[i] = pow_mod(fac[i], mod - 2, mod);
    }
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    init();
    cin >> t;
    while (t -- ){
        ans = 0, L[0] = R[0] = 1;
        cin >> n >> c >> k;
        L_ = pow_mod(l, c % (mod - 1), mod), R_ = pow_mod(r, c % (mod - 1), mod);
        for (int i = 1; i <= k; i ++ ){
            L[i] = 1ll * L[i - 1] * L_ % mod;
            R[i] = 1ll * R[i - 1] * R_ % mod;
        }
        for (int r = 0; r <= k; r ++ ){
            int tmp = 1ll * L[k - r] * R[r] % mod;
            int res;
            if (tmp == 1)
                res = n % mod;
            else
                res = 1ll * tmp * (pow_mod(tmp, n % (mod - 1), mod) - 1) % mod * pow_mod(tmp - 1, mod - 2, mod) % mod;
            res = 1ll * res * C(k, r) % mod;
            if (r & 1)
                ans -= res;
            else
                ans += res;
            ans %= mod;
        }
        ans = (1ll * ans * pow_mod(s, k, mod)) % mod;
        ans = (ans % mod + mod) % mod;
        cout << ans << "\n";
    }
    return 0;
}

1009 Leading Robots

  • 思路:根据加速度与位移的公式\(x = p + \frac{1}{2}at^2\),建立\(x-t^2\)二维直角坐标系,直线去重后,\(ans=\)凸包大小

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

typedef pair<ll, ll> pll;
const int N = 5e4 + 10;

int t, n, tot, top, ans;
int st[N];
bool flag1[N], flag2[N];
pll a[N], b[N];

inline double operator *(pll p1, pll p2){
    return 1.0 * (p2.second - p1.second) / (p1.first - p2.first);
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    while (t -- ){
        tot = 0, top = 0, ans = 0;
        memset(flag1, false, sizeof(flag1));
        memset(flag2, false, sizeof(flag2));
        cin >> n;
        for (int i = 1; i <= n; i ++ ){
            cin >> a[i].second >> a[i].first;
            a[i].second *= 2;
        }
        sort(a + 1, a + n + 1);
        for (int i = 1, j = 1; j <= n;){
            while (j < n && a[j + 1] == a[i])
                j ++ ;
            b[ ++ tot ] = a[i];
            if (j != i)
                flag1[tot] = true;
            j ++ ;
            i = j;
        }
        for (int i = 1, j = 1; j <= tot;){
            while (j < tot && b[i].first == b[j + 1].first)
                j ++ ;
            i = j;
            while (top && b[st[top]].second <= b[i].second)
                top -- ;
            while (top > 1 && b[st[top]] * b[st[top - 1]] * b[i].first + b[i].second >= b[st[top]] * b[st[top - 1]] * b[st[top]].first 
            + b[st[top]].second)
                top -- ;
            st[ ++ top ] = i;
            j ++ ;
            i = j;
        }
        for (int i = 1; i <= top; i ++ )
            flag2[st[i]] = true;
        for (int i = 1; i <= tot; i ++ )
            if (!flag1[i] && flag2[i])
                ans ++ ;
        cout << ans << "\n";
    }
    return 0;
}

1011 Minimum Index

  • 思路:Lyndon分解 Duval算法

  • AC代码


#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll mult_mod(ll x, ll y, ll mod){
    return (x * y - (ll)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;
}

ll pow_mod(ll a, ll b, ll p){
    ll res = 1;
    while (b){
        if (b & 1)
            res = mult_mod(res, a, p);
        a = mult_mod(a, a, p);
        b >>= 1;
    }
    return res % p;
}

ll gcd(ll a, ll b){
    return b ? gcd(b, a % b) : a;
}

const int N = 1e6 + 10;
const int mod = 1e9 + 7;

int t, len, ans;
int res[N];
char s[N];

int main(){
#ifndef ONLINE_JUDGE
    freopen("my_in.txt", "r", stdin);
#endif
    scanf("%d", &t);
    while (t -- ){
        ans = 0;
        res[1] = 1;
        scanf("%s", s + 1);
        len = strlen(s + 1);
        int i = 1;
        while (i <= len){
            int j = i + 1, k = i;
            while (j <= len && s[k] <= s[j]){
                if (s[k] < s[j]){
                    res[j] = i;
                    k = i;
                }
                else{
                    res[j] = res[k] + j - k;
                    k ++ ;
                }
                j ++ ;
            }
            res[j] = j;
            while (i <= k)
                i += j - k;
        }
        for (int i = len; i >= 1; i -- )
            ans = (1ll * ans * 1112 % mod + res[i]) % mod;
        cout << ans << "\n";
    }
    return 0;
}
posted @ 2020-07-25 22:16  Misuchii  阅读(193)  评论(0编辑  收藏  举报