容斥原理

解法一:

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


先把$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. Win7 64X 安装VisualSVNServer 2.6.0过程中出现Custom action InstallWMISchemaExcute failed: Cannot query proxy blanket: No such interface supported (0x80004002)

    Win7 64X 安装VisualSVNServer 2.6.0过程中出现错误:Custom action InstallWMISchemaExcute failed: Cannot query pr ...

  2. spring-boot-route(八)整合mybatis操作数据库

    MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以使用简单的 XML ...

  3. Java知识系统回顾整理01基础06数组02初始化数组

    一.分配空间与赋值分步进行 分配空间与赋值分步进行 public class HelloWorld { public static void main(String[] args) { int[] a ...

  4. (入门)matlab中创建和调用m文件

    大学学过的一款软件,说实话没好好学,老师直接讲到高深的做仿真之类的 综合网上的教程讲述基础的matlab创建遇到的问题: 参考: 1. https://blog.csdn.net/weixin_423 ...

  5. Linux系统编程—有名管道

    ▋****1. 管道的概念 管道,又名「无名管理」,或「匿名管道」,管道是一种非常基本,也是使用非常频繁的IPC方式. 1.1 管道本质 管道的本质也是一种文件,不过是伪文件,实际上是一块内核缓冲区, ...

  6. 网站搭建-云服务器ECS-镜像管理

    学习笔记: 快照,系统盘可创建镜像,数据盘不可以. 实例可以直接创建镜像,包括系统盘和数据盘 复制镜像: 新购服务器,选择镜像(又买). 共享镜像: 账号ID就是UID 云市场获取镜像; 1. 创建新 ...

  7. 多测师讲解接口测试 _postman(上)_高级讲师肖sir

    Postman 一.Postman介绍 Postman是一个网页调试工具,也可以调试css.html Postman的操作环境 环境:Postman Mac.Windows X32.Windows X ...

  8. MeteoInfoLab脚本示例:站点数据散点图

    这里演示从micaps第一类数据(地面全要素观测)中读取一个变量(用DimDataFile类的stationdata方法),然后maskout掉中国区域之外的数据,利用scatterm函数绘制散点图. ...

  9. centos初步配置

    设置PS1 编辑sudo vi /etc/profile,PS1的值用于控制主提示符格式,含义如下 参数 描述 /d 代表日期,格式为weekday month date,例如:"Mon A ...

  10. k8s-获取kuboardtoken

    master节点执行命令 echo $(kubectl -n kube-system get secret $(kubectl -n kube-system get secret | grep kub ...