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,两种选法分 ...
随机推荐
- Winform DataGridView扩展
public class ObjectPropertyCompare<T> : IComparer<T> { private readonly PropertyDescript ...
- 【bzoj1085】[SCOI2005]骑士精神
1085: [SCOI2005]骑士精神 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1757 Solved: 961[Submit][Statu ...
- razor GPU
抓之前要把设置里面 Setting -Debug Setting -Graphic -PA DEBUG yes -RAZOR GPU yes replay是个很有用的功能,要设置 -Debug Set ...
- win8 获取管理员权限
Win8 下动不动 就弹出要管理员权限什么....... 网上找到很多方法. 什么注册表什么..... 不行.. 以下这个方法可行. 按WIN+R,运行对话框中输入gpedit.msc,开启 ...
- “System.Data.Entity.Internal.AppConfig"的类型初始值设定项引发异常。{转}
<connectionStrings> <add name="ConnectionStringName" providerName="System.Da ...
- Javascript引擎单线程机制及setTimeout执行原理说明
setTimeout用法在实际项目中还是会时常遇到.比如浏览器会聪明的等到一个函数堆栈结束后才改变DOM,如果再这个函数堆栈中把页面背景先从白色设为红色,再设回白色,那么浏览器会认为DOM没有发生任何 ...
- 真机模拟器.a文件编译报错
- POJ 1419
#include <iostream> #define MAXN 105 #define max _max using namespace std; int j; bool _m[MAXN ...
- [转]fedora启动telnet服务
http://blog.chinaunix.net/uid-22996709-id-3056078.html 在win7上安装了SecurityCRT,登录VMWARE Fedora时候登录超时,检查 ...
- API 版本控制
http://www.oschina.net/translate/introduction-to-web-api-versioning