日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/7/25 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 coeforces 665D D. Simple Subset(最大团orsb题) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目鏈接:

D. Simple Subset

time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

A tuple of positive integers?{x1,?x2,?...,?xk}?is called simple if for all pairs of positive integers?(i,??j)?(1??≤?i??<??j?≤?k),?xi??+??xj?is a prime.

You are given an array?a?with?n?positive integers?a1,??a2,??...,??an?(not necessary distinct). You want to find a simple subset of the array?awith the maximum size.

A prime number (or a prime) is a natural number greater than?1?that has no positive divisors other than?1?and itself.

Let's define a subset of the array?a?as a tuple that can be obtained from?a?by removing some (possibly all) elements of it.

?

Input

The first line contains integer?n?(1?≤?n?≤?1000) — the number of integers in the array?a.

The second line contains?n?integers?ai?(1?≤?ai?≤?106) — the elements of the array?a.

?

Output

On the first line print integer?m?— the maximum possible size of simple subset of?a.

On the second line print?m?integers?bl?— the elements of the simple subset of the array?a?with the maximum size.

If there is more than one solution you can print any of them. You can print the elements of the subset in any order.

?

Examples input 2
2 3 output 2
3 2 input 2
2 2 output 1
2 input 3
2 1 1 output 3
1 1 2 input 2
83 14 output 2
14 83


題意:

選一個(gè)最大的子序列,滿足這個(gè)序列里的任意兩個(gè)數(shù)的和是素?cái)?shù);

思路:

可以是一個(gè)最大完全數(shù)的題,也可以是水題,因?yàn)槠鏀?shù)+奇數(shù)=偶數(shù),偶數(shù)+偶數(shù)=偶數(shù),(1除外);所以最多有一個(gè)奇數(shù)和一個(gè)偶數(shù);
我寫的分情況討論的代碼真是跟翔一樣;

AC代碼:

#include <bits/stdc++.h> using namespace std; const int N=2e6+6; typedef long long ll; int n,a[1010],flag[N]; int get_prime() {for(int i=2;i<N;i++){if(!flag[i]){for(int j=2*i;j<N;j+=i){flag[j]=1;}}} } queue<int>qu; void print() {printf("%d\n",qu.size());while(!qu.empty()){printf("%d ",qu.front());qu.pop();} }int main() {get_prime();int f=0;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]==1){f++;qu.push(1);}}if(f>1){for(int i=1;i<=n;i++){if(a[i]>1&&!flag[a[i]+1]){for(int j=i+1;j<=n;j++){if(a[j]>1&&!flag[a[i]+a[j]]&&!flag[a[j]+1]){qu.push(a[i]);qu.push(a[j]);print();return 0;}}}}for(int i=1;i<=n;i++){if(a[i]>1&&!flag[a[i]+1]){qu.push(a[i]);print();return 0;}}print();}else if(f==1){for(int i=1;i<=n;i++){if(a[i]>1&&!flag[a[i]+1]){for(int j=i+1;j<=n;j++){if(a[j]>1&&!flag[a[i]+a[j]]&&!flag[a[j]+1]){qu.push(a[i]);qu.push(a[j]);print();return 0;}}}}for(int i=1;i<=n;i++){if(a[i]>1){for(int j=i+1;j<=n;j++){if(a[j]>1&&!flag[a[i]+a[j]]){printf("2\n");printf("%d %d",a[i],a[j]);return 0;}}}}for(int i=1;i<=n;i++){if(a[i]>1&&!flag[a[i]+1]){qu.push(a[i]);print();return 0;}}print();}else{for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++){if(!flag[a[i]+a[j]]){qu.push(a[i]);qu.push(a[j]);print();return 0;}}}printf("1\n");printf("%d",a[1]);}return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/zhangchengc919/p/5421033.html

總結(jié)

以上是生活随笔為你收集整理的coeforces 665D D. Simple Subset(最大团orsb题)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。