Codeforces Round #320 (Div. 2) 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
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.
题意:给你n个数,可以在任意位置乘以k次x;
求n个数最大的或值;
思路:首先显然尽量将最大的位置放1;所以尽量乘以大的数;
将全部拆分成二进制,复杂度N*60
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define mod 1000000007
#define esp 0.00000000001
const int N=2e5+,M=1e6+,inf=1e9;
ll a[N];
ll flag[N];
ll quickmul(ll x,ll y)
{
ll ans=;
while(y)
{
if(y&)
ans*=x;
x*=x;
y>>=;
}
return ans;
}
void update(ll x,ll gg)
{
int ji=;
while(x)
{
flag[ji++]+=(gg)*(x%);
x>>=;
}
}
ll getans()
{
ll base=,sum=;
for(int i=;i<=;i++)
{
if(flag[i])
sum+=base;
base*=;
}
return sum;
}
int main()
{
ll x,y,z,i,t;
scanf("%I64d%I64d%I64d",&x,&y,&z);
ll mul=quickmul(z,y);
for(i=;i<x;i++)
scanf("%I64d",&a[i]),update(a[i],);
ll ans=;
for(i=;i<x;i++)
{
update(a[i],-);
update(a[i]*mul,);
ans=max(ans,getans());
update(a[i]*mul,-);
update(a[i],);
}
printf("%I64d\n",ans);
return ;
}
;
Codeforces Round #320 (Div. 2) D. "Or" Game 数学的更多相关文章
- 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)
1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria ...
- 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) C. A Problem about Polyline(数学) D. "Or" Game(暴力,数学)
解题思路:就是求数 n 对应的二进制数中有多少个 1 #include <iostream> #include<cstdio> using namespace std; int ...
- codeforces 578a//A Problem about Polyline// Codeforces Round #320 (Div. 1)
题意:一个等腰直角三角形一样的周期函数(只有x+轴),经过给定的点(a,b),并且半周期为X,使X尽量大,问X最大为多少? 如果a=b,结果就为b 如果a<b无解. 否则,b/(2*k*x-a) ...
- codeforces 578c//Weakness and Poorness// Codeforces Round #320 (Div. 1)
题意:一个数组arr,一个数字x,要使arr-x的最大子段最小,问该最小值. 三分x,复杂度logn,内层是最大子段的模板,只能用n复杂度的.因为是绝对值最大,正负各求一次,取大的.精度卡得不得了,要 ...
- codeforces 578b//"Or" Game// Codeforces Round #320 (Div. 1)
题意:n个数字,最多操作k次,每次乘x,要使结果数组的与值最大. 能推断出结果是对一个元素操作k次,并且这个元素的二进制最高位比较大.并不一定是取最大的,比如1100和1010,乘以一次2,两种选法分 ...
随机推荐
- 重定向 vs output redirect
http://asawicki.info/files/visual_cpp_redirect.png http://asawicki.info/news_1496_redirecting_output ...
- (链接保存)CentOS 6.6下yum快速升级内核
(因Docker建议3.8以上kernel版本)这个方法升级很方便,保存链接备用: http://www.dadclab.com/archives/5340.jiecao Docker Engine安 ...
- eclipse下使用API操作HDFS
1)使用eclipse,在HDFS上创建新目录 import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Fil ...
- 学生信息管理 --- c语言实现
第一次写比较大的程序,昨晚看了 大话数据结构 有感-----同样求 1+2+3+4+...+100,我则是简单的从1+2+3+4+...+100. 而不是 (1+100) / 2 * 100;(高 ...
- HDU 1028 Ignatius and the Princess III (递归,dp)
以下引用部分全都来自:http://blog.csdn.net/ice_crazy/article/details/7478802 Ice—Crazy的专栏 分析: HDU 1028 摘: 本题的意 ...
- LCA(最近公共祖先)离线算法Tarjan+并查集
本文来自:http://www.cnblogs.com/Findxiaoxun/p/3428516.html 写得很好,一看就懂了. 在这里就复制了一份. LCA问题: 给出一棵有根树T,对于任意两个 ...
- POJ 2182
#include <iostream> #define MAXN 8005 using namespace std; int _m[MAXN]; int main() { //freope ...
- Python异步IO --- 轻松管理10k+并发连接
前言 异步操作在计算机软硬件体系中是一个普遍概念,根源在于参与协作的各实体处理速度上有明显差异.软件开发中遇到的多数情况是CPU与IO的速度不匹配,所以异步IO存在于各种编程框架中,客户端比如浏览 ...
- zoj 3591 Nim 博弈论
思路:先生成序列再求异或,最多的可能为n*(n+1)/2: 在去掉其中必败的序列,也就是a[i]=a[j]之间的序列. 代码如下: #include<iostream> #include& ...
- 机器学习之逻辑回归(Logistic Regression)
1. Classification 这篇文章我们来讨论分类问题(classification problems),也就是说你想预测的变量 y 是一个离散的值.我们会使用逻辑回归算法来解决分类问题. 之 ...