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).满足条件的 ...
随机推荐
- vim跳转到文件的指定偏移位置
:goto 偏移量 例如:偏移到文件的第100个字节处 :goto 100
- js基础(补10.10)
1.内嵌式: <html> <head> <title></title> </head> <body> <a href=& ...
- Ubuntu 16 Mysql 安装配置
安装Mysql apt-get update; apt-get install mysql-server apt-get install mysql-client //安装过程中会提示修改密码 ...
- Software - (转)Winform 程序捕获全局异常
static class Program { /// <summary> /// 应用程序的主入口点. /// </summary> [STAThread] static vo ...
- 剑指Offer的学习笔记(C#篇)-- 二维数组中的查找
题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数 ...
- fatal pylint error : ......can't find '__main__'module in
fatal pylint error : ......can't find '__main__'module in原因是没有安装pylint,所以提示没有找到__main__模块 解决方案:1.到官网 ...
- Codeforces Round #564 (Div. 2) C. Nauuo and Cards
链接:https://codeforces.com/contest/1173/problem/C 题意: Nauuo is a girl who loves playing cards. One da ...
- 063 Unique Paths II 不同路径 II
这是“不同路径” 的进阶问题:现在考虑网格中有障碍物.那样将会有多少条不同的路径从左上角到右下角?网格中的障碍物和空位置分别用 1 和 0 来表示.例如,如下所示在 3x3 的网格中有一个障碍物.[ ...
- DevExpress GridControl 控件二表连动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- document.getElementById(...) is null
<html> <head> <script type="text/javascript"> document.getElementById('b ...