头像

卡冈图亚




离线:12小时前


最近来访(10)
用户头像
呆呆小Y
用户头像
iiiiiiire
用户头像
yoakashi
用户头像
SherlockZ
用户头像
yuanheci
用户头像
猪头_少年
用户头像
yt2
用户头像
小陈今天早睡了没
用户头像
也_1


卡冈图亚
14小时前
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 110;

int n, a[N][N];

int gauss()
{
    int r, c;
    for(r = c = 1; c <= n; ++ c)
    {
        int t = r;
        for(int i = r; i <= n; ++ i)
            if(a[i][c])
            {
                t = i;
                break;
            }

        if(!a[t][c]) continue;

        for(int i = c; i <= n + 1; ++ i) swap(a[t][i], a[r][i]);

        for(int i = r + 1; i <= n; ++ i)
            if(a[i][c])
                for(int j = c; j <= n + 1; ++ j)
                    a[i][j] ^= a[r][j];

        ++ r;
    }

    if(r <= n)
    {
        for(int i = n; i >= r; -- i)
            if(a[i][n + 1]) return 2;
        return 1;
    }

    for(int i = n; i >= 1; -- i)
        for(int j = n; j > i; -- j)
            a[i][n + 1] ^= a[i][j] & a[j][n + 1];

    return 0;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;

    for(int i = 1; i <= n; ++ i)
        for(int j = 1; j <= n + 1; ++ j)
            cin >> a[i][j];

    int res = gauss();

    if(!res)
    {
        for(int i = 1; i <= n; ++ i) cout << a[i][n + 1] << endl;
    }
    else if(res == 1) cout << "Multiple sets of solutions" << endl;
    else cout << "No solution" << endl;

    return 0;
}


活动打卡代码 AcWing 894. 拆分-Nim游戏

卡冈图亚
15小时前
#include <iostream>
#include <algorithm>
#include <cstring>
#include <unordered_set>

using namespace std;

const int N = 110;

int n, x, a[N], res;
int f[N];

int sg(int x)
{
    if(f[x] != -1) return f[x];

    unordered_set<int> st;
    for(int i = 0; i < x; ++ i)
        for(int j = 0; j <= i; ++ j)
            st.insert(sg(i) ^ sg(j));

    for(int i = 0; ; ++ i)
        if(!st.count(i)) return f[x] = i;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    memset(f, -1, sizeof f);

    cin >> n;

    for(int i = 1; i <= n; ++ i) 
    {
        cin >> x;
        res ^= sg(x);
    }

    if(res) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


活动打卡代码 AcWing 892. 台阶-Nim游戏

卡冈图亚
15小时前
#include <iostream>
#include <algorithm>

using namespace std;

int n, x, res;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;
    for(int i = 1; i <= n; ++ i)
    {
        cin >> x;
        if(i % 2) res ^= x;
    }

    if(res) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


活动打卡代码 AcWing 893. 集合-Nim游戏

卡冈图亚
15小时前
#include <iostream>
#include <algorithm>
#include <cstring>
#include <unordered_set>

using namespace std;

const int N = 110, M = 1e4 + 10;

int n, k, x, s[N], res;
int f[M];

int sg(int p)
{
    if(f[p] != -1) return f[p];

    unordered_set<int> st;
    for(int i = 1; i <= k; ++ i)
        if(p - s[i] >= 0) st.insert(sg(p - s[i]));

    for(int i = 0; ; ++ i)
        if(!st.count(i)) return f[p] = i;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> k;
    for(int i = 1; i <= k; ++ i) cin >> s[i];

    memset(f, -1, sizeof f);

    cin >> n;
    while(n --)
    {
        cin >> x;
        res ^= sg(x);
    }

    if(res) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


活动打卡代码 AcWing 891. Nim游戏

卡冈图亚
15小时前
#include <iostream>
#include <algorithm>

using namespace std;

int n, x, res;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;
    while(n --)
    {
        cin >> x;
        res ^= x;
    }

    if(!res) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}



活动打卡代码 AcWing 890. 能被整除的数

卡冈图亚
16小时前
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int N = 20;

ll n, m, x, cnt, p[N], ans;

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> m;
    for(int i = 1; i <= m; ++ i) cin >> p[i];

    for(int i = 1; i < 1 << m; ++ i)
    {
        x = 1;
        cnt = 0;
        for(int j = 0; j < m; ++ j)
            if(i >> j & 1)
            {
                ++ cnt;
                if(x * p[j + 1] > n)
                {
                    x = -1;
                    break;
                }
                x *= p[j + 1];
            }
        if(x != -1)
        {
            if(cnt % 2) ans += n / x;
            else ans -= n / x;
        }
    }

    cout << ans << endl;

    return 0;
}



