链接:https://ac.nowcoder.com/acm/contest/887/H
来源:牛客网

题目描述

Given three integers A, B, C. Count the number of pairs <x ,y> (with 1≤x≤Aand1≤y≤B)
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.
示例1

输入

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的更多相关文章

  1. 2019牛客多校第六场H Pair(数位DP 多个数相关)题解

    题意: 传送门 给你\(A,B,C\),要求你给出有多少对\((x, y)\)满足\(x\in [1,A],y\in [1,B]\),且满足以下任意一个条件:\(x \& y > C\) ...

  2. 2019牛客多校第七场H Pair 数位DP

    题意:给你一个3个数A, B, C问有多少对pair(i, j),1 <= i <= A, 1 <= j <= B, i AND j > C或 i XOR j < ...

  3. 牛客多校第七场H Pair 数位dp理解

    Pair 题意 给出A B C,问x取值[1,A]和y取值[1,B]存在多少组pair<x,y>满足以下最小一种条件,\(x \& y >c\),\(x\) xor \(y& ...

  4. 牛客多校第六场 C Generation I 组合数学 阶乘逆元模板

    链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets whi ...

  5. 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)

    链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...

  6. 同构图+思维构造——牛客多校第六场E

    考的其实是同构图的性质: 1.同构图的顶点数,边数相等 2.同构图通过点的映射后邻接矩阵相同 这篇博客讲的很好https://www.jianshu.com/p/c33b5d1b4cd9 本题还需要一 ...

  7. 2018牛客多校第六场 G.Pikachu

    题意: 给出一棵n个点的树,每条边有边权.对这个树加边变成一个完全图.新加的边的权值为边上两点在树上的距离.求完全图上任意两点的最大流之和. 题解: 一共有C(n,2)个点对.假设当前求s到t之间的最 ...

  8. 2018牛客多校第六场 I.Team Rocket

    题意: 给出n个区间和m个点(点按顺序给出且强制在线).每个区间只会被第一个他包含的点摧毁.问每个点能摧毁多少个区间以及每个区间是被哪个点摧毁的. 题解: 将n个区间按照左端点排序,然后用vector ...

  9. 2018牛客多校第五场 H.subseq

    题意: 给出a数组的排列.求出字典序第k小的b数组的排列,满足1<=bi<=n,bi<bi+1,a[b[i]]<a[b[i+1]],m>0. 题解: 用树状数组倒着求出以 ...

随机推荐

  1. The Preliminary Contest for ICPC Asia Nanjing 2019 D. Robots

    题意:给出一个DAG,一只机器人从1点出发,等概率地选择一条出边走或者停留在原点,机器人的第k次行动消耗能量是k(无论是走还是停留都算一次行动).问1到n的期望. 解法:因为行动消耗的能量跟行动次数有 ...

  2. 笔记70 Spring Boot快速入门(八)(重要)

    上传文件 一.方式一 1.上传页面 upLoadPage.html <!DOCTYPE html> <html lang="en"> <head> ...

  3. 对struct typedef *的认识

    typedef struct node { ……… }NODE,*PNODE; 应该等价于 typedef struct node NODE;//struct node = NODE,eg:struc ...

  4. 【leetcode】654. Maximum Binary Tree

    题目如下: Given an integer array with no duplicates. A maximum tree building on this array is defined as ...

  5. Mysql 列变行其中一种做法。

    需求是: 上班打卡记录   和  下班打卡记录  是分别是两条数据,现在是要合并为一条数据,并且封装成一个实体. 有可能是 只有上班记录,,或者是只有下班的记录.如何关联全查,一边为null或者另一边 ...

  6. linux shell的单行多行注释

    1.单行注释,使用符号# echo " echo "test" #echo "comment“ 2. 多行注释 (1)使用 :<<!  ! file ...

  7. Oracle with as语法

    with as优点 增加了sql的易读性,如果构造了多个子查询,结构会更清晰: 更重要的是:“一次分析,多次使用”,这也是为什么会提供性能的地方,达到了“少读”的目标 用法:给查询的语句起个别名 e. ...

  8. textAppearance的属性设置

    android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?a ...

  9. dedecms SESSION变量覆盖导致SQL注入漏洞修补方案

    dedecms的/plus/advancedsearch.php中,直接从$_SESSION[$sqlhash]获取值作为$query带入SQL查询,这个漏洞的利用前提是session.auto_st ...

  10. 从输入 URL 到页面展示,到底发生了什么

    从输入 URL 到页面展示,到底发生了什么 1.输入URL 当我们开始在浏览器中输入网址的时候,浏览器其实就已经在智能的匹配可能得 url 了,他会从历史记录,书签等地方,找到已经输入的字符串可能对应 ...