其他分享
首页 > 其他分享> > Codeforces Round #735 (Div. 2)

Codeforces Round #735 (Div. 2)

作者:互联网

A. Cherry

贪心

#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
using ll = long long ;
int test(int n){}
void solve()
{
    int n;
    cin>>n;
    vector<ll>a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    long long int ans=0;
    for(int i=2;i<=n;i++)
        ans=max(ans,a[i]*a[i-1]);
    cout<<ans<<"\n";
}
int main()
{
    ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

Cobb

求i⋅j−k⋅(ai|aj) 的最大值
暴力加剪枝就行

#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
using ll = long long ;
int test(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    int ans=-0x3f3f3f3f;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        ans=max(ans,i*j-k*(a[i]|a[j]));
    cout<<ans<<endl;
}
void solve()
{
    int n,k;
    cin>>n>>k;
    vector<ll>a(n+1);
    for(register int i=1,x;i<=n;i++) cin>>a[i];
    ll res=-0x3f3f3f3f;
    for(register ll i=n;i>=1;i--){
        for(register ll j=i-1;j>=1;j--){
            ll p=1ll*i*j-k*(a[i]|a[j]);
            if(p>res) res=p;
            if(i*j<res)break;
        }
    }
    cout<<res<<"\n";
}
int main()
{
    //freopen("out.txt","r",stdin);
    ios::sync_with_stdio(false);
    int T=1;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

标签:int,ll,Codeforces,long,--,735,using,Div,define
来源: https://www.cnblogs.com/qq1415584788/p/15077806.html