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).满足条件的 ...
随机推荐
- HeapCreate
为进程创建新堆,请求分配虚拟内存分页,函数原型如下: HANDLE HeapCreate( DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximu ...
- HDU - 6383 百度之星2018初赛B 1004 p1m2(二分答案)
p1m2 Accepts: 1003 Submissions: 4595 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072 ...
- std::function"函数"对象包装器
语义: 类模板std::function是可调用对象的包装器,可以包装除了类成员之外的所有可调用对象.包括,普通函数,函数指针,lambda,仿函数.通过指定的模板参数,它可以用统一的方式保存,并延迟 ...
- Bootstrap 栅栏布局中 col-xs-*、col-sm-*、col-md-*、col-lg-* 区别及使用方法
(1)概括 一句话概括:根据显示屏幕宽度的大小,自动的选用对应的类的样式. (2)关键字段 1.col是column简写:列: 2.xs是maxsmall简写:超小, ...
- Luogu P1558 色板游戏【线段树/状态压缩】By cellur925
题目传送门 今天非常想再看一遍霸王别姬想不进去题于是开始刷数据结构 注意到至多只有\(30\)种颜色,啊啊啊啊我一开始竟然想的不是状态压缩而是在线段树中存一个30大小的数组,这样每次更新的时候暴力循环 ...
- 一站式解决方案:springboot
优点: ·轻松创建独立的spring应用 ·内嵌tomcat.jetty等web容器,不需要部署war文件 ·提供一系列的“starter”来简化maven配置 ·开箱即用,尽可能自动配置spring
- 00 | Two Sum
Question Given an array of integers, return indices of the two numbers such that they add up to a sp ...
- jquery jtemplates.js模板渲染引擎的详细用法第三篇
jquery jtemplates.js模板渲染引擎的详细用法第三篇 <span style="font-family:Microsoft YaHei;font-size:14px;& ...
- c# Array或List有个很实用的ForEach方法,可以直接传入一个方法对集合中元素操作
using System; using System.Collections.Generic; namespace demo { class Program { static void Main(st ...
- beanshell解析json(从简单到复杂)
使用beanshell 解析单层Json: Json 数据如下: { "status":200, "code": 0, "message": ...