think-cell Round 1

A:Maximise The Score

每次选两个数,加上小的数的值,求最高分

排序,每次挑小的

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
int a[N],b[N];

void solve(){
   int n;
   cin>>n;
   for(int i=0;i<n*2;i++) cin>>a[i];
   int res=0;
   sort(a,a+n*2);
   for(int i=0;i<n*2;i+=2){
   	  res+=a[i];
   }
   cout<<res<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

B:Permutation Printing

不让满足的话只需要大小交替即可

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
int a[N],b[N];

void solve(){
   int n;
   cin>>n;
   int l=1,r=n;
   for(int i=1;i<=n;i++){
   	  if(i&1) cout<<l++<<" ";
   	  else cout<<r--<<" ";
   }
   cout<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

C:Lexicographically Largest

字典树最大,贪心的思考,必须把大的放到前面,由于插入后还会删去,我们一定要把最后面最大值插进去,不然前面要减一,先排序加上序号,排序,每次取min(a[i],a[i-1]-1)

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 310000
int a[N],b[N];

void solve(){
   int n;
   cin>>n;
   for(int i=0;i<n;i++) cin>>a[i],a[i]+=i+1;
   int mx=1e18;
   sort(a,a+n,greater<>());
   for(int i=0;i<n;i++) {
   	   if(mx>a[i]) {
   	      cout<<a[i]<<" ";
		  mx=a[i];   	
	  }
	  else cout<<mx-1<<" ",mx--;
   }
   cout<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

D:Sum over all Substrings (Hard Version)

d1暴力枚举所有子串构造节课

d2要想每一个1怎么构造,发现三个一组,动态规划

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
typedef pair<int,int>pii;
#define N 1010000
//int a[N],b[N];
int dp[N];
void solve(){
   int n;
   cin>>n;
   string s;
   cin>>s;
   s=" "+s;
   for(int i=1;i<=n;i++) dp[i]=0;
   for(int i=1;i<=n;i++){
   	  if(s[i]=='1') {
   	     if(i>=3) dp[i]=dp[i-3]+i;
		 else dp[i]=i;  	
	  } 
	  else dp[i]=dp[i-1];
   }
   cout<<accumulate(dp+1,dp+n+1,0ll)<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t=1;
    cin>>t;
   // init();
    while(t--){
        solve();
    }
}

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多年以后

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值