当前位置:网站首页>牛客2021暑期训练3-J-Counting Triangles
牛客2021暑期训练3-J-Counting Triangles
2022-07-15 15:11:00 【yl-9】
牛客2021暑期训练3-J-Counting Triangles
题意
给一个 n(n<=8000) 个顶点的图,每两个顶点边颜色为黑或白,求三个顶点组成的三角形边颜色相同的个数
题解
每个三⻆形要么同⾊,要么有两边同⾊另⼀边异⾊。对于后者,三⻆形有恰有两个异⾊⻆,⽽前者没有异⾊⻆。
因此异⾊⻆数/2 即为不符合条件的三⻆个数。⽤总数减去即可。复杂度 n^2
代码
#include<bits/stdc++.h>
#define LL 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;
using namespace std;
const int N=8009;
LL ans;
bool edge[8005][8005];
int v[N][2];
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();
v[i][edge[i][j]]++;
v[j][edge[i][j]]++;
}
for(int i=0;i<n;i++)
ans+=(LL)v[i][0]*(LL)v[i][1];
cout<<(LL)n*(LL)(n-1)*(LL)(n-2)/6-ans/2<<endl;
return 0;
}
边栏推荐
- 技术峰会|58同城刘元受邀参加QECON 2022全球软件质量&效能大会
- 《遥远的救世主》遵守客观规律(三)——文化属性
- openstack登陆dashboard提示认证发生错误
- SN6多光谱和SAR数据融合
- 2022年宁德市职业院校教师实践教学能力提升培训——网络搭建与管理
- What are the hardware of the cashier system?
- (PC+WAP)织梦模板防水建材类网站
- 抢先体验! 在浏览器里写 Flutter 是一种什么体验?
- The distant savior obeys the objective law (III) -- cultural attribute
- X-Shell远程连接虚拟机
猜你喜欢

Generate XML file of VOC dataset

Sword finger offer15 number bit operation of 1 in binary

Start of u-boot S analysis (I)
![[SQL injection] Stack Injection](/img/aa/6ad848479d492170fdd5d7613cbe64.png)
[SQL injection] Stack Injection

40+倍提升,详解 JuiceFS 元数据备份恢复性能优化之路
![[detailed tutorial] a thorough article on mongodb aggregation query](/img/31/e0b7267edd4026ddb73773c9e1bbd0.png)
[detailed tutorial] a thorough article on mongodb aggregation query

元宇宙带火的VR市场,字节也才摸到一点边

An article uncovers the mystery of Haidilao's spin off and listing. How much investment value is it?

Start of u-boot S analysis (II)

抢先体验! 在浏览器里写 Flutter 是一种什么体验?
随机推荐
u-boot之顶层Makefile分析(三)
抢先体验! 在浏览器里写 Flutter 是一种什么体验?
Sword finger offer15 number bit operation of 1 in binary
Start of u-boot S analysis (II)
A new UI testing method: visual perception test
简化IT供应商采用流程的六种方式
生成VOC数据集的xml文件
“认养一头牛”IPO的三只拦路虎
剑指Offer16-数值的整数次方-位运算
C#接口知识大全收藏建议收藏
Experience first! What kind of experience is it to write fluent in the browser?
LeNet
【答疑解惑】 裁员浪潮中,N+1 到底指什么?
ASTM e595-15 (2021) outgassing latest standard for degassing test
LeetCode_ Dynamic programming_ Medium_ 718. Longest repeating subarray
LeetCode_滑动窗口_二分搜索_中等_713.乘积小于 K 的子数组
Top level makefile analysis of u-boot (2) config Generation of MK file
EN 1090-1 structural members for steel and aluminum construction - CE certification
Three obstacles to the IPO of "adopt a cow"
sqli-labs less-1(报错注入之updatexml)