牛客多校第六场-H-Pair
生活随笔
收集整理的這篇文章主要介紹了
牛客多校第六场-H-Pair
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
鏈接:https://ac.nowcoder.com/acm/contest/887/H
來(lái)源:牛客網(wǎng)
題目描述
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數(shù)位dp求 x&y<=c && x^y>=c的個(gè)數(shù)然后用所有方案剪掉 具體見(jiàn)代碼 #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說(shuō)明之前一直相等當(dāng)前位取要<=a,否則說(shuō)明之前<a了當(dāng)前位可以亂取int bb=limb?b[pos]:1;int c1=limand?c[pos]:1; //同理如果之前x&y一直等于c那么當(dāng)前位要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
?
轉(zhuǎn)載于:https://www.cnblogs.com/tetew/p/11324428.html
總結(jié)
以上是生活随笔為你收集整理的牛客多校第六场-H-Pair的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: bootstrap 模态窗口 多重/多个
- 下一篇: VC++6中的一些快捷键(陆续补充中。。