求助,分治方法就#5对了,其他全部WA
查看原帖
求助,分治方法就#5对了,其他全部WA
1018047
tfj_typhoon楼主2025/1/8 02:17

题目:P2415 集合求和

就#5对了

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll ans=0;
ll s[35];
void marge(ll l,ll r)
{
    if(l==r) {
        ans+=s[l];
        return ;
    }
    int mid=(l+r)>>1;
    marge(l,mid); marge(mid+1,r); //分治
    for(int i=l;i<=r;i++) ans+=s[i];
}
int main()
{
    ios::sync_with_stdio(false);
    cout.tie(0);cin.tie(0);
    int i=0;
    while(cin>>s[++i]);
    marge(1,i);
    cout<<ans;
    return 0;
}
2025/1/8 02:17
加载中...