【51Nod1406】与查询
来源:互联网 发布:淘宝查排名 编辑:程序博客网 时间:2024/06/01 23:07
有n个整数。输出他之中和x相与之后结果为x的有多少个。x从0到1,000,000
Input
第一行输入一个整数n。(1<=n<=1,000,000).
第二行有n个整数a[0],a[1],a[2],…a[n-1],以空格分开.(0<=a[i]<=1,000,000)
Output
对于每一组数据,输出1000001行,第i行对应和i相与结果是i的有多少个数字。
Input示例
3
2 3 3
Output示例
3
2
3
2
0
0
……
后面还有很多0
题解
两秒题,很容易想到倒得枚举所有子集,但是这样会有重复,把枚举位的循环(从大到小枚举)打在外面即可。
代码
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<set>#include<ctime>#include<vector>#include<cmath>#include<algorithm>#include<map>#define mod 1000000007 #define ll long long #define inf 1e9using namespace std;inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}void write(int x){ int a1=0,a[20]; a[1]=0; if (!x) a1++; while (x) { a[++a1]=x%10;x/=10; } for (int i=a1;i>=1;i--) putchar(a[i]+'0');}int n,dp[1000005];int main(){ n=read(); for (int i=1;i<=n;i++) { int x=read(); dp[x]++; } for (int j=20;j>=0;j--) for (int i=1e6;i>=0;i--) if (i&(1<<j)) dp[i^(1<<j)]+=dp[i]; for (int i=0;i<=1e6;i++) write(dp[i]),puts(""); return 0;}
阅读全文
0 0
- 【51Nod1406】与查询
- 51nod1406 与查询 dp
- 51Nod-1406-与查询
- 51nod-1406 与查询
- 51nod 1406 与查询
- 51nod 1406 与查询
- 51nod 1406 与查询 二进制+暴力
- 51 nod 1406 与查询(思维)
- jpa 查询对象与查询
- 左右查询与内查询
- 连接查询与子查询
- 连接查询与子查询
- hibernate 查询与连接
- 分页与查询优化
- 分组查询与排序
- JTable与数据库查询
- Hibernate查询与缓存
- j2me与xml查询
- SpringBoot前后端传送文件问题
- 刷题-NOIP历年真题
- Add Two Numbers 两个链表相加 python
- Java桥接模式知识点总结
- android安装busybox
- 【51Nod1406】与查询
- 文章标题
- GIT 分支的合并 与 分支删除 (merge与delete)
- <5>—— Longest Palindromic Substring
- 多线程编程核心技术读书笔记(一):Java多线程技能
- POJ-2109:Power of Cryptography
- TensorFlow cpu-only 安装记录
- iOS tableview的delegate和datasource执行顺序
- 解决Ubuntu无法从外部应用启动Chrome打开链接的问题