#include <iostream>
#include <algorithm>

using namespace std;

const int N = 2e5 + 10;

int u, v, w;
int n, m, fa[N], ans;
struct node
{
    int a, b, c;
    bool operator < (const node&_) const
    {
        return c < _.c;
    }
}edge[N];

int find(int x)
{
    return x == fa[x] ? x : fa[x] = find(fa[x]);
}

bool kruskal()
{
    int cnt = 0;
    for(int i = 1; i <= m; ++ i)
    {
        u = find(edge[i].a);
        v = find(edge[i].b);
        w = edge[i].c;
        if(u != v)
        {
            fa[u] = v;
            ans += w;
            ++ cnt;
            if(cnt == n - 1) return true;
        }
    }
    return cnt == n - 1;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> m;

    for(int i = 1; i <= n; ++ i) fa[i] = i;

    for(int i = 1; i <= m; ++ i) cin >> edge[i].a >> edge[i].b >> edge[i].c;

    sort(edge + 1, edge + m + 1);

    if(!kruskal()) cout << "impossible" << endl;
    else cout << ans << endl;

    return 0;
}



#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 510, INF = 0x3f3f3f3f;

int u, v, w;
int n, m, ans;
int g[N][N], dist[N];
bool st[N];

bool prim()
{
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;

    for(int i = 1; i <= n; ++ i)
    {
        int t = -1;
        for(int j = 1; j <= n; ++ j)
            if(!st[j] && (t == -1 || dist[j] < dist[t])) t = j;

        if(t == -1 || dist[t] >= INF) return false;
        st[t] = true;
        ans += dist[t];

        for(int j = 1; j <= n; ++ j)
            if(!st[j]) dist[j] = min(dist[j], g[t][j]);
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> m;

    for(int i = 1; i <= n; ++ i)
        for(int j = 1; j <= n; ++ j)
            if(i == j) g[i][j] = 0;
            else g[i][j] = INF;

    while(m --)
    {
        cin >> u >> v >> w;
        g[u][v] = g[v][u] = min(g[u][v], w);
    }

    if(!prim()) cout << "impossible" << endl;
    else cout << ans << endl;

    return 0;
}



#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

ll n, ans;

ll qmi(ll a, ll k)
{
    ll res = 1;
    while(k)
    {
        if(k & 1) res = res * a % mod;
        a = a * a % mod;
        k >>= 1;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;

    ll x = 1, y = 1;
    for(int i = 1, j = 2 * n; i <= n; ++ i, -- j)
    {
        x = x * i % mod;
        y = y * j % mod;
    }

    ans = y * qmi(x, mod - 2) % mod;

    ans = ans * qmi(n + 1, mod - 2) % mod;

    cout << ans << endl;

    return 0;
}


活动打卡代码 AcWing 888. 求组合数 IV

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

const int N = 5010;

int a, b, num[N];
int primes[N], cnt;
bool st[N];

void get_primes(int n)
{
    for(int i = 2; i <= n; ++ i)
    {
        if(!st[i]) primes[cnt ++] = i;
        for(int j = 0; primes[j] * i <= n; ++ j)
        {
            st[primes[j] * i] = true;
            if(i % primes[j] == 0) break;
        }
    }
}

int get(int x, int y)
{
    int res = 0;
    while(x)
    {
        res += x / y;
        x /= y;
    }
    return res;
}

vector<int> mul(vector<int>&c, int d)
{
    vector<int> res;
    int t = 0;
    for(int i = 0; i < c.size() || t; ++ i)
    {
        if(i < c.size()) t += c[i] * d;
        res.push_back(t % 10);
        t /= 10;
    }

    return res;
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> a >> b;

    get_primes(a);

    for(int i = 0; i < cnt; ++ i)
    {
        int p = primes[i];
        num[i] = get(a, p) - get(b, p) - get(a - b, p);
    }

    vector<int> c;
    c.push_back(1);

    for(int i = 0; i < cnt; ++ i)
        while(num[i] --) c = mul(c, primes[i]);

    for(int i = c.size() - 1; i >= 0; -- i) cout << c[i];
    cout << endl;

    return 0;
}