CodeForces - 665D Simple Subset 想法题
//题意:给你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 想法题的更多相关文章
- Codeforces 665D Simple Subset【构造】
题目链接: http://codeforces.com/problemset/problem/665/D 题意: 给定序列,从中找出最大的子集,使得子集中的数两两相加均为质数. 分析: 貌似有用最大团 ...
- Codeforces 665D Simple Subset [简单数学]
题意: 给你n个数,让你从中选一个子集要求子集中的任何两个数相加都是质数. 思路: 一开始把自己坑了,各种想,后来发现一个简单的性质,那就是两个数相加的必要条件是这两个数之中必定一个奇数一个偶数,(除 ...
- codeforces 665D Simple Subset
题目链接 给一个数列, 让你选出其中的m个数, 使得选出的数中任意两个数之和都为质数, m尽可能的大. 首先, 除了1以外的任意两个相同的数相加结果都不是质数. 然后, 不考虑1的话, 选出的数的个数 ...
- CodeFores 665D Simple Subset(贪心)
D. Simple Subset time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- CodeForces - 344B Simple Molecules (模拟题)
CodeForces - 344B id=46665" style="color:blue; text-decoration:none">Simple Molecu ...
- codeforces 704B - Ant Man [想法题]
题目链接:http://codeforces.com/problemset/problem/704/B ------------------------------------------------ ...
- coeforces 665D D. Simple Subset(最大团orsb题)
题目链接: D. Simple Subset time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 12 D. Simple Subset 最大团
D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...
- CodeForces 111B - Petya and Divisors 统计..想法题
找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...
随机推荐
- 今天被坑了,而且被坑的好爽! 该死的UTF-8 有 BOM 格式编码
调一个项目,最后无法登录了. 排查到最后发现是cookie无法保存会话ID, 工作两年的经验这时候没用上. 开始一以为是PHP.ini的配置错了. 考虑过域名,浏览器问题. 脚本BUG. 最后最后一步 ...
- headless webkit(无界面浏览器、爬虫)
phantomjs / puppeteer https://github.com/amir20/phantomjs-node https://github.com/GoogleChrome/puppe ...
- MySQL on Linux 部署手册
1. 背景 MySQL为开源数据库,因此可以基于源码实现安装.基于源码安装有更多的灵活性.也就是说我们可以针对自己的硬件平台选用合适的编译器来优化编译后的二进制代码,根据不同的软件平台环境调整相关的编 ...
- Oracle查询锁表和解锁
1.查询是否锁表 SELECT l.session_id sid, s.serial#, l.locked_mode,l.oracle_username, l.os_user_name,s.machi ...
- python cookie
http://www.jayconrod.com/posts/17/how-to-use-http-cookies-in-python
- 关于linux下文件的权限问题
今天在linux更新服务中的启动文件时,直接把更新的启动文件拷贝过来执行,报错:can't be execute 后来想了下列出了文件的详细信息中发现拷贝过去的执行文件是-r--r--r--(表示只有 ...
- 转:git windows中文目录乱码问题解决
Git的Windows版本Msysgit对中文的支持不够好 当使用时,会出现以下三种情况的中文乱码: 1.ls不能显示中文目录 解决办法:在git/git-completion.bash中增加一行: ...
- 随心所欲玩复制 详解robocopy
说实话,Windows系统自带的复制功能不仅功能简单,而且定制性也不强,每每在对大量文件进行复制.移动.备份时,总少不了繁杂往复的操作.不过幸好,微软意识到了这一点,为我们提供了一款很强力的复制备份工 ...
- linux批量修改文件名
源文件; [root@test_machine fuzj]# ls fuzj-1.txt fuzj-2.txt fuzj-3.txt fuzj-4.txt fuzj-5.txt fuzj-6 ...
- 【python3】基于 qq邮箱的邮件发送
脚本内容: #!/usr/bin/python3 # -*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText ...