Codeforces Round #195 (Div. 2) C. Vasily the Bear and Sequence
来源:互联网 发布:echarts饼图显示数据 编辑:程序博客网 时间:2024/04/29 15:06
啊啊啊啊啊啊
一开始想错了,以为只能是某一个数取并之后 必须得到一个 2的某次方 其实比如第三组数据
3
1 20 22
输出
2
20 22 (取并以后是20 20%4==0 oh fuck!)
意思应该是得到一个2的某次方的倍数就可以了。
思路:枚举每一位上的1。看这一位上的 1 是否可以满足条件。
当然 只要这个数的该位是1 就可以用来并 因为题目是要越多越好 而且越多的话也不会改变什么 有0的地方 再多的数也是0
#include <iostream>#include <cstdio>#include <cstring>#include <vector>using namespace std;vector <int> ans;int n;int X[100005];int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&X[i]); for(int i=30;i>=0;i--) { ans.clear(); int tmp=-1; for(int j=1;j<=n;j++) { if(X[j]&(1<<i)) { ans.push_back(X[j]); if(tmp==-1)tmp=X[j]; else tmp&=X[j]; } } if(tmp%(1<<i)==0)break; } printf("%d\n%d",ans.size(),ans[0]); for(int i=1;i<ans.size();i++) printf(" %d",ans[i]); puts(""); return 0;}
- Codeforces Round #195 (Div. 2) C. Vasily the Bear and Sequence
- Codeforces Round #195 (Div. 2) C--Vasily the Bear and Sequence(贪心)
- Codeforces Round #195 (Div. 2) A Vasily the Bear and Triangle
- Codeforces Round #195 (Div. 2) / 336A Vasily the Bear and Triangle(模拟&数学)
- Codeforces Round #195 (Div. 2) B. Vasily the Bear and Fly - 找规律
- CodeForces #195 Div.2-A. Vasily the Bear and Triangle
- codeforces 336C Vasily the Bear and Sequence
- Codeforces 336C Vasily the Bear and Sequence 暴力
- Codeforces 336C Vasily the Bear and Sequence (暴力)
- [Codeforces Round #195 DIV2B (CF336B)] Vasily the Bear and Fly
- [Codeforces Round #195 DIV2E (CF336E)] Vasily the Bear and Painting Square
- [Codeforces Round #195 DIV2D (CF336D)] Vasily the Bear and Beautiful Strings
- Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers
- Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers
- Codeforces Round #318 (Div. 2) C - Bear and Poker
- Codeforces Round #226 (Div. 2)--C. Bear and Prime Numbers
- Codeforces Round #356 (Div. 2)-C. Bear and Prime 100
- Codeforces Round #356 (Div. 2)-C. Bear and Prime 100
- 《灵飞经5·龙生九子》第二十四章 九王朝阙 下
- securecrf中vim选中不能复制却变成visual模式
- 用java从网络上抓取HTML文件内容并写入本地文本中
- js2dx --- CocosBuilder
- URAL 1343
- Codeforces Round #195 (Div. 2) C. Vasily the Bear and Sequence
- ubuntu 10.04 Lucid 更新源列表,适合国内大部分电信、网通用户
- MySQL+Sphinx实现全文搜索
- Wikioi 天梯 十进制转m进制(1474)
- JSP中下列列框详解
- 推荐使用jquerymobile做移动开发
- php的$_POST数组
- ubuntu安装中文输入法
- ARM处理器模式切换(含MRS,MSR指令)