Codeforces 988 D. Points and Powers of Two(数学+结论)

Shanon ·
更新时间:2024-09-20
· 764 次阅读

codeforces每日一题。
题意:
给出一个数组,让你挑选出能组成任意pair差值为2的幂的序列,并且使这个序列长度尽可能大。

思路:

针对于挑选出来的序列,任意pair对的差值为2的幂数。 假设有多个pair对,设dis(a,b)=2的x次幂,dis(a,c)等于2的y次幂,即有dis(a,c)=dis(a,b)+dis(b,c)=2的x次幂+2的y次幂,很明显若是dis(a,c)为2的幂数,那么x==y,可得每对pair的dis是相等的。 那么对于第四对pair,dis(a,d)=3*dis(a,b),很明显不符合条件。 所以这道题的目的就是在数组里寻找是否有长度为3的序列满足题意,如果没有再考虑2,再考虑1 。

代码如下:

#include #define ll long long #define inf 0x3f3f3f3f #define mod 1000000007 #define PI acos(-1) #define fi first #define se second #define lowbit(x) (x&(-x)) #define mp make_pair #define pb push_back #define ins insert #define si size() #define E exp(1.0) #define fixed cout.setf(ios::fixed) #define fixeds(x) setprecision(x) #pragma GCC optimize(2) using namespace std; inline ll read(){ll s=0,w=1;char ch=getchar(); while(ch'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch>= 1;}return ans%p;}ll Inv(ll x,ll p){return qp(x,p-2,p);} ll Cal(ll n,ll m,ll p){if (m>n) return 0;ll ans = 1;for(int i = 1; i <= m; ++i) ans=ans*Inv(i,p)%p*(n-i+1)%p;return ans%p;} const int manx=2e5+5; ll lg[manx],a[manx];; sets; vectorans; int main(){ ll n=read(),flag=0; for(int i=1;i<=n;i++){ ll x=a[i]=read(); s.ins(x); } lg[0]=1; for(int i=1;i<=32;i++) lg[i]=lg[i-1]*2; for(int i=1;i<=n;i++){ for(int j=0;j0){ cout<<ans.si<<endl; for(auto v: ans) cout<<v<<" "; } else cout<<1<<endl<<a[1]; return 0; }
作者:别对自己失望



CodeForces AND 数学

需要 登录 后方可回复, 如果你还没有账号请 注册新账号