Codeforces Round #723 (Rated for Div 2)

题解

A - Mean Inequality

题意:
想也不想直接暴力
数组开小了也没有报re然后。。就挺sb的。。。

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int t, n, m, q;
ll a[100], ans[100];//n*2了就不是25了。。
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--) {
        cin>>n;
        n*=2;
        int k=0;
        int q=n;
        for(int i=1; i<=n; i++) cin>>a[i];
        sort(a+1, a+1+n);
        for(int i=1; i<=n; i++) {
            if(i%2) ans[i]=a[++k];
            else ans[i]=a[q--];
        }
        for(int i=1; i<=n; i++) {
            cout<<ans[i]<<" \n"[i==n];
        }
    }
	return 0;
}

B - I Hate 1111

打表 说是个定理

#include<bits/stdc++.h>
using namespace std;
long long n, t, a[2005];
int flag;
bool dfs(int x, int i) {
    if (x==0) {
        flag=1;return 1;
    }
    if (i==1)return 0;
    if (x-a[i]>=0) dfs(x-a[i], i);
    if (flag)return 1;
    return dfs(x, i-1);
}
int main() {
    a[1]=1;
    for (int i=2; i<=10; i++) {
        a[i]=a[i-1]*10+1;
    }
    cin>>t;
    while(t--) {
        cin>>n;
        flag=0;
        if(dfs(n,10)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
 return 0;
}

C1 - Potions (Easy Version)

C2 - Potions (Hard Version)

就没什么好说的。。。。使劲贪。。。。写的时候太在乎位置了把所有负数都push了。。。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200005;
string s;
int t, n, ans;
ll a[N], sum;
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    priority_queue<ll, vector<ll >, greater<ll>> q;
    for(int i=1; i<=n; i++) {
        cin>>a[i];
        sum+=a[i];
        q.push(a[i]);
        ans++;
        while(!q.empty()&&sum<0) {
            ll k=q.top();
            q.pop();
            sum-=k;
            ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

自闭场555
在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值