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,两种选法分 ...
随机推荐
- Least Common Ancestors 分类: ACM TYPE 2014-10-19 11:24 84人阅读 评论(0) 收藏
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- AngularJs学习笔记--html compiler
原文再续,书接上回...依旧参考http://code.angularjs.org/1.0.2/docs/guide/compiler 一.总括 Angular的HTML compiler允许开发者自 ...
- javascript和“主流大型语言”(c# JAVA C++等)的差异
1.javascript不支持overload,因为它的函数参数是以数组方式来实现的,没有固定的参数签名,所以无法重载. 2.javascript的基本类型只有5个:number string boo ...
- 几种CPU架构
原文链接:http://blog.csdn.net/wyzxg/article/details/5027738 这几天在下载RPM包的时候,总会看见x86,x86-64,IA64,i386,i586等 ...
- pku 1703(种类并查集)
题目链接:http://poj.org/problem?id=1703 思路;个人觉得本质上还是和带权并查集一样的,只不过多了一个MOD操作,然后就是向量关系图稍微改动一下就变成种类并查集了,对于本题 ...
- 01 - 开发成功的Oracle应用
笔记 1. 开发数据库应用,不能把数据库当黑盒.需要了解数据库的一下内容 数据库的体系结构 并发控制 开发的时候就要调优你的代码 数据库有哪些特性,不要在你的代码里重复实现 深入的学习SQL 2. 我 ...
- Linux下Boost交叉编译
http://davidlwq.iteye.com/blog/1580752 运行环境:ubuntu 12.04, boost 1.50.0 由于要把boost移植到arm板上去,所以折腾了一下,后来 ...
- JavaWeb项目开发案例精粹-第6章报价管理系统-06po层
1. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www ...
- iOS sqlite3数据库解析
看来从版本3.3.1基本上已经支持线程句柄的传递功能.具体限制我标记了一下.(6) Is SQLite threadsafe?SQLite is threadsafe. We make this co ...
- JAVA字符串格式化String.format()的使用
JAVA字符串格式化-String.format()的使用常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprin ...