这题是大一暑假时候做的,当时没有出,直到今天突然觉得应该把没过的题目再做一边,不然真的是越积越多。

现在能够独立做出来真的是难以表达的兴奋,刚开始的时候就觉得 O(30 * 30 * n)的复杂度有点不安全,不过还是敲了,事实说明实际的负责度没这么高。和去年一样,没有思路,后来仔细一想,真的是数学题。现在感觉爱上了Math...

附上代码:

 #include <cstdio>
#include <cstring> // 保存原始数组
int b[];
// a[i][j]表示b[i]的二进制表示法中的各个位上的数值, 而able数组保存的是每一轮中可以选的标记
bool a[][], able[];
int n; int main(void) {
while (~scanf("%d", &n) && n) {
memset(a, false, sizeof(a));
for (int i = ; i < n; i++) {
int x;
scanf("%d", &x);
b[i] = x;
for (int j = ; j >= ; j--) {
if (( << j) & x)
a[i][-j] = true;
}
} int cnt;
for (int i = ; i <= ; i++) {
cnt = ;
memset(able, false, sizeof(able));
for (int j = ; j < n; j++) {
if ( a[j][i] ) {
able[j] = true;
cnt++;
}
}
if (cnt == ) continue; int j;
for (j = i + ; j <= ; j++) {
int f = ;
for (int k = ; k < n; k++) {
if ( able[k] ) {
if ( !a[k][j] ) {
f = ;
break;
}
}
}
if (f == )
break;
}
if (j > )
break;
}
printf("%d\n", cnt);
int flag = ;
for (int i = ; i < n; i++) {
if ( able[i] ) {
if (flag)
printf(" ");
flag = ;
printf("%d", b[i]);
}
}
puts("");
} return ;
}

Codeforces 336C的更多相关文章

  1. codeforces 336C Vasily the Bear and Sequence(贪心)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Vasily the Bear and Sequence Vasily the b ...

  2. Codeforces 336C 0-1背包

    题意:每个水果有两个值,一个美味度 a,一个卡路里 b,从中挑选一些,要求 sum(aj) / sum(bj) = k,使得 sum(a) 最大. 分析:没有那个条件就是一个01背包,可以转换,对公式 ...

  3. C. Vasily the Bear and Sequence Codeforces 336C(枚举,思维)

    C. Vasily the Bear and Sequence time limit per test 1 second memory limit per test 256 megabytes inp ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. spring入门案例分析及原理

    Springmvc执行原理: 一. 入门案例的执行流程 1. 当启动Tomcat服务器的时候,因为配置了load-on-startup标签,所以会创建DispatcherServlet对象,就会加载s ...

  2. 图像Ping技术

    在CORS出现以前,要实现跨域Ajax通信颇费一些周折.开发人员想出了一些办法,利用DOM中能够执行跨域清求的功能,在不依赖XHR对象的情况下也能发送某种请求.虽然CORS技术已经无处不在,但开发人员 ...

  3. git图形化

    在windows下安装git中文版客户端并连接gitlab 转载自:https://blog.whsir.com/post-1801.html 下载git Windows客户端 git客户端下载地址: ...

  4. Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal

    学习htmlutil发现报错 完整的引入 <!-- 引入htmlunit --> <dependency> <groupId>net.sourceforge.htm ...

  5. org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.hs.model.StudentModel]: No default constructor found; nested exception is java.lang.NoSuchMethodException: c

    root cause org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [c ...

  6. jnhs-SpringMVC jsp页面向controller传递参数的五种方式

    一共是五种传参方式: 一:直接将请求参数名作为Controller中方法的形参 public  String login (String username,String password)   : 解 ...

  7. SpringCloud微服务实战二:Spring Cloud Ribbon 负载均衡 + Spring Cloud Feign 声明式调用

    1.Spring Cloud Ribbon的作用 Ribbon是Netflix开发的一个负载均衡组件,它在服务体系中起着重要作用,Pivotal将其整合成为Spring Cloud Ribbon,与其 ...

  8. Docker Nginx部署

    1.下载nginx镜像 docker pull nginx 2.创建nginx配置文件 vim /etc/nginx/nginx.conf user nginx; worker_processes 1 ...

  9. 2018-8-10-win10-uwp-禁止编译器优化代码

    title author date CreateTime categories win10 uwp 禁止编译器优化代码 lindexi 2018-08-10 19:16:50 +0800 2018-2 ...

  10. Uva10817 Headmaster's Headache

    https://odzkskevi.qnssl.com/b506a3c20adad78678917d1ff4c9b953?v=1508327485 [题解] dp[i][S1][S2]表示前i个教师选 ...