题意:n个数字,最多操作k次,每次乘x,要使结果数组的与值最大。

能推断出结果是对一个元素操作k次,并且这个元素的二进制最高位比较大。并不一定是取最大的,比如1100和1010,乘以一次2,两种选法分别为11000|1010=11010,;;;1100|10100=11100后者更大。

有没有可能k次乘在不同的数字上呢?不可能。如果有3个数字abc二进制最高位都是第5位,k=3,x=2,假如乘了一次a,再乘两次a,与的结果是8位。如果放弃a,去乘别的,只有7位以下。

实现过程中,用一个数组arr记录每个位的出现数。比如9是1001,那么++arr[0],++arr[3]。对当前元素,减掉它的贡献,加上乘法操作后的贡献,然后与起来看是不是更大,最后输出最大的。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <iomanip>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
const double EPS=1e-;
typedef long long lon; int arr[];
lon num=; int main()
{
std::ios::sync_with_stdio();
lon maxv=,maxid=;
//freopen("d:\\1.txt","r",stdin);
//for(;scanf("%d",&n)!=EOF;)
{
lon n,k,x;
cin>>n>>k>>x;
vector<lon> vct;
for(int i=;i<n;++i)
{
lon tmp;
cin>>tmp;
vct.push_back(tmp);
}
for(int i=;i<n;++i)
{
lon cur=vct[i];
for(int j=;(num<<j)<=cur;++j)
{
if(cur&(num<<j))
{
++arr[j];
}
}
}
for(int i=;i<n;++i)
{
lon cur=vct[i];
lon res=;
for(int j=;(num<<j)<=cur;++j)
{
if(cur&(num<<j))
{
--arr[j];
}
}
for(int j=;j<;++j)
{
if(arr[j])
{
res|=(num<<j);
}
} lon a=cur;
for(int j=;j<k;++j)
{
a*=x;
} res|=a;
//cout<<res<<endl;
if(res>maxv)
{
maxv=res;
maxid=i;
} for(int j=;(num<<j)<=cur;++j)
{
if(cur&(num<<j))
{
++arr[j];
}
}
} lon res=;
for(int i=;i<n;++i)
{
if(i!=maxid)
{
res|=vct[i];
}
else
{
res|=maxv;
}
}
cout<<res<<endl;
}
return ;
}

codeforces 578b//"Or" Game// Codeforces Round #320 (Div. 1)的更多相关文章

  1. [Codeforces] Round #320 (Div.2)

    1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game

    题目链接:http://codeforces.com/contest/578/problem/B 题目大意:现在有n个数,你可以对其进行k此操作,每次操作可以选择其中的任意一个数对其进行乘以x的操作. ...

  5. codeforces Round #320 (Div. 2) C. A Problem about Polyline(数学) D. "Or" Game(暴力,数学)

    解题思路:就是求数 n 对应的二进制数中有多少个 1 #include <iostream> #include<cstdio> using namespace std; int ...

  6. Codeforces Round #320 (Div. 2) D. "Or" Game 数学

    D. "Or" Game time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. 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) ...

  8. codeforces 578c//Weakness and Poorness// Codeforces Round #320 (Div. 1)

    题意:一个数组arr,一个数字x,要使arr-x的最大子段最小,问该最小值. 三分x,复杂度logn,内层是最大子段的模板,只能用n复杂度的.因为是绝对值最大,正负各求一次,取大的.精度卡得不得了,要 ...

  9. 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 ...

随机推荐

  1. ios 透过上层视图点击相应下方视图的点击事件

    - (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{ UIView *hitView = [super hitTest:point ...

  2. Linux基础命令---bzmore

    bzmore 将bzip压缩过的文件解压到标准输出,同时也可以将普通文件显示到标准输出.该指令可以实现分屏显示,并且不会删除压缩包.bzmore是一个过滤器,它允许在软拷贝终端上一次检查压缩或纯文本文 ...

  3. Linux服务器---关闭selinux

    关闭selinux 1.通过命令“getenforce”获取selinux状态, [root@localhost ~]# getenforce Enforcing        //enforcein ...

  4. Django框架----视图函数补充

    视图函数的补充 1.视图函数:一定是要包含两个对象的(render源码里面有HttpResponse对象)   request对象:----->所有的请求信息   HttpResponse:-- ...

  5. 9大行为导致Java程序员薪资过低, 你有几个?

    Java程序员薪水有高有低,有的人一个月可能拿30K.50K,有的人可能只有2K.3K.同样有五年工作经验的Java程序员,可能一个人每月拿20K,一个拿5K.是什么因素导致了这种差异?本文整理导致J ...

  6. Contiki源码+原理+功能+编程+移植+驱动+网络(转)

    源:Contiki源码+原理+功能+编程+移植+驱动+网络 请链接:http://www.rimelink.com/nd.jsp? id=31&_np=105_315 假设您对于用Contik ...

  7. Sybase 存储过程中IF的用法

    Sybase 存储过程中IF的用法 --@i_val 为参数 or @i_val is null then begin --执行内容 end; end if;

  8. mysql主备部署[高可用]

    配置方案 master:192.168.99.61 service-id:61 slave:192.168.99.62 service-id:62同步账号:sync   同步密码:sync 主:192 ...

  9. js验证两次输入的密码是否一致

    原文链接:http://blog.csdn.net/DDfanL/article/details/51460324

  10. QT中VideoProbe的简介和实现

    一.遇到问题        在Android机上使用QT进行图像处理程序设计的时候,遇到的一个比较明显的问题就是图片采集的问题----摄像头获得是实时的视频,如果我们想从中动态地截获图片,并且转换成M ...