CF336C-Vasily|CF336C-Vasily the Bear and Sequence题解--贪心

题目链接
https://www.luogu.org/problemnew/show/CF336C
分析
一个比较妙的贪心
我们要让最后\(and\)起来的数被\(2^k\)整除且\(k\)最大,我们不妨从后往前枚举\(k\),同时运用贪心的思路,对于二进制第\(k\)为1的数,我们想让最后得到的数除第\(k\)位外都为0,当然是\(and\)越多越好
代码

#include #include #include #include #include #include #include #define ll long long #define ri register int using std::min; using std::max; template inline void read(T &x){ x=0; int ne=0; char c; while(!isdigit(c=getchar()))ne=c=='-'; x=c-48; while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48; x=ne?-x:x; return ; } const int maxn=100005; const int inf=0x7fffffff; int a[maxn],n,q[maxn]; int main(){ int x,y,z; int ans=0; read(n); for(ri i=1; i<=n; i++){ read(a[i]); } for(ri k=30; k>=0; k--){ x=(1<

【CF336C-Vasily|CF336C-Vasily the Bear and Sequence题解--贪心】转载于:https://www.cnblogs.com/Rye-Catcher/p/9627572.html

    推荐阅读