//题意:给你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. XSS三重URL编码绕过实例

    遇到一个很奇葩的XSS,我们先来加一个双引号,看看输出: 双引号被转义了,我们对双引号进行URL双重编码,再看一下输出: 依然被转义了,我们再加一层URL编码,即三重url编码,再看一下输出: URL ...

  2. mysql类型对应Java的类型

    整型 JDBCtinyint         java.lang.Integersmallintmediumint       java.lang.Longint          bigint    ...

  3. osgearth2.8关于RectangleNodeEditor编辑点不可见的问题

    static_cast<SphereDragger*>(_llDragger)->setColor(osg::Vec4(0,0,1,0)); Alpha写成了0 应该写成 stati ...

  4. 系统头文件cmath,cstdlib报错

    >C:\Program Files (x86)\Microsoft Visual Studio\\Community\VC\Tools\MSVC\\include\cstdlib(): erro ...

  5. mysql基础知识笔记

    Mysql基础笔记 环境配置 基本概念 mysql命令行 进入 use show 查询 select order by where like 数据过滤regexp concat 文本函数 日期函数 数 ...

  6. 使用java中的session来记录访问次数

    <%@ page import="java.net.CookieHandler" %><%-- Created by IntelliJ IDEA. User: D ...

  7. Netty《一》

    作者:郭无心链接:https://www.zhihu.com/question/24322387/answer/78947405来源:知乎著作权归作者所有,转载请联系作者获得授权. Netty是什么? ...

  8. 【小程序+thinkphp5】 用户登陆,返回第三方session3rd

    服务器环境: centos7   php7.0 准备工作: 注册小程序,并获取 appid .appsecret 下载微信解密算法sdk : https://mp.weixin.qq.com/debu ...

  9. 【大数据系列】hadoop上传文件报错_COPYING_ could only be replicated to 0 nodes

    使用hadoop上传文件 hdfs dfs -put  XXX 17/12/08 17:00:39 WARN hdfs.DFSClient: DataStreamer Exception org.ap ...

  10. MFC 常见问题

    一 常见变量获得 CDC * cDc=GetDC(); HDC m_Screenhdc = this->GetDC()->m_hDC; //  整个窗口客户区的坐标 this->Ge ...