A.
贪心,排序完找2个2个之间最大即可
// Problem: A. Maximise The Score
// Contest: Codeforces - think-cell Round 1
// URL: https://codeforces.com/contest/1930/problem/0
// 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];
void Lan(){
int n;
cin>>n;
for(int i=1;i<=2*n;i++){
cin>>a[i];
}
sort(a+1,a+1+2*n);
ll ans=0;
for(int i=1;i<=2*n;i+=2){
ans+=a[i];
}
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. Permutation Printing
// Contest: Codeforces - think-cell Round 1
// URL: https://codeforces.com/contest/1930/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(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
a[i]=i;
}
int l=1,r=n;
while(l<r){
cout<<a[r]<<" ";
r--;
cout<<a[l]<<" ";
l++;
}
if(n&1){
cout<<a[r];
}
cout<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while (q--) {
Lan();
}
return 0;
}
C.
贪心,排序,不重复即可
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
const int N=3e5+9;
int a[N];
inline void lan(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){//模拟操作
a[i]+=i;
}
sort(a+1,a+1+n,greater<int>());
for(int i=2;i<=n;i++){//不重复
a[i]=min(a[i],a[i-1]-1);//a[i],a[i]重复,(a[i]-1)
}
for(int i=1;i<=n;i++){
cout<<a[i]<<" ";
}
cout<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int q;
cin>>q;
while(q--){
lan();
}
return 0;
}
D1.
题意是给定一个字符串,求每个子串要几个区间为三的101覆盖,然后求和
#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(){
int n;
cin>>n;
string s;
cin>>s;
ll ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=i;k<=j;k++){
if(s[k]=='1'){
ans++;
k+=2;
}
}
}
}
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;
}