Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D "Or" Game 枚举+前缀后缀
2 seconds
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make
as large as possible, where
denotes the bitwise OR.
Find the maximum possible value of
after performing at most k operations optimally.
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output the maximum value of a bitwise OR of sequence elements after performing operations.
3 1 2
1 1 1
3
4 2 3
1 2 4 8
79
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is
.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result.
题解:肯定是全部乘在一个数上
用前缀后缀枚举就好
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
#define maxn 201000
__int64 a = , b , c , d[maxn*] , L[maxn*] , R[maxn*], k , x , n; int main()
{
cin >> n >> k >> x; for(int i = ; i <= n ; i++)
cin >> d[i] , L[i] = L[i-]|d[i]; for(int i = ; i <= k ; i++)
a *= x; for(int i = n ; i >= ; i--)
R[i] = R[i+]|d[i]; for(int i = ; i <= n ; i++)
b = max(b , (L[i-]|R[i+]|((__int64)a*d[i]))); cout << b << endl; return ;
}
代码
Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D "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] B "Or" Game (贪心)
首先应该保证二进制最高位尽量高,而位数最高的数乘x以后位数任然是最高的,所以一定一个数是连续k次乘x. 当出现多个最高位的相同的数就枚举一下,先预处理一下前缀后缀即可. #include<bit ...
- 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).满足条件的 ...
随机推荐
- 面试之JVM
目录 Java虚拟机 类的加载方式 Java内存模型 程序计数器(PC) Java虚拟机栈(Stack) 本地方法栈 元空间(MetaSpace) Java堆(Heap) 内存分配策略 垃圾回收(GC ...
- Memcache 分布式存储 【一致性Hash】crc32
class memcacheHash { private $_node = array(); private $_nodeData = array(); private $_keyNode = 0; ...
- Python之trutle库-五角星
Python之trutle库-五角星 #!/usr/bin/env python # coding: utf-8 # Python turtle库官方文档:https://docs.python.or ...
- (十一)python3 encode()和decode()
从英文意思上看,encode和decode分别指编码和解码.在python中,Unicode类型是作为编码的基础类型,即: decode encode str ---------> str(Un ...
- c# TcpClient简易聊天工具
说明: TcpClient 链接是一个比较安全稳定的链接,作为聊天或者是数据稳定传输,是比较合适的,下面的代码测试过,如果你吧他放在公网服务器上,也是可以用的 using System; using ...
- Leetcode 207.课程表
课程表 现在你总共有 n 门课需要选,记为 0 到 n-1. 在选修某些课程之前需要一些先修课程. 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] 给定课程总 ...
- POJ 1191 DP+DFS棋盘分割问题
题目大意: Description 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形 ...
- noip模拟赛 收集果子
分析:显然的,树形dp,状态也很好想到:f[i][j]表示以i为根的子树收集到j个果子的方案数.转移的话就相当于是背包问题,每个子节点可以选或不选.如果不选子节点k的话,那么以k为根的子树的边无论断不 ...
- ZOJ 2770_Burn the Linked Camp
题意: 给定每个兵营的最大容量,以及第i到第j个兵营至少有多少个士兵,问所有兵营一共至少有多少个士兵? 分析: 差分约束系统,注意 第i到第j至少有k个 第i到第j最多有最大容量之和个 每个兵营至少有 ...
- JDBC的结果集
以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/result-sets.html: SQL语句从数据库查询中获取数据,并将数据返回到结果集中.SELEC ...