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;
}

B.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;
}

c.Mikasa

#include <iostream>
#include <cstring>
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
using ll = long long ;
void solve()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll ans=0x7fffffff;
    for(ll i=32;i>=0;i--){
        ll l=(n>>i)<<i,r=((m>>i)+1)<<i;
        ans=min(ans,l^r);
    }
    printf("%d\n",ans);
}
int main()
{
    int T=1;
    scanf("%d",&T);
    while(T--)
        solve();
    return 0;
}

D.Diane

如果是偶数...aabaaa...奇数末尾加个c

#include <iostream>
#include <cstring>
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
using ll = long long ;
void solve()
{
    int n;
    scanf("%d",&n);
    if(n&1){
        for(int i=1;i<n/2;i++)putchar(‘a‘);putchar(‘b‘);
        for(int i=1;i<=n/2;i++)putchar(‘a‘);
        if(n!=1)putchar(‘c‘);
    }else{
        for(int i=1;i<n/2;i++)putchar(‘a‘);putchar(‘b‘);
        for(int i=1;i<=n/2;i++)putchar(‘a‘);
    }puts("");
}
int main()
{
    ios::sync_with_stdio(false);
    int T=1;
    scanf("%d",&T);
    while(T--)
        solve();
    return 0;
}

Codeforces Round #735 (Div. 2)

上一篇:新增一块磁盘,磁盘无法识别问题,无需重启主机


下一篇:Stream