容斥原理

解法一:

其他容斥原理的题也可以用这种思想


先把$A$,$B$,$C$分解因数

一种很暴力的想法是,将这些因数分成若干个集合(画出韦恩图),然后对有序数组的三个数分别枚举其位于哪一个集合中

然后可以将这些因数划分成$7$个集合

$1$  $1$  $1$

$C$  $B$ $A$

此处为二进制下的数字

$001$:只为$A$的因数的集合

$010$:只为$B$的因数的集合

$100$:只为$C$的因数的集合

$011$:只为$A$,$B$的共同因数的集合

$101$:只为$A$,$C$的共同因数的集合

$110$:只为$B$,$C$的共同因数的集合

$111$:$A$,$B$,$C$的共同因数的集合

如图

对于这几个集合所含数的个数可以在$O(\sqrt{x})$的时间内求出

还要注意因为题中长方体可以任意翻转,在枚举集合的时候要注意

枚举过$(i,j,k)$就不能再枚举$(i,k,j)$或$(j,k,i)$等其他情况

然后考虑如何统计

对于一个集合中有n个数来说,取出r可重复的元素的方案数为

$C_{n+r-1}^{r}$

此处同理

即可解决

 1 #include <bits/stdc++.h>
2 using namespace std;
3 const int N=1e5+100;
4 int t,a,b,c,fac[8],ans,cnt[8];
5 int ab,bc,ac,abc,sum[N];
6 int cal(int x)
7 {
8 int cnt=0;
9 for (int i=1;i*i<=x;i++)
10 {
11 if (x%i==0)
12 {
13 cnt++;
14 if (x/i!=i) cnt++;
15 }
16 }
17 return cnt;
18 }
19 int cal_fac(int x)
20 {
21 return sum[x];
22 }
23 int gcd(int a,int b)
24 {
25 if (b==0) return a;
26 return gcd(b,a%b);
27 }
28 bool check(int a,int b,int c)
29 {
30 //这个函数是判断a,b,c三个数任意排列是否分别为为A,B,C的因数
31 if ((a&1) && (b&2) && (c&4)) return true;
32 if ((a&1) && (c&2) && (b&4)) return true;
33 if ((b&1) && (a&2) && (c&4)) return true;
34 if ((b&1) && (c&2) && (a&4)) return true;
35 if ((c&1) && (b&2) && (a&4)) return true;
36 if ((c&1) && (a&2) && (b&4)) return true;
37 return false;
38 }
39 int C(int n,int m)
40 {
41 int cnt=1;
42 for (int i=n;i>n-m;i--)
43 cnt=cnt*i/(n-i+1);
44 return cnt;
45 }
46 int main()
47 {
48 for (int i=1;i<=1e5+10;i++)
49 sum[i]=cal(i);//要先预处理出范围内的因数个数
50 scanf("%d",&t);
51 while (t--)
52 {
53 scanf("%d%d%d",&a,&b,&c);;
54 memset(fac,0,sizeof(fac));
55 ans=0;
56 ab=gcd(a,b);ac=gcd(a,c);bc=gcd(b,c);
57 abc=gcd(a,gcd(b,c));
58 a=cal_fac(a);b=cal_fac(b);c=cal_fac(c);
59 ab=cal_fac(ab);ac=cal_fac(ac);bc=cal_fac(bc);
60 abc=cal_fac(abc);
61 fac[1]=a-ab-ac+abc;
62 fac[2]=b-ab-bc+abc;
63 fac[3]=ab-abc;
64 fac[4]=c-ac-bc+abc;
65 fac[5]=ac-abc;
66 fac[6]=bc-abc;
67 fac[7]=abc;//同上的定义
68 for (int i=1;i<=7;i++)
69 {
70 for (int j=i;j<=7;j++)
71 {
72 for (int k=j;k<=7;k++)
73 {
74 if (check(i,j,k))
75 {
76 int sum=1;
77 memset(cnt,0,sizeof(cnt));
78 cnt[i]++;cnt[j]++;cnt[k]++;//统计每一个集合中要选取多少个数
79 for (int p=1;p<=7;p++)
80 sum=sum*C(fac[p]+cnt[p]-1,cnt[p]);//统计答案
81 ans+=sum;
82 }
83 }
84 }
85 }
86 printf("%d\n",ans);
87 }
88 }

解法二:

直接容斥原理硬推公式,待填

