codeforces 579D D. "Or" Game(前后缀+贪心)
题目链接:
2 seconds
256 megabytes
standard input
standard output
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 题意: 给一列数,任选一个数,乘x,最多操作k次,问最后a[1]|a[2]|...|a[n]的最大值是多少; 思路: 或运算是0|0=0,1|0=1,0|1=1,1|1=1,那么每次乘一个大于等于2的数就能使最高位数增加,那么肯定是把k个x都乘在一个数上才能最大,把a[1]|...|a[n]的前后缀都找出来,暴力枚举要找的那个数,得到最大值就好了,我以前连这么水的题都不会,想想好伤心; AC代码:
//#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio> using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e9+;
const double PI=acos(-1.0);
const LL inf=1e14;
const int N=2e5+; int n,k,x;
LL a[N],pre[N],nex[N],temp;
LL solve(int x)
{
LL ans=a[x]*temp;
return ans|pre[x-]|nex[x+];
} int main()
{
read(n);read(k);read(x);
Riep(n)read(a[i]),pre[i]=(pre[i-]|a[i]);
for(int i=n;i>;i--)
{
nex[i]=(nex[i+]|a[i]);
}
temp=;
while(k--)temp=temp*x;
LL ans=;
for(int i=;i<=n;i++)
ans=max(ans,solve(i));
cout<<ans<<"\n";
return ;
}
codeforces 579D D. "Or" Game(前后缀+贪心)的更多相关文章
- Codeforces Round #545 (Div. 2)D(KMP,最长公共前后缀,贪心)
#include<bits/stdc++.h>using namespace std;const int N=1000007;char s1[N],s2[N];int len1,len2; ...
- Codeforces 587D - Duff in Mafia(2-SAT+前后缀优化建图)
Codeforces 题面传送门 & 洛谷题面传送门 2-SAT hot tea. 首先一眼二分答案,我们二分答案 \(mid\),那么问题转化为,是否存在一个所有边权都 \(\le mid\ ...
- Codeforces 855B:Marvolo Gaunt's Ring(枚举,前后缀)
B. Marvolo Gaunt's Ring Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaun ...
- Codeforces Round #609 (Div. 2)前五题题解
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
- Objective-C 【NSString-字符串比较&前后缀检查及搜索】
———————————————————————————————————————————NSString 字符串比较 #import <Foundation/Foundation.h> vo ...
- poj 2752 Seek the Name, Seek the Fame【KMP算法分析记录】【求前后缀相同的子串的长度】
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14106 Ac ...
- [LeetCode] Prefix and Suffix Search 前后缀搜索
Given many words, words[i] has weight i. Design a class WordFilter that supports one function, WordF ...
- Hibernate给表和字段设置前后缀及分隔符
在<一口一口吃掉Hibernate(一)--使用SchemaExport生成数据表>中介绍了如何生成数据表.但是这只是最基本的.hibernate在生成或者操作数据库时,会受一些限制.比如 ...
- HDU 2594(求最长公共前后缀 kmp)
题意是在所给的两个字符串中找最长的公共前后缀,即第一个字符串前缀和第二个字符串后缀的最长相等串. 思路是将两个字符串拼接在一起,然后直接套用 kmp 算法即可. 要注意用 next 会报编译错误,改成 ...
随机推荐
- SQL Server中行列转换
典型实例 一.行转列 1.建立表格 ifobject_id('tb')isnotnulldroptabletb go createtabletb(姓名varchar(10),课程varchar(10) ...
- Oracle中TO_DATE格式
转自:http://www.cnblogs.com/ajian/archive/2009/03/25/1421063.html TO_DATE格式(以时间:2007-11-02 13:45:25为 ...
- erlang: Programming Rules and Conventions。
http://www.erlang.se/doc/programming_rules.shtml#HDR33 http://www.erlang.org/eeps/eep-0008.html
- OSGI(面向Java的动态模型系统)
基本简介编辑 OSGI服务平台提供在多种网络设备上无需重启的动态改变构造的功能.为了最小化耦合度和促使这些耦合度可管理,OSGi技术提供一种面向服务的架构,它能使这些组件动态地发现对方.OSGi联 O ...
- Js 基本数据类型、引用数据类型
数据类型 1. ECMAScript变量包含两种不同类型的值:基本类型值.引用类型值: 2. 基本类型值:指的是保存在栈内存中的简单数据段: 3. 引用类型值:指的是那些保存在堆内存中的对 ...
- DAG成员服务器还原
DAG成员服务器 exmb02 已损坏: 1.使用 Get-MailboxDatabase cmdlet 为要恢复的服务器上的任何邮箱数据库副本检索所有重播延迟和截断延迟设置: Get-Mailb ...
- influxdb Measurements
第一次看influxdb的代码实例时不明白influxdb Measurements是什么意思.经过研究总结一下. 1)measurement,相当于关系数据库中的table,包含tag,field, ...
- SQL 32位还原位64位出现3154错误
1:首先检查新建数据库的路径是否正确. 2:勾选覆盖原有数据库. 3:新建查询,选择master.然后新建查询中进行如下直接对bak文件的操作. RESTORE DATABASE TestFROM D ...
- GLSL-几何着色器详解跟实例(GS:Geometry Shader)[转]
[OpenGL4.0]GLSL-几何着色器详解和实例(GS:Geometry Shader) 一.什么是几何着色器(GS:Geometry Shader) Input Assembler(IA)从顶点 ...
- iOS开发——测试篇&breakpoints、lldb 和 chisel 的详解
breakpoints.lldb 和 chisel 的详解 Breakpoints BreakPoint分类 breakpoint也是有分类的,我这里的文章内大致按使用的方式分为了 Normal Br ...