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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Summarize to the Power of Two(CF-1005C)

發布時間:2025/3/17 编程问答 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Summarize to the Power of Two(CF-1005C) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

A sequence a1,a2,…,an is called good if, for each element aiai, there exists an element ajaj (i≠j) such that ai+aj is a power of two (that is, 2d for some non-negative integer dd).

For example, the following sequences are good:

[5,3,11]?(for example, for a1=5 we can choose a2=3. Note that their sum is a power of two. Similarly, such an element can be found for a2 and a3),
[1,1,1,1023]
[7,39,89,25,89],
[][].

Note that, by definition, an empty sequence (with a length of 0) is good.

For example, the following sequences are not good:

[16] (for a1=16, it is impossible to find another element aj such that their sum is a power of two),
[4,16] (for a1=4, it is impossible to find another element aj such that their sum is a power of two),
[1,3,2,8,8,8] (for a3=2, it is impossible to find another element aj such that their sum is a power of two).
You are given a sequence a1,a2,…,an. What is the minimum number of elements you need to remove to make it good? You can delete an arbitrary set of elements.

Input

The first line contains the integer nn (1≤n≤120000) — the length of the given sequence.

The second line contains the sequence of integers a1,a2,…,an(1≤ai≤10^9).

Output

Print the minimum number of elements needed to be removed from the given sequence in order to make it good. It is possible that you need to delete all nn elements, make it empty, and thus get a good sequence.

Examples

Input

6
4 7 1 5 4 9

Output

1

Input

5
1 2 3 4 5

Output

2

Input

1
16

Output

1

Input

4
1 1 1 1023

Output

0

題意:給出 n 個數,對于每個數 ai,要求 ai+aj 都為2的冪,求不符合條件的個數

思路:

要判斷是否和為 2 的冪,因此可以貪心的從 2^30 向下進行枚舉,如果數組中的每一個數 ai,在數組中存在 j-ai 的話,則證明符合條件,反之則不符合。

因為題目的數據范圍較大,因此用?map 存儲。

Source Program

#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<cstdlib> #include<queue> #include<set> #include<map> #include<stack> #include<ctime> #include<vector> #define INF 0x3f3f3f3f #define PI acos(-1.0) #define N 1000005 #define MOD 123 #define E 1e-6 using namespace std; map<long long,long long> mp; map<long long,bool>vis; long long a[N]; int main() {int n;cin>>n;for(int i=0;i<n;i++){cin>>a[i];mp[a[i]]++;}sort(a,a+n);int cnt=0;for(int i=0;i<n;i++){if(vis[a[i]])continue;bool flag=true;for(long long j=1<<30;j>=1;j>>=1){if(j<a[i])break;if(mp.count(j-a[i])){if(j-a[i]==a[i]&&mp[j-a[i]]==1)continue;vis[a[i]]=1;vis[j-a[i]]=1;flag=false;break;}}if(flag)cnt++;}cout<<cnt<<endl;return 0; }

?

總結

以上是生活随笔為你收集整理的Summarize to the Power of Two(CF-1005C)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 少妇脱了内裤让我添 | 日韩精品在线观看免费 | 黄网页在线观看 | 国产伦一区二区 | 欧美成人xxx | 老熟女一区二区三区 | 伊久久 | www.青青草| 艳妇臀荡乳欲伦交换在线看 | 经典三级在线视频 | 国产a久久| 色综合网站 | 精品视频一区二区在线观看 | 综合久久久久综合 | 中文字幕首页 | 久久久久久婷婷 | 日韩中文字幕免费视频 | 亚洲在线免费 | 男人的天堂在线视频 | 性欧美18—19sex性高清 | 久久精品一区二区三 | 亚洲精品国产精品乱码在线观看 | 国产粉嫩在线观看 | 91禁蘑菇在线看 | 动漫av在线免费观看 | 亚洲国产一区二区三区四区 | a天堂中文网 | 日韩视频不卡 | 91蝌蚪少妇偷拍 | 免费久久av | 精品人妻伦一二三区久 | 男生操女生网站 | 久久在线免费视频 | 黄色草逼视频 | 性xxx18| 免费在线国产精品 | 久久草视频 | 毛片av网址| 国产综合视频一区 | 青青草原成人网 | 91尤物视频 | 加勒比在线免费视频 | 亚洲激情网站 | 成人免费xxxxxx视频 | 精品一区不卡 | 野外吮她的花蒂高h在线观看 | 东方成人av在线 | 欧美日韩在线免费看 | 一级免费黄色大片 | 国产男女视频 | 免费欧美一级 | 亚洲欧美久久 | 波多野结衣在线免费观看视频 | 杨幂国产精品一区二区 | 亚洲成人av | 成人黄色小说视频 | 国产网站精品 | 经典三级视频 | 欧美xxxx性xxxxx高清 | 成年人视频在线免费观看 | 成年人性生活免费视频 | 成人精品视频在线观看 | 天海翼一二三区 | 中文字幕第一页av | 香蕉视频免费网站 | 午夜吃瓜 | 久久国产成人精品国产成人亚洲 | 日韩免费视频 | 97国产精品久久 | 吃瓜网今日吃瓜 热门大瓜 色婷在线 | 国产老妇伦国产熟女老妇视频 | 99人妻碰碰碰久久久久禁片 | 最新天堂中文在线 | 四级黄色片 | 欧美日一区二区 | 性色av一区二区三区红粉影视 | 国产肉体xxxx裸体784大胆 | 国产精品视频久久久久久 | 在线看片一区二区 | 老司机综合网 | 亚洲永久精品一区 | 老司机狠狠爱 | 亚洲一区二区三区高清在线 | 国内偷拍av | 国产91精品一区二区麻豆亚洲 | 在线观看av网站 | 日日狠狠久久 | 国产精品资源网 | 亚洲欧美va天堂人熟伦 | 国产无套精品 | 日本九九视频 | 捆绑无遮挡打光屁股调教女仆 | 亚洲av永久无码精品放毛片 | gv天堂gv无码男同在线观看 | 国产成人在线精品 | 欧美videossex另类| 亚洲蜜桃精久久久久久久久久久久 | 香蕉视频国产在线观看 | 欧美精品在线视频观看 |