zoukankan      html  css  js  c++  java
  • CF div2 320 D

    D. "Or" Game
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    Input

    The first line contains three integers nk 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

    Output the maximum value of a bitwise OR of sequence elements after performing operations.

    Sample test(s)
    input
    3 1 2
    1 1 1
    output
    3
    input
    4 2 3
    1 2 4 8
    output
    79
    Note

    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.

     题目意思是求一组数的或值最大,其中的元素可以乘k次x 问最大值是多少。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <queue>
     5 #include <vector>
     6 #include <stack>
     7 
     8 using namespace std;
     9 
    10 const int M = 10005;
    11 const int maxn = 5000000;
    12 typedef long long ll;
    13 
    14 vector<int>G[maxn];
    15 queue<int>Q;
    16 stack<int>st;
    17 
    18 
    19 long long a[maxn];
    20 long long suml[maxn];
    21 long long sumr[maxn];
    22 
    23 int main()
    24 {
    25    int n,k,x;
    26    scanf("%d%d%d",&n,&k,&x);
    27    int t = 1;
    28    while(k--){
    29     t *= x;
    30    }
    31    for(int i=1;i<=n;i++){
    32     scanf("%lld",&a[i]);
    33 
    34    }
    35    //suml[1] = a[1];
    36    for(int i=1;i<=n;i++){
    37     suml[i] = suml[i-1]|a[i];
    38    }
    39    //sumr[n] = a[n];
    40    for(int i=n;i>0;i--){
    41     sumr[i] = sumr[i+1]|a[i];
    42    }
    43    long long ans = 0;
    44    for(int i=1;i<=n;i++){
    45     ans = max(ans,suml[i-1]|(a[i]*t)|sumr[i+1]);
    46    }
    47    printf("%lld
    ",ans);
    48 
    49     return 0;
    50 }
    View Code
  • 相关阅读:
    Redis 锁
    Redis 持久化
    Redis 数据淘汰策略
    Redis 事务命令
    【vue禁止复制粘贴】
    tsconfig.json无法写入webpack.config.js 因为它会覆盖输入文件。
    npm 进阶命令知多少(一)
    如何将360度评估调查应用于员工发展?
    如何利用360度评估做好民主评议促进干部管理与选拔?
    手把手带你使用360度评估系统实施绩效反馈全流程(附详细图文)
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4818013.html
Copyright © 2011-2022 走看看