牛客多校第六场-H-Pair
链接:https://ac.nowcoder.com/acm/contest/887/H
来源:牛客网
题目描述
such that at least one of the following is true:
- (x and y) > C
- (x xor y) < C
("and", "xor" are bit operators)
输入描述:
The first line of the input gives the number of test cases,T(T≤100). T test cases follow. For each test case, the only line contains three integers A, B and C.
1≤A,B,C≤10^9
输出描述:
For each test case, the only line contains an integer that is the number of pairs satisfying the condition given in the problem statement.
输入
3
3 4 2
4 5 2
7 8 5
输出
5
7
31
数位dp求 x&y<=c && x^y>=c的个数然后用所有方案剪掉
具体见代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int T,A,B,C;
int a[],b[],c[];
ll f[][][][][];
void cal(int x,int v[])
{
for (int i=;i<=;i++) v[i]=(x>>i)&;
}
ll dfs(int pos,bool lima,bool limb,bool limand,bool limxor)
// 位 x<a y<b x&y<c x^y>c
{
if (pos==-) return ;
if (f[pos][lima][limb][limand][limxor]!=-) return f[pos][lima][limb][limand][limxor]; int aa=lima?a[pos]:; //lima=1说明之前一直相等当前位取要<=a,否则说明之前<a了当前位可以乱取
int bb=limb?b[pos]:;
int c1=limand?c[pos]:; //同理如果之前x&y一直等于c那么当前位要x&y<=c,否则就可以乱取
int c2=limxor?c[pos]:;
ll &ret=f[pos][lima][limb][limand][limxor];
ret=; for (int i=;i<=aa;i++)
for (int j=;j<=bb;j++)
{
if ((i&j)>c1) continue;
if ((i^j)<c2) continue;
ret+=dfs(pos-,lima&&i==aa,limb&&j==bb,limand&&(i&j)==c1,limxor&&(i^j)==c2);
}
return ret;
}
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&A,&B,&C);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(c,,sizeof(c));
memset(f,-,sizeof(f));
cal(A,a); cal(B,b); cal(C,c);
ll ans=dfs(,,,,);
ans-=max(,A-C+);
ans-=max(,B-C+); //减掉x,y为0的情况
printf("%lld\n",(ll)A*B-ans); }
return ;
}
牛客多校第六场-H-Pair的更多相关文章
- 2019牛客多校第六场H Pair(数位DP 多个数相关)题解
题意: 传送门 给你\(A,B,C\),要求你给出有多少对\((x, y)\)满足\(x\in [1,A],y\in [1,B]\),且满足以下任意一个条件:\(x \& y > C\) ...
- 2019牛客多校第七场H Pair 数位DP
题意:给你一个3个数A, B, C问有多少对pair(i, j),1 <= i <= A, 1 <= j <= B, i AND j > C或 i XOR j < ...
- 牛客多校第七场H Pair 数位dp理解
Pair 题意 给出A B C,问x取值[1,A]和y取值[1,B]存在多少组pair<x,y>满足以下最小一种条件,\(x \& y >c\),\(x\) xor \(y& ...
- 牛客多校第六场 C Generation I 组合数学 阶乘逆元模板
链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets whi ...
- 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)
链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...
- 同构图+思维构造——牛客多校第六场E
考的其实是同构图的性质: 1.同构图的顶点数,边数相等 2.同构图通过点的映射后邻接矩阵相同 这篇博客讲的很好https://www.jianshu.com/p/c33b5d1b4cd9 本题还需要一 ...
- 2018牛客多校第六场 G.Pikachu
题意: 给出一棵n个点的树,每条边有边权.对这个树加边变成一个完全图.新加的边的权值为边上两点在树上的距离.求完全图上任意两点的最大流之和. 题解: 一共有C(n,2)个点对.假设当前求s到t之间的最 ...
- 2018牛客多校第六场 I.Team Rocket
题意: 给出n个区间和m个点(点按顺序给出且强制在线).每个区间只会被第一个他包含的点摧毁.问每个点能摧毁多少个区间以及每个区间是被哪个点摧毁的. 题解: 将n个区间按照左端点排序,然后用vector ...
- 2018牛客多校第五场 H.subseq
题意: 给出a数组的排列.求出字典序第k小的b数组的排列,满足1<=bi<=n,bi<bi+1,a[b[i]]<a[b[i+1]],m>0. 题解: 用树状数组倒着求出以 ...
随机推荐
- hibernate 参数一览
实现包含了Hibernate与数据库的基本连接信息的配置方式有两种方式: 第一种是使用hibernate.properties文件作为配置文件. 第二种是使用hibernate.cfg.xml文件作为 ...
- GenXus学习笔记——Transaction的建立
我们上次聊到 如何正确无误的的创建一个项目KB 那么这次我们就该聊一点实际的东西了(敲黑板( ̄▽ ̄)) 上回书说道我们在创建完自己的KB后 该创建自己的数据库了 首先我们先创建创建一个表 但是创建之 ...
- 分析dwebsocket的源码过程
前言 dwebsocet 是python django的websocket库,github地址:https://github.com/duanhongyi/dwebsocket 本章是对dwebsoc ...
- VSCode中行数与代码之间用点点点代替
在settings.json中添加一行 "editor.renderWhitespace": "all"
- 工具类Collections、Arrays(传入的是数组)
Collections类: 1. Collections.sort(list) //对list集合进行排序前提是 list里面存储的对象已经实现了 comparable接口 2. Collecti ...
- Halo(二)
@Conditional 满足条件给容器注册Bean(在配置类 @Configuration 的类和方法上配置) 需要实现Condition接口, 实现matches方法 public class L ...
- 【原理】scan
SCAN 命令的保证(guarantees) 同一个元素可能会被返回多次. 处理重复元素的工作交由应用程序负责, 比如说, 可以考虑将迭代返回的元素仅仅用于可以安全地重复执行多次的操作上. 如果一个元 ...
- selenuim模块的使用 解析库
selenium: 是自动化测试工具,我们可以用它来进行爬虫. 可以驱动浏览器,执行自定义好的任务. 可以执行js代码 执行速度慢,效率低. 一般用于做登录的认证 基本选择器: find_elemen ...
- php time()函数 语法
php time()函数 语法 time()函数怎么用? php time()函数用来返回当前时间的unix时间戳.语法是time(),返回自从 Unix 纪元(格林威治时间 1970 年 1 月 1 ...
- Network基础(二):数制转换
一.数制转换 目标: 1)请将下列数字转换为十进制数: (110010011111)2 .(10110101110)2 2)请将下列十进制数转换为二进制: 156.2608.1043 方案: 使用按权 ...