hdu-5269(bc #44)
来源:互联网 发布:淘宝psv游戏 编辑:程序博客网 时间:2024/06/05 09:23
题意:求所有lowbit(Ai xor Aj)的和。即Ai^Aj的值第一个1出现的位置k,求k<<1的和。
思路:
#include<iostream>#include<stdio.h>#include<math.h>#include <string>#include<string.h>#include<map>#include<set>#include<algorithm>#include<stdlib.h>using namespace std;#define eps 1e-8#define inf 0x3f3f3f3f#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define ll long long int#define maxn 1000005#define mod 998244353struct node{ int sum; int l,r;}f[1000000];void init(int x){ f[x].l=f[x].r=f[x].sum=0;}int tot;ll cal(int root,int k){//统计总和。 if(root==0||k>29) return 0; return (2ll*(f[f[root].l].sum*(1<<k)%mod)*f[f[root].r].sum%mod+cal(f[root].l,k+1)%mod+cal(f[root].r,k+1)%mod)%mod;}void Insert(int root,int x,int k){//向二叉树插入值。 if(k>29) { f[root].sum++; return ; } if(x&1){ if(f[root].l==0) { f[root].l=++tot; init(tot); } Insert(f[root].l,x>>1,k+1); } else{ if(f[root].r==0) { f[root].r=++tot; init(tot); } Insert(f[root].r,x>>1,k+1); } f[root].sum=f[f[root].l].sum+f[f[root].r].sum;}int main(){ int T,t=0; int n,f[10]; int x; rd(T); while(T--){ tot=1; init(0); init(1); rd(n); for(int i=1;i<=n;i++) { rd(x); Insert(1,x,0); } printf("Case #%d: %I64d\n",++t,cal(1,0)); } return 0;}
0 0
- hdu-5269(bc #44)
- BC-33 hdu 5186
- BC,HDU 5719
- BC-Round 3 HDU 4908
- HDU BC#39 1002 Mutiple
- BC#41 hdu 5228 5229
- bc
- bc
- bc
- bc
- BC
- BC
- BC C Revenge of Collinearity hdu 5020
- hdu 5059 BC#12 Help him
- BC#34 1002 hdu 5192 Building Blocks
- BC-40 HDU5225 HDU 5226 【水】
- BC#45 1004 && HDU 5275【差值方法】
- HDU 4956/BC 5A Poor Hanamichi
- nginx 配置案例
- 将输入框内容进行修改及替换html标签
- web利用CXF+Spring+structs搭建webservices服务器
- Linux 正则表达式详解
- 终结符和非终结符
- hdu-5269(bc #44)
- 多个Fragment时的加载优化,使用懒加载
- 【算法复习一】常见的算法策略汇总
- 黑马程序员——JAVA集合
- Django数据库操作(python)
- 一步步将vim改造成C/C++开发环境(IDE)
- 学习七十一雾央MFC游戏心得,初体验(八)
- JMS基本概念
- Sona - NBUT 1457 莫队算法