2021牛客暑期多校训练营3

126 篇文章 0 订阅
32 篇文章 0 订阅


B–Black and white

题目链接:


题解:

#include<bits/stdc++.h>

#define ll long long
using namespace std;
const int maxn = 5005;
struct node {
    int u,v;
    ll w;
    bool operator < (const node& r) const {return w<r.w;}
}e[maxn*maxn];
int fa[maxn<<1];
int find(int x)
{
    return fa[x] == x?x:fa[x] = find(fa[x]);
}
ll n,m,a,b,c,d,p;
int main()
{
    cin>>n>>m>>a>>b>>c>>d>>p;
    int cnt = 1;
    e[0].w = a;
    for(int i = 0; i <= n+m+2; i++) fa[i] = i;
    for(int i = 1; i <= n; i++)
        for(int j = n+1; j <= n+m; j++)
        {
            e[cnt].u = i,e[cnt].v = j;
            e[cnt].w = (e[cnt-1].w*e[cnt-1].w*b+e[cnt-1].w*c+d)%p;
            cnt++;
        }
    sort(e+1,e+1+cnt);
    ll ans = 0;
    for(int i=1;i<=cnt;i++){
        int x = find(e[i].u);
        int y = find(e[i].v);
        if(x != y)
        {
            ans+=e[i].w;
            fa[x] = y;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

E–Math

题目链接:


题解:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
const ll inf=1e18;
int t;
vector<ll> ans;
void init(){
    ans.push_back(1);
    for(ll i=2;i<=1000000;i++){
        __int128 x=i,y=i*i*i,k=i*i;
        while(y<=inf){
            ans.push_back(y);
            __int128 t=y;
            y=k*y-x;
            x=t;
        }
    }
    sort(ans.begin(),ans.end());
}
int main(){
    init();
    scanf("%d",&t);
    ll x;
    while(t--){
        scanf("%lld",&x);
        ll res=upper_bound(ans.begin(), ans.end(), x)-ans.begin();
        printf("%lld\n",res);
    }
}

J–Counting Triangles

题目链接:


题解:

#include <bits/stdc++.h>

using namespace std;
#define int long long
namespace GenHelper {
unsigned z1, z2, z3, z4, b, u;
unsigned get() {
    b = ((z1 << 6) ^ z1) >> 13;
    z1 = ((z1 & 4294967294U) << 18) ^ b;
    b = ((z2 << 2) ^ z2) >> 27;
    z2 = ((z2 & 4294967288U) << 2) ^ b;
    b = ((z3 << 13) ^ z3) >> 21;
    z3 = ((z3 & 4294967280U) << 7) ^ b;
    b = ((z4 << 3) ^ z4) >> 12;
    z4 = ((z4 & 4294967168U) << 13) ^ b;
    return (z1 ^ z2 ^ z3 ^ z4);
}
bool read() {
    while (!u) u = get();
    bool res = u & 1;
    u >>= 1;
    return res;
}
void srand(int x) {
    z1 = x;
    z2 = (~x) ^ 0x233333333U;
    z3 = x ^ 0x1234598766U;
    z4 = (~x) + 51;
    u = 0;
}
}

using namespace GenHelper;
bool edge[8005][8005];
int num[8005];

signed main() {
    int n, seed;
    cin >> n >> seed;
    srand(seed);
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++) edge[j][i] = edge[i][j] = read();
    int res = 0, a = 0, b = 0;
    for (int i = 0; i < n; i++) {
        int n1 = 0, n0 = 0;
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (edge[i][j])
                n1++;
            else if (!edge[i][j])
                n0++;
        }
        a += n0 * (n0 - 1) / 2 + n1 * (n1 - 1) / 2;
        b += n0 * n1;
    }
    
    res = (a - b / 2) / 3;
    cout << res << endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值