Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2)

Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2)

A. Prison Break

#include <bits/stdc++.h>

using namespace std;
const int maxn = 3e5 + 5;
const int INF=0x7f7f7f7f; //2139062143

void solve(){
    int n,m,r,c;
    cin>>n>>m>>r>>c;
    cout<<(max(n-r,r-1)+max(m-c,c-1))<<"\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

B. Repainting Street

枚举100个颜色即可;
∑n≤10^5 ,

#include <bits/stdc++.h>

using namespace std;
const int maxn = 3e5 + 5;
const int INF=0x7f7f7f7f; //2139062143

int a[maxn];

void solve(){
    int n,k,min_=INF;
    cin>>n>>k;
    for (int i = 1; i <=n; ++i) cin>>a[i];
    for (int i = 1; i <=100; ++i) {
        int num=0;
        for (int j = 1; j <=n; ++j)
            if(a[j]!=i) num++,j+=k-1;
        min_=min(num,min_);
    }
    cout<<min_<<"\n";
}

int main() {
//    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

C. Bouncing Ball

球到i只能是i作为p,或者从i-k跳过来,如果落地点为0就要花费x,否则花费0;
dp[i]=min(dp[i-k],(i-p)*y)+(s[i]==‘0’?x:0);
最后遍历max(n-k+1,p)到n取最小值即可(与p取最大值防止遍历到p之前)

#include <bits/stdc++.h>

using namespace std;
const int maxn = 3e5 + 5;
const int INF=0x7f7f7f7f; //2139062143

int dp[maxn];

void solve(){
    int n,p,k,x,y;
    string s;
    cin>>n>>p>>k>>s>>x>>y;
    dp[p]=(s[p-1]=='0'?x:0);
    for (int i = p; i <=n; ++i) {
        dp[i]=(i-p)*y;
        if (i-k>=p) dp[i]=min(dp[i],dp[i-k]);
        if(s[i-1]=='0') dp[i]+=x;
    }
    int min_=INF;
    for (int i = max(n-k+1,p); i <=n; ++i)
        min_=min(min_,dp[i]);
    cout<<min_<<"\n";
}

int main() {
//    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

D. XOR-gun

n>60必存在连续3个数异或满足改情况
n<60暴力遍历

#include <bits/stdc++.h>

#define int long long
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;

int a[70];

void solve() {
    int n;
    cin >> n;
    if (n > 60) {cout << 1 << endl;return;}
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] ^= a[i - 1];
    }
    int ans = 70;
    for (int i = 1; i < n - 1; ++i) {
        for (int j = i; j < n; ++j) {
            for (int k = j + 1; k <= n; ++k) {
                if ((a[i - 1] ^ a[j]) > (a[k] ^ a[j]))
                    ans = min(k - i - 1, ans);
            }
        }
    }
    if (ans == 70) cout << -1 << endl;
    else cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--)
        solve();
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值