codeforces195c
link:http://codeforces.com/problemset/problem/336/C
从大到小枚举,如果对应的二进制位不等于0,就加进来,最后的sum如果%2^k==0那么就是合法的。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
int a[];
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int n;
while (~scanf("%d", &n))
{
for (int i=;i<n;++i) scanf("%d",a+i);
for (int i=;i>=;--i)
{
int sad=<<i, sum=-, cnt=;
for (int j=;j<n;++j)
{
if((sad&a[j])!=)
{
if(sum==-) sum=a[j];
else sum = sum & a[j];
cnt++;
}
}
int tmp=;
if (sum%sad==)
{
printf("%d\n",cnt);
for (int j=;j<n;++j)
{
if((sad&a[j])!=)
{
tmp++;
if(tmp!=cnt)
printf("%d ",a[j]);
else printf("%d\n",a[j]);
}
}
break;
}
}
} return ;
}
很神奇的做法。
开始被这道题目吓到了。o(╯□╰)o
codeforces195c的更多相关文章
随机推荐
- 里面的div怎么撑开外面的div让高度自适应
			
参考网址:http://www.jb51.net/css/140685.html 随着微软新操作系统的上市,ie6现在用的人越来越少了,但是XP系统看来是太过经典,仍然有相当多的用户在使用,且这部分人 ...
 - javascript 函数声明和函数表达式的区别(学习笔记)
			
javascript中声明函数的方法有两种:函数声明式和函数表达式. 区别如下: 1).以函数声明的方法定义的函数,函数名是必须的,而函数表达式的函数名是可选的. 2).以函数声明的方法定义的函数,函 ...
 - HTML基础(1)
			
1.前端开发语言介绍 HTML(Hypertext Markup Language)—— 结构—— 超文本标记语言 CSS(Cascading Style Sheets)—— 样式—— 层叠样式表 J ...
 - union (共用声明和共用一变量定义)
			
"联合"是一种特殊的类,也是一种构造类型的数据结构.在一个"联合"内可以定义多种不同的数据类型, 一个被说明为该"联合"类型的变量中,允许装 ...
 - spring主要的作用?
			
在SSH框假中spring充当了管理容器的角色.我们都知道Hibernate用来做持久层,因为它将JDBC做了一个良好的封装,程序员在与数据库进行交互时可以不用书写大量的SQL语句.Struts是用来 ...
 - nginx反向代理实现跨域请求
			
nginx反向代理实现跨域请求 跨域请求可以通过JSONP实现,缺点是需要修改被请求的服务器端代码进行配合,稍显麻烦通过在自己服务器上配置nginx的反向代理,可以轻松实现跨域请求 思路 示例服务器A ...
 - urlencode 和 rawurlencode 的区别
			
urlencode和rawurlencode的区别urlencode和rawurlencode的区别 $str1 = urlencode(':/?= &#'); $str2 = rawurle ...
 - Cube Mapping
			
Cube map技术说到底就是用一个虚拟的立方体(cube)包围住物体,眼睛到物体某处的向量eyevec经过反射(以该处的法线为对称轴),反射向量reflectvec射到立方体上,就在该立方体上获得一 ...
 - Authentication和Authorization的区别
			
搞不太清楚Authentication和Authorization的区别,在网上搜了一下,lucky16的一篇文章讲的通俗,看了就懂,记录下来: 你要登机,你需要出示你的身份证和机票,身份证是为了证明 ...
 - 能源项目xml文件 -- springMVC-servlet.xml -- context:component-scan
			
<context:component-scan base-package="com.xindatai.ibs" use-default-filters="false ...