think-cell Round 1
叮!你的橙名体验卡已到期~
A
sort 以后,是奇数项之和。
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while (t--){
int n;
cin>>n;
vector<ll> v(n*2);
for (int i=0; i<n*2; i++){
cin>>v[i];
}
sort(v.begin(),v.end());
ll ans=0;
for (int i=0; i<n*2; i+=2){
ans+=v[i];
}
cout<<ans<<"\n";
}
return 0;
}
B
构造 1 n 2 n-1 ...
就可以了。也就是说
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while (t--){
int n;
cin>>n;
int l=1,r=n,f=0;
while (n--){
if (!f){
cout<<l<<" ";
l++;
}
else{
cout<<r<<" ";
r--;
}
f^=1;
}
cout<<"\n";
}
return 0;
}
C
噩梦的开始。
从
然后可以从大到小 sort 不会改变答案,直接这样即可。
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5+5;
ll n,a[N];
void solve(){
cin>>n;
for (int i=1; i<=n; i++){
cin>>a[i];
a[i]+=i;
}
sort(a+1,a+1+n);
reverse(a+1,a+1+n);
set<ll> st;
ll cur=a[1];
for (int i=1; i<=n; i++){
if (a[i]<cur){
cur=a[i];
}
st.insert(cur);
cur--;
}
vector<int> v;
for (auto u : st){
v.push_back(u);
}
reverse(v.begin(),v.end());
for (auto u : v){
cout<<u<<" ";
}
cout<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while (t--){
solve();
}
return 0;
}
D1
枚举所有 010
的结构可以把长度
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(){
int n;
cin>>n;
string s;
cin>>s;
s=" "+s;
int ans=0;
for (int i=1; i<=n; i++){
for (int j=i; j<=n; j++){
vector<int> dp(n+1,1e9);
dp[i-1]=0;
for (int k=i; k<=j; k++){
dp[k]=min(dp[k],dp[k-1]+s[k]-'0');
if (k>=2)dp[k]=min(dp[k],dp[k-2]+(s[k]-'0'+s[k-1]-'0'+1)/2);
if (k>=3)dp[k]=min(dp[k],dp[k-3]+(s[k]-'0'+s[k-1]-'0'+s[k-2]-'0'+2)/3);
}
ans+=dp[j];
}
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while (t--){
solve();
}
return 0;
}
D2
枚举
这个是赛后代码,因为赛时代码有一处多余的部分。
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(){
int n;
cin>>n;
string s;
cin>>s;
s=" "+s;
ll ans=0;
vector<ll> f(n+1,0);
for (int i=1; i<=n; i++){
ll t=ans;
if (s[i]=='1'){
ans+=s[i]-'0';
if (i>=2)ans+=(s[i]-'0'+s[i-1]-'0'+1)/2;
if (i>=3)ans+=f[i-3]+(i-2)*((s[i]-'0'+s[i-1]-'0'+s[i-2]-'0'+2)/3);
}
else{
ans+=f[i-1];
}
f[i]=ans-t;
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while (t--){
solve();
}
return 0;
}
E
前情提要:我推出来了正确式子,但是认为它是
枚举操作了几次。
-
次。答案加 。 -
次。要删掉 个数。这个有 种,但是有些方案不行。发现如果有 不和其他的连续(最大连续段长 )才可以。因此答案加上 。(如果是连续的(后面一项),可以压缩成一个,不同的位置也要相应的减。)
然后复杂度时
这是赛后代码/ng
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6+6;
const ll mod = 998244353;
ll fac[N],inv[N];
ll pw(ll x,ll y){
ll res=1;
while (y){
if (y&1){
res=res*x%mod;
}
x=x*x%mod;
y>>=1;
}
return res;
}
ll Inv(ll x){
return pw(x,mod-2);
}
void init(){
fac[0]=inv[0]=1;
for (int i=1; i<N; i++){
fac[i]=fac[i-1]*i%mod;
inv[i]=Inv(fac[i]);
}
}
ll C(ll x,ll y){
if (x<0||y<0||x<y)return 0;
return fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
init();
while (t--){
int n;
cin>>n;
for (int k=1; k*2<n; k++){
ll ans=1;
for (int t=1; 2*k*t<n; t++){
ans=(ans+C(n,2*k*t)-C(n-2*k*(t-1)-1,2*k-1)+mod)%mod;
}
cout<<ans<<" ";
}
cout<<"\n";
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)