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
就有,化简不等式得到
,因此每次应该投
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;
}
1454

被折叠的 条评论
为什么被折叠?



