codeforces 808d

Posted %%%%%

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 808d相关的知识,希望对你有一定的参考价值。

Array Division

题意:给一个序列,问将一个数调换顺序能否使得序列分为连续的2段后,2段的和相同;

思路:模拟,注意一点,可能第一个数就大于sum/2,所以要1-n模拟一遍再n-1模拟一遍,具体看代码

AC代码:

#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define step(x) fixed<< setprecision(x)<<
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ll long long
#define endl ("\n")
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const ll mod=1e9+7;
const ll INF = 1e18+1LL;
const int inf = 1e9+1e8;
const double PI=acos(-1.0);
const int N=1e5+100;

ll n,a[N],sum,now;
map<ll,int> M1,M2;
int main(){
    scanf("%lld",&n);
    for(int i=1; i<=n; ++i){
        scanf("%lld",a+i);
        sum+=a[i], M1[a[i]]++, M2[a[i]]++;
    }
    if(sum&1){
        cout<<"NO\n";
        return 0;
    }
    for(int i=1; i<n; ++i){
        ll x=(sum/2)-now;
        if(M1[x]>0){
            cout<<"YES\n";
            return 0;
        }
        now+=a[i], M1[a[i]]--;
    }
    now=0;
    for(int i=n; i>1; --i){
        ll x=(sum/2)-now;
        if(M2[x]>0){
            cout<<"YES\n";
            return 0;
        }
        now+=a[i], M2[a[i]]--;
    }
    cout<<"NO\n";
    return 0;
}

 

以上是关于codeforces 808d的主要内容,如果未能解决你的问题,请参考以下文章

[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段

c_cpp Codeforces片段

Codeforces 86C Genetic engineering(AC自动机+DP)

CodeForces 1005D Polycarp and Div 3(思维贪心dp)

(Incomplete) Codeforces 394 (Div 2 only)

CodeForces 931F Teodor is not a liar!