Codeforces 578B. "Or" Game(思维题)
2024-10-03 11:24:26
我们知道所有sigma(2^i){i<n}比2^n小,所以我们肯定是把这k次操作全部丢到一个数上看看能不能凑出二进制下一个更高位的1。
因为k最大只有10,我们可以求出每一个数乘以k次之后的值,然后记录一下前缀或和 后缀或和,枚举每一个数作为被乘数,前缀或当前数或后缀得出答案。
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=;
ll n, k, x;
ll a[maxn], b[maxn], qzh[maxn], hzh[maxn], ans;
void read(ll &k)
{
int f=; k=; char c=getchar();
while(c<'' || c>'') c=='-' && (f=-), c=getchar();
while(c<='' && c>='') k=k*+c-'', c=getchar();
k*=f;
}
int main()
{
read(n); read(k); read(x);
for(int i=;i<=n;i++)
{
read(a[i]); b[i]=a[i];
for(int j=;j<=k;j++) b[i]*=x;
qzh[i]=qzh[i-]|a[i];
}
for(int i=n;i;i--) hzh[i]=hzh[i+]|a[i];
for(int i=;i<=n;i++) ans=max(ans, qzh[i-]|b[i]|hzh[i+]);
printf("%I64d\n", ans);
}
最新文章
- html5 canvas常用api总结(一)
- js获取域名
- LeetCode Rotate List
- 误差曲线(Matlab)
- Myeclipse2016 部署webapp 至 tomcat 上出现 “There are no resources that can be added or removed from the server”
- c语言函数指针的理解与使用
- http知识累积
- GDKOI2015
- webservice和.net remoting浅谈
- Python用subprocess的Popen来调用系统命令
- zoj 3981 Balloon Robot
- springboot---->;javax.servlet.ServletException
- WebAPI获取客户端请求数据
- 只能输入float
- 线性判别分析LDA详解
- WriteableBitmap(三) 扩展
- C++学习笔记--名称空间
- [转]AngularJS+UI Router(1) 多步表单
- c# 怎么获取自己的IP地址
- php 小坑记录