2021牛客暑期多校3-J

时间:2021-07-25
本文章向大家介绍2021牛客暑期多校3-J,主要包括2021牛客暑期多校3-J使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

J

签到差点没签成功.......

如果一个三角形三条边不是同一种颜色,那么一定有一个顶点,与其相连的两条边颜色相反。

所以枚举每一个点,统计其黑白边个数,相乘即是以其为顶点之一的三条边不是同一种颜色的三角形的个数。

从总个数减去不满足的个数可以得到答案。

不要忘了去重。

复杂度 \(\Theta(n^2)\)

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define ull unsigned long long
#define cint const int&
#define Pi acos(-1)

const int mod = 1e9+7;
const int inf_int = 0x7fffffff;
const ll inf_ll = 0x7fffffffffffffff;
const double ept = 1e-9;

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];

ll sol(ll x) {
    return x*(x-1)*(x-2)/6;
}

int 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();
    ll ans = 0;
    for(int i=0; i<n; i++) {
        int s1 = 0, s2 = 0;
        for(int j=0; j<n; j++) if(i!=j){
            if(edge[i][j]) ++s1;
            else ++s2;
        }
        ans += s1*s2;
    }
    cout << sol(n) - ans/2 << endl;
 	return 0;
}

原文地址:https://www.cnblogs.com/ullio/p/15057223.html