• codeforces 1365 E 鸽巢+思维


    n为500

    题意:在数组a中挑出k个数,组成新的数组,将新的数组中的每个数,化成二进制,若第i位上数字是1的元素数量大于等于max(1,k-2),那么该位计算出2^i参与求和,求选出的新数组对应的最大和。

    思路:当n<=3时,只要i位置存在i为1即可。

         当n>3的时候,假如选4个数

    1100

    0110

    0011

    1001

      在三个数上新加的一个数,如果想对结果不产生不利影响,则需要原有3个在这个位置上为1,且第四个也在这个位置有1.这样的话,加进来的这个数,不会产生价值,只存在原值不变和原值减小。

    所以n小于3则k为n,n大于等于3则k为3.

    ans实际即为a[i] | a[j] | a[k]

      n为500直接枚举即可。

    #include <iostream>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <map>
    #include <iomanip>
    #include <algorithm>
    #include <queue>
    #include <stack>
    #include <set>
    #include <vector> 
    // #include <bits/stdc++.h>
    #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define sp ' '
    #define endl '
    '
    #define inf  0x3f3f3f3f;
    #define FOR(i,a,b) for( int i = a;i <= b;++i)
    #define bug cout<<"--------------"<<endl
    #define P pair<int, int>
    #define fi first
    #define se second
    #define pb(x) push_back(x)
    #define ppb() pop_back()
    #define mp(a,b) make_pair(a,b)
    #define ms(v,x) memset(v,x,sizeof(v))
    #define rep(i,a,b) for(int i=a;i<=b;i++)
    #define repd(i,a,b) for(int i=a;i>=b;i--)
    #define sca3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
    #define sca2(a,b) scanf("%d %d",&(a),&(b))
    #define sca(a) scanf("%d",&(a));
    #define sca3ll(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
    #define sca2ll(a,b) scanf("%lld %lld",&(a),&(b))
    #define scall(a) scanf("%lld",&(a));
    
    
    using namespace std;
    typedef long long ll;
    ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
    ll powmod(ll a, ll b, ll mod){ll sum = 1;while (b) {if (b & 1) {sum = (sum * a) % mod;b--;}b /= 2;a = a * a % mod;}return sum;}
    
    const double Pi = acos(-1.0);
    const double epsilon = Pi/180.0;
    const int maxn = 2e5+10;
    
    ll a[510];
    
    int main()
    {
        int n;
        cin>>n;
        rep(i,1,n){
            cin>>a[i];
        }
        ll ans = -1;
        rep(i,1,n){
            ans = max(ans,a[i]);
            rep(j,i+1,n){
                ans = max(ans,a[i]|a[j]);
                rep(k,j+1,n){
                    ans = max(ans,a[i]|a[j]|a[k]);
                }
            }
        }
        cout<<ans<<endl;
    }

        

  • 相关阅读:
    Spring Boot Admin 添加报警提醒和登录验证功能!
    安卓平板体验Java开发,还能白嫖一年阿里无影云,真香!
    Java中停止线程的3种方式
    Nacos中服务删除不了,怎么办?
    面试突击30:线程池是如何执行的?拒绝策略有哪些?
    面试突击25:sleep和wait有什么区别
    SpringCloud Nacos + Ribbon 调用服务的 2 种方法!
    为什么start方法不能重复调用?而run方法却可以?
    Spring Cloud Alibaba Nacos 服务注册与发现功能实现!
    多图|一文详解Nacos参数!
  • 原文地址:https://www.cnblogs.com/jrfr/p/13211959.html
Copyright © 2020-2023  润新知