Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B "Or" Game (贪心)
首先应该保证二进制最高位尽量高,而位数最高的数乘x以后位数任然是最高的,所以一定一个数是连续k次乘x。
当出现多个最高位的相同的数就枚举一下,先预处理一下前缀后缀即可。
#include<bits/stdc++.h>
using namespace std; const int maxn = 2e5+;
int a[maxn];
int pf[maxn],sf[maxn]; int main()
{
int n,k,x; scanf("%d%d%d",&n,&k,&x);
for(int i = ; i <= n; i++){
scanf("%d",a+i);
pf[i] = pf[i-]|a[i];
}
for(int i = n; i >= ; i--){
sf[i] = sf[i+]|a[i];
}
long long ans = pf[n];
for(int i = ; i <= n; i++){
long long t = a[i];
int ct = k; while(ct--) t *= x;
ans = max(ans,t|pf[i-]|sf[i+]);
}
printf("%I64d",ans);
return ;
}
Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B "Or" Game (贪心)的更多相关文章
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C. Weakness and Poorness 三分 dp
C. Weakness and Poorness Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心
B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578 ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game
题目链接:http://codeforces.com/contest/578/problem/B 题目大意:现在有n个数,你可以对其进行k此操作,每次操作可以选择其中的任意一个数对其进行乘以x的操作. ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E. Weakness and Poorness 三分
E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】
A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D 数学+(前缀 后缀 预处理)
D. "Or" Game time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E 三分+连续子序列的和的绝对值的最大值
E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness (三分)
显然f(x)是个凹函数,三分即可,计算方案的时候dp一下.eps取大了会挂精度,指定循环次数才是正解. #include<bits/stdc++.h> using namespace st ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline(数学)
题目中给出的函数具有周期性,总可以移动到第一个周期内,当然,a<b则无解. 假设移动后在上升的那段,则有a-2*x*n=b,注意限制条件x≥b,n是整数,则n≤(a-b)/(2*b).满足条件的 ...
随机推荐
- CodeForces - 505B Mr. Kitayuta's Colorful Graph 二维并查集
Mr. Kitayuta's Colorful Graph Mr. Kitayuta has just bought an undirected graph consisting of n verti ...
- iOS三方支付--微信支付/支付宝支付
一.微信支付 1.注册账号并申请app支付功能 公司需要到微信开放品台进行申请app支付功能 , 获得appid和微信支付商户号(mch_id)和API秘钥(key) . Appsecret(secr ...
- HTML5学习笔记(四)语义元素
语义元素能够清楚的描述其意义给浏览器和开发者. 无语义 元素实例: <div> 和 <span> - 无需考虑内容. 语义元素实例: <form>, <tab ...
- 特性attribute,声明和使用attribute,应用attribute,AOP面向切面,多种方式实现AOP
1 特性attribute,和注释有什么区别2 声明和使用attribute3 应用attribute4 AOP面向切面5 多种方式实现AOP ---------------------------- ...
- 实现简易版shell
操作系统小组作业,实现一个简易shell,shell实现了下列命令 exit------退出终端命令 clr-------清屏命令 time-----时间命令 myshell----欢迎命令 quit ...
- [openjudge] 1455:An Easy Problem 贪心
描述As we known, data stored in the computers is in binary form. The problem we discuss now is about t ...
- ue4 1官网编程指南总结
https://docs.unrealengine.com/latest/CHN/index.html 中编程指南 快速入门 actor生命周期 FloatingActor.h #pragma onc ...
- 【NOIP模拟赛】密码锁
题目描述 hzwer有一把密码锁,由N个开关组成.一开始的时候,所有开关都是关上的.当且仅当开关x1,x2,x3,…xk为开,其他开关为关时,密码锁才会打开. 他可以进行M种的操作,每种操作有一个si ...
- python 之 列表生成式、生成器表达式、模块导入
5.16 列表生成式 l=[]for i in range(100): l.append('egg%s' %i)print(l)l=['egg%s' %i for i in range(100 ...
- Mac下IDEA不能进行编辑
在安装Idea时,在选择插件的时候,把IDEAVim这个玩意儿选上了. 所以,编辑模式就跟命令行里面的Vim一样.输入时,需要先输入i, 进入insert模式下,然后才可以编辑. 彻底解决办法就是进入 ...