//题意:给你n个数(可能有重复),问你最多可以取出多少个数使得任意两个数之和为质数。
//题解:以为是个C(2,n)复杂度,结果手摸几组,发现从奇偶性考虑,只有两种情况:有1,可以取出所有的1,并可以再取一个偶数(如果这个偶数+1是质数)。没有1,如果取了一个奇质数,那只能再拿一个2(如果有2的话)。

坑:一度把题目记错了,以为输入的是质数,结果比赛的时候一直wa到orz

ac代码:

#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;
const int maxn = (1e6 + ) * ;
const int mod = 1e9 + ;
int isp[maxn];
int p[];
void setp() { for (int i = ; i <= maxn; i++)isp[i] = ;
isp[] = ;
for (int i = ; i*i <= maxn; i++)if (isp[i]) {
int x = i;
while (x*i <= maxn) {
isp[x*i] = ;
x++;
}
}
}
int main() {
int n;
cin >> n;
int cnt = , c2 = ;
setp();
//for(int i=1;i<=5;i++)if(isp[i])cout<<i<<' ';
for (int i = ; i <= n; i++) {
cin >> p[i];
if (p[i] == )cnt++;
if (p[i] == )c2 = ;//题目记错了
}
if (cnt >= ) {
//cout << cnt + c2 << endl;
int tmp=;
for (int i = ; i <= n; i++)if (p[i] % == ) {
if (isp[p[i] + ])tmp = p[i];
}
if (tmp==)cout << cnt;
else cout << cnt + ;
cout << endl;
while (cnt--)cout << << ' ';
if (tmp)cout << tmp;
cout << endl; //if (c2)cout << 2;
}
else { sort(p + , p + n + );
for (int i = ; i<n; i++) {
for (int j = i + ; j <= n; j++) {
if (isp[p[i] + p[j]]) { printf("%d\n%d %d", , p[i], p[j]); return ; }
}
}
int okk = ;
for (int i = ; i <= n; i++)if (isp[p[i]]) { okk = p[i]; break; }
if (okk) printf("%d\n%d", , okk);
else cout << << endl, cout << p[];//莫名其妙的一句,忘了当时为啥加的 }
}

CodeForces - 665D Simple Subset 想法题的更多相关文章

  1. Codeforces 665D Simple Subset【构造】

    题目链接: http://codeforces.com/problemset/problem/665/D 题意: 给定序列,从中找出最大的子集,使得子集中的数两两相加均为质数. 分析: 貌似有用最大团 ...

  2. Codeforces 665D Simple Subset [简单数学]

    题意: 给你n个数,让你从中选一个子集要求子集中的任何两个数相加都是质数. 思路: 一开始把自己坑了,各种想,后来发现一个简单的性质,那就是两个数相加的必要条件是这两个数之中必定一个奇数一个偶数,(除 ...

  3. codeforces 665D Simple Subset

    题目链接 给一个数列, 让你选出其中的m个数, 使得选出的数中任意两个数之和都为质数, m尽可能的大. 首先, 除了1以外的任意两个相同的数相加结果都不是质数. 然后, 不考虑1的话, 选出的数的个数 ...

  4. CodeFores 665D Simple Subset(贪心)

    D. Simple Subset time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  5. CodeForces - 344B Simple Molecules (模拟题)

    CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecu ...

  6. codeforces 704B - Ant Man [想法题]

    题目链接:http://codeforces.com/problemset/problem/704/B ------------------------------------------------ ...

  7. coeforces 665D D. Simple Subset(最大团orsb题)

    题目链接: D. Simple Subset time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Educational Codeforces Round 12 D. Simple Subset 最大团

    D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...

  9. CodeForces 111B - Petya and Divisors 统计..想法题

    找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...

随机推荐

  1. php前端传过来的json数据丢失 (max_input_vars)

    开发向我反馈,前端业务页面提交数据用js将要传输的数据用json dump后,发给服务器,服务器在loads后发现数据是不全的. 这个问题困扰开发人员和运维人员.首先调整php.ini文件的上传文件数 ...

  2. 查看本地RF版本号

    在CMD下执行:pybot --version

  3. asp.net 验证码

    Before proceeding with the topic first we must understand "What is a Captcha code?" and &q ...

  4. Python对文件和文件路径的管理

    1. 使用os.path进行路径和文件管理 1.1 拆分路径 os.path.split                   返回一个二元组,包含文件路径和文件名 os.path.dirname    ...

  5. repr方法字符串输出实例对象的值

    #coding=utf-8 #repr方法字符串输出实例对象的值 class CountFromBy(object): def __init__(self, val=0, incr=1): self. ...

  6. 常见C语言编译错误解析【转】

    C语言编译错误信息及说明1. 在函数 ‘transform’ 中:7: 错误:expected ‘;’ before ‘{’ token    解释:‘{’之前的某个语句缺少分号‘;’: 2. 在函数 ...

  7. 【API设计】RESTful API 设计指南

    RESTful API URL定位资源,用HTTP动词(GET,POST,DELETE,DETC)描述操作. 例如 . REST描述的是在网络中client和server的一种交互形式:REST本身不 ...

  8. linux多行注释

    1.多行注释:   1. 首先按esc进入命令行模式下,按下Ctrl + v,进入列(也叫区块)模式;   2. 在行首使用上下键选择需要注释的多行;   3. 按下键盘(大写)“I”键,进入插入模式 ...

  9. 【docker】 追加端口映射时 报错 WARNING: IPv4 forwarding is disabled. Networking will not work.

    解决办法: vi /etc/sysctl.conf 添加如下代码: net.ipv4.ip_forward= 重启network服务 systemctl restart network 查看: sys ...

  10. 【WEB前端开发最佳实践系列】高可读的HTML

    一.HTML语义化 HTML5中增加了很多标签都是基于此类原则设计的(article   nav  header  footer).页面标签语义化的优点是使得搜索引擎以及第三方抓包工具等更容易读懂页面 ...