日韩性视频-久久久蜜桃-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)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 成人免费在线播放视频 | 97视频国产| 黄色网页免费在线观看 | 九九影视理伦片 | 色噜噜噜| 欧美成人黄色小视频 | 亚洲国产第一页 | 久久成人福利 | 免费级毛片 | 欧美一级爱爱视频 | 成人区精品一区二区婷婷 | 白浆四溢 | 视频在线观看视频 | 牛牛av国产一区二区 | 欧美少妇一级片 | 亚洲美女一级片 | 日韩欧美一区在线观看 | 亚洲欧美成人一区二区 | 日韩啪啪网站 | 亚洲国产成人久久 | 91尤物视频在线观看 | 未满十八岁勿进 | 亚洲小说网 | 国产激情网址 | 91色在线视频 | 黄色短视频在线观看 | 成人免费性视频 | 日屁网站 | 亚洲大片免费观看 | 国产精品久久久久久久久久久久久久久久 | 欧美婷婷六月丁香综合色 | 中文在线免费视频 | jzzjzz日本丰满成熟少妇 | 日韩簧片 | 国产第八页 | 四虎久久 | 激情视频免费观看 | 国产999视频| 国产精品一区二区不卡 | 狠狠干中文字幕 | 国产又粗又猛又大爽 | 成人爽a毛片一区二区 | 国产一区二三区 | 亚洲精品国产一区二区 | 欧洲亚洲视频 | 日日拍拍 | 总裁边开会边做小娇妻h | 影音先锋激情在线 | 麻豆视频网站入口 | 理论片在线观看理伦片 | 日本理论中文字幕 | 久久精品国产欧美亚洲人人爽 | 亚洲高清视频在线播放 | 三级男人添奶爽爽爽视频 | 免费看日批视频 | 精品在线一区 | 国产精品色图 | 风间由美在线观看 | 男人和女人插插 | 午夜视频福利在线观看 | 极品美妇后花庭翘臀娇吟小说 | 日韩大片一区 | 大尺度做爰呻吟舌吻情头 | 亚洲精品国产精品国自产 | 毛片毛片毛片毛片毛片毛片 | 亚洲av永久无码国产精品久久 | 国产毛片a级 | 日韩伦理一区二区三区 | 深爱五月综合网 | 伊人久久影视 | 国产视频在线观看免费 | 免费看裸体视频网站 | 国产成人久久精品77777综合 | 欧美重口另类 | 中文字幕日韩人妻在线视频 | 欧美日p视频 | 不卡视频在线观看免费 | 少妇被粗大猛进进出出s小说 | 久久一二区 | 婷婷狠狠操 | 久久久久久久久久影院 | 天天干夜夜嗨 | 久久久亚洲成人 | 亚洲一区二区三区久久久 | 国产福利一区在线 | 91黄色免费视频 | 国产精品久久精品三级 | 色综合影视 | 欧美午夜精品理论片a级按摩 | 成人短视频在线播放 | 久久久噜噜噜 | 久久精品小视频 | 欧美国产日韩在线观看成人 | 乱精品一区字幕二区 | 日本中文字幕在线播放 | 欧美精品一区二区在线观看 | 亚洲视频欧美视频 | 影音先锋激情在线 | 美女扒开大腿让男人桶 |