Codeforces Round 926 (Div. 2)

A.

很离谱的贪心

实际上化简完式子是an-a1,找最大最小就好了

// Problem: A. Sasha and the Beautiful Array
// Contest: Codeforces - Codeforces Round 926 (Div. 2)
// URL: https://codeforces.com/contest/1929/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
ll a[N],b[N];
void Lan(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	ll ans=0;
	sort(a+1,a+1+n);
	int l=1;
	int r=n;
	for(int i=1;i<=n;i++){
		if(i&1){
			b[i]=a[r];
			r--;
		}else{
			b[i]=a[l];
			l++;
		}
	}
	for(int i=2;i<=n;i++){
		ans+=(a[i]-a[i-1]);
	}
	cout<<ans<<'\n';
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Lan();
	}
	return 0;
}

B.

推结论,加特判

// Problem: B. Sasha and the Drawing
// Contest: Codeforces - Codeforces Round 926 (Div. 2)
// URL: https://codeforces.com/contest/1929/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define eps 1e-5
#define INF 1e9
using namespace std;
typedef long long ll;
const int N = 2e6 + 9;
int a[N];
void Lan(){
	ll n,k;
	cin>>n>>k;
	if(k==4*n-2){
		cout<<2*n<<'\n';
		return;
	}
	cout<<(k+1)/2<<'\n';
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int q;
	cin>>q;
	while (q--) {
		Lan();
	}
	return 0;
}

C.

找到一种方法可以一直都是赚的策略

然后如果能经过x+1次后金额数>=0就必然能得到很多钱

策略是这样的

设总和亏损loss,倍率是k,这次要投t

就有t*k> (loss+t),化简不等式得到t>\frac{loss}{k-1},因此每次应该投$\lfloor \frac{loss}{k-1} \rfloor+1$

std里枚举推公式

#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
const int N=2e5+9;
int a[N];
inline void lan(){
    ll k,x,a;
    cin>>k>>x>>a;
    //需要找到一种下注方式使得这轮如果成功必然能把之前失败的都赚回来,不会输钱
    //k=2
    //第一把投1,第二把投2(因为投1只能回本,投2可以多赚一点),第三把投4
    //k=3
    //第一把投1,第二把投1,第三把投2
    //k
    //第一把投loss,第二把投loss/(k-1)+1
    ll tou=0;//投多少
    ll loss=0;//损失多少
    for(int i=1;i<=x+1;i++){//这是赌场最优方式来让你亏损
        tou=loss/(k-1)+1;
        loss+=tou;
        if(loss>a){//没有钱就无法再投
            cout<<"NO"<<'\n';
            return;
        }
    }
    //那必然可以得到无限money
    cout<<"YES"<<'\n';
    return;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int q;
    cin>>q;
    while(q--){
        lan();
    }
    return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值