Codeforces Round #667 (Div. 3)

Codeforces Round #667 (Div. 3)

A. Yet Another Two Integers Problem

#include <bits/stdc++.h>
#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e4 + 10;
using namespace std;

void solve() {
    int a,b;
    cin>>a>>b;
    int t=ceil(abs(b-a)*1.0/10);
    cout<<t<<endl;
}

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

B. Minimum Product

#include <bits/stdc++.h>
#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e4 + 10;
using namespace std;

void solve() {
    int a,b,x,y,n;
    cin>>a>>b>>x>>y>>n;
    cout<<min(max(y,b-n+min(n,a-x))*max(x,a-n),max(x,a-n+min(n,b-y))*max(y,b-n))<<endl;
}

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

C. Yet Another Array Restoration

#include <bits/stdc++.h>
#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e4 + 10;
using namespace std;

void solve() {
    int n,x,y;
    cin>>n>>x>>y;
    for (int i=1;i<=50; ++i)
        if ((y - x) % i == 0 && (y - x) / i < n) {
            int sum=y+(n-ceil(y*1.0/i))*i;
            if (y/i>=n)sum=y;
            for (int j=sum ; n--; j -= i) cout << j << " ";
            cout<<endl;
            return;
        }
}

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

D. Decrease the Sum of Digits

#include <bits/stdc++.h>
#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e4 + 10;
using namespace std;

int sum(int n){
    int a=0;
    while (n) a+=n%10,n/=10;
    return a;
}

void solve() {
    int n,s,num=0,b=10;
    cin>>n>>s,num=n;
    while (sum(n)>s) n+=b-n%b,b*=10;
    cout<<n-num<<endl;
}

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

E. Two Platforms

#include <bits/stdc++.h>

#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
using namespace std;

int a[maxn], x[maxn], l[maxn];

void solve(){
    int n, k, y, ans=0;
    memset(a,0,sizeof(a));
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) cin >> x[i];
    sort(x + 1, x + n + 1);
    for (int j = 1; j <= n; ++j) cin >> y;
    for (int i =n;i>=1;i--){
        int nx=x[i]+k;
        int ii=upper_bound(x+1,x+n+1,nx)-x;
        a[i]=max(a[i+1],ii-i);
    }
    for (int i = 1; i <= n; ++i) {
        int nx=x[i]+k;
        int ii=upper_bound(x+1,x+n+1,nx)-x;
        ans=max(ans,a[ii]+ii-i);
    }
    cout << ans << endl;
}

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

F. Subsequences of Length Two

#include <bits/stdc++.h>
#define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N=205;
using namespace std;

int dp[N][N][N];

void solve(){
    int n,kk;
    char a[N],b[N];int max_=0;
    cin>>n>>kk>>a>>b;
    if(b[0]==b[1]){
        char c=b[1];
        int cnt=count(a,a+n,c);
        cnt=min(cnt+kk,n);
        max_=cnt*(cnt-1)/2;
    }else{
        memset(dp,-1000000,sizeof(dp));
        dp[0][0][0]=0;
        for (int i =1; i <=n; ++i) {
            for (int j = 0; j <=n; ++j) {
                for (int k = 0; k <=kk; ++k) {
                    int &res = dp[i][j][k];
                    if(a[i-1]==b[0]&&j) res = max(res, dp[i - 1][j-1][k]);
                    else if (a[i-1]==b[1]) res=max(res,dp[i-1][j][k]+j);
                    else res = dp[i - 1][j][k];
                    if (k){
                        if (j&&a[i-1]!=b[0]) res = max(res, dp[i - 1][j - 1][k - 1]);
                        if (a[i-1]!=b[1])res =max(res,dp[i-1][j][k-1]+j);
                    }
                    max_=max(max_,res);
                }
            }
        }
    }
    cout<<max_<<endl;
}

signed main() {
    //ios::sync_with_stdio(false);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、付费专栏及课程。

余额充值