ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

codeforces round 589

2020-03-07 18:57:45  阅读:255  来源: 互联网

标签:格子 ll codeforces 589 xx ans 质因数 round mod


题意

给定一个 h×wh×w 的矩形,以及 hh 个 rr 和 ww 个 cc。

riri 表示第 ii 行左边界从左往右连续的黑色格子的是 riri 个。

cici 表示第 ii 列上边界从上往下连续的黑色格子的是 cici 个。

给出 h,w,r[],c[]h,w,r[],c[],求可以构造出多少种矩形满足条件。

思路

模拟

对每行每列模拟,填充黑色格子和白色格子(黑色格子旁边一个格子一定是白色),如果行列有冲突就输出零,否则找出所有的没填充的格子的个数 cntcnt,答案为 2cntmod109+72cntmod109+7。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll maxn = 1e3 + 10;

ll c[maxn], r[maxn];
ll g[maxn][maxn];

ll qmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1) res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h, w;
    cin >> h >> w;
    for(ll i = 1; i <= h; ++i) {
        cin >> r[i];
        for(ll j = 1; j <= r[i]; ++j) {
            g[i][j] = 1;
        }
        g[i][r[i] + 1] = 2;
    }
    ll f = 1;
    for(ll i = 1; i <= w; ++i) {
        cin >> c[i];
        for(ll j = 1; j <= c[i]; ++j) {
            if(g[j][i] == 2) {
                f = 0;
            }
            g[j][i] = 1;
        }
        if(g[c[i] + 1][i] == 1) {
            f = 0;
        }
        g[c[i] + 1][i] = 2;
    }
    if(f == 0) {
        cout << 0 << endl;
    } else {
        ll ans = 0;
        for(ll i = 1; i <= h; ++i) {
            for(ll j = 1; j <= w; ++j) {
                if(!g[i][j]) {
                    ++ans;
                }
            }
        }
        cout << qmod(2, ans, mod) << endl;
    }
    return 0;
}

  C

题意

g(x,p)g(x,p) 定义为最大的 pkpk 满足 pkpk 整除 xx。

f(x,y)f(x,y) 定义为所有 g(y,p)g(y,p) 的乘积,其中 pp 是 xx 的质因数。

给定 xx 和 nn,求 ∏ni=1f(x,i)mod (109+7)∏i=1nf(x,i)mod (109+7)。

思路

理解了 g(x,p)g(x,p) 的含义就容易做了。

g(x,p)g(x,p) 其实为 xx 分解质因数后 pp 出现的次数。

先求出 xx 的所有质因数。然后对于每个质因数,求出 11 到 nn 中这个质因数出现的次数。也就是求 n!n! 的这个质因数的个数。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

vector<ll> divide(ll x) {
    vector<ll> ans;
    for(int i = 2; i <= x / i; ++i) {
        if (x % i == 0) {
            ans.push_back(i);
            while (x % i == 0) x /= i;
        }
    }
    if (x > 1) ans.push_back(x);
    return ans;
}

ll qmod(ll a, ll b, ll m) {
    if(!b) return 1 % m;
    ll ans = 1;
    while(b) {
        if(b & 1) ans = (ans * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x, n;
    cin >> x >> n;
    vector<ll> p = divide(x);
    ll ans = 1;
    for(int i = 0; i < p.size(); ++i) {
        ll tmp = n;
        while(tmp >= p[i]) {
            ans = ans * qmod(p[i], tmp / p[i], mod) % mod;
            tmp /= p[i];
        }
    }
    cout << ans % mod << endl;
    return 0;
}

  

标签:格子,ll,codeforces,589,xx,ans,质因数,round,mod
来源: https://www.cnblogs.com/hgangang/p/12436171.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有