日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

牛客多校第六场-H-Pair

發布時間:2025/10/17 编程问答 10 豆豆
生活随笔 收集整理的這篇文章主要介紹了 牛客多校第六场-H-Pair 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

鏈接:https://ac.nowcoder.com/acm/contest/887/H
來源:牛客網

題目描述

Given three integers A, B, C. Count the number of pairs <x?,y> (with 1≤x≤Aand1yB)
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(T100). 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[35],b[35],c[35]; ll f[35][2][2][2][2]; void cal(int x,int v[]) {for (int i=0;i<=30;i++) v[i]=(x>>i)&1; } ll dfs(int pos,bool lima,bool limb,bool limand,bool limxor) // 位 x<a y<b x&y<c x^y>c {if (pos==-1) return 1;if (f[pos][lima][limb][limand][limxor]!=-1) return f[pos][lima][limb][limand][limxor];int aa=lima?a[pos]:1; //lima=1說明之前一直相等當前位取要<=a,否則說明之前<a了當前位可以亂取int bb=limb?b[pos]:1;int c1=limand?c[pos]:1; //同理如果之前x&y一直等于c那么當前位要x&y<=c,否則就可以亂取int c2=limxor?c[pos]:0;ll &ret=f[pos][lima][limb][limand][limxor];ret=0;for (int i=0;i<=aa;i++)for (int j=0;j<=bb;j++){if ((i&j)>c1) continue;if ((i^j)<c2) continue;ret+=dfs(pos-1,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,0,sizeof(a));memset(b,0,sizeof(b));memset(c,0,sizeof(c));memset(f,-1,sizeof(f));cal(A,a); cal(B,b); cal(C,c);ll ans=dfs(30,1,1,1,1);ans-=max(0,A-C+1);ans-=max(0,B-C+1); //減掉x,y為0的情況printf("%lld\n",(ll)A*B-ans);}return 0; } View Code

?

轉載于:https://www.cnblogs.com/tetew/p/11324428.html

總結

以上是生活随笔為你收集整理的牛客多校第六场-H-Pair的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。