CF1008D Pave the Parallelepiped的更多相关文章

  1. codeforces 1007B Pave the Parallelepiped

    codeforces 1007B Pave the Parallelepiped 题意 题解 代码 #include<bits/stdc++.h> using namespace std; ...

  2. CF1007B Pave the Parallelepiped 容斥原理

    Pave the Parallelepiped time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. [CF1007B]Pave the Parallelepiped[组合计数+状态压缩]

    题意 \(t\) 组询问,给你 \(A, B, C\) ,问有多少组三元组 \((a, b, c)\) 满足他们任意排列后有: \(a|A,\ b|B,\ c|C\) . \(A,B,C,t\leq ...

  4. Pave the Parallelepiped CodeForces - 1007B (计数)

    大意: 给定A,B,C, 求有多少个三元组$(a,b,c)$, 满足$a \le b \le c$, 且以若干个$(a,b,c)$为三边的长方体能填满边长(A,B,C)的长方体. 暴力枚举出$A,B, ...

  5. Codeforces Round #138 (Div. 2) A. Parallelepiped

    A. Parallelepiped time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. UVA 503 Parallelepiped walk

    https://vjudge.net/problem/UVA-503 题目 给出一个长方体和长方体上两点的坐标,求两点的沿着长方体表面走的最小距离 题解 沿着表面走就是在展开图上面走,如果分类讨论就需 ...

  7. 认识 EXT2 文件系统

    认识ext文件系统 硬盘组成与分割 文件系统特性 Linux 的 EXT2 文件系统(inode) 与目录树的关系 EXT2/EXT3 文件的存取与日志式文件系统的功能 Linux 文件系统的运行 挂 ...

  8. 微软版的SqlHelper.cs类

    一,微软SQLHelper.cs类 中文版: using System; using System.Data; using System.Xml; using System.Data.SqlClien ...

  9. OracleHelper类

    using System; using System.Collections; using System.Collections.Generic; using System.Data; using S ...

随机推荐

  1. K8S环境的Jenkin性能问题处理

    环境信息 在K8S环境通过helm部署了Jenkins(namespace为helm-jenkins),用于日常Java项目构建: kubernetes:1.15 jenkins:2.190.2 he ...

  2. GAN训练技巧汇总

    GAN自推出以来就以训练困难著称,因为它的训练过程并不是寻找损失函数的最小值,而是寻找生成器和判别器之间的纳什均衡.前者可以直接通过梯度下降来完成,而后者除此之外,还需要其它的训练技巧. 下面对历年关 ...

  3. Python实现的数据结构与算法之快速排序详解

    一.概述 快速排序(quick sort)是一种分治排序算法.该算法首先 选取 一个划分元素(partition element,有时又称为pivot):接着重排列表将其 划分 为三个部分:left( ...

  4. mac操作liunx

    mkdir demo //创建一个文件夹 touch index.html // 创建一个html文件 rm rouch index.html //删除找个index.html文件 rmdir dem ...

  5. shell-逻辑操作符讲解与文件条件测试多范例多生产案例

    1. 逻辑操作符 在书写测试表达式时,可以使用表1.1中的逻辑操作符实现复杂的条件测试  表1.1逻辑连接符 提示: ! 中文意思是反:与一个逻辑值相反的逻辑值 -a 中文意思是与(and & ...

  6. ansible-playbook定义变量与使用

    1. ansible-playbook变量定义与使用 命令行 在Inventory中定义 在Playbook中定义 在Role中定义 注册变量(register) 系统信息变量(facts) 2. 在 ...

  7. JVM性能调优(4) —— 性能调优工具

    前序文章: JVM性能调优(1) -- JVM内存模型和类加载运行机制 JVM性能调优(2) -- 垃圾回收器和回收策略 JVM性能调优(3) -- 内存分配和垃圾回收调优 一.JDK工具 先来看看有 ...

  8. lua 1.1 源码阅读总结

    GC 1. 怎么回收的lua 中所有已经分配的数据都会用一些指令的数据结构来记录,当需要回收时,先遍历当前栈内所有 object,把 ref 标志位打上 1,遍历符号表(这部分不能回收),反符号表中的 ...

  9. select函数详解(转)

    Select函数在Socket编程中还是比较重要的,可是对于初学Socket的人来说都不太爱用Select写程序,他们只是习惯写诸如connect. accept.recv或recvfrom这样的阻塞 ...

  10. Shell Scripting 笔记

    Shell Scripting Tutorial Variables in the Bourne shell do not have to be declared, as they do in lan ...