我是靠谱客的博主 明亮马里奥,最近开发中收集的这篇文章主要介绍codeforce Number of Ways(暴力),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #define N 500005
 6 using namespace std;
 7 typedef long long LL;
 8 LL prefix[N], suffix[N], num[N];
 9 LL cntSuf[N];
10 int main(){
11     int n;
12     scanf("%d", &n);
13     for(int i=1; i<=n; ++i){
14         scanf("%lld", &num[i]);
15         prefix[i]=prefix[i-1]+num[i];//前缀和
16     }    
17     for(int i=n; i>=1; --i)
18         suffix[i]=suffix[i+1]+num[i];//后缀和
19     LL s=prefix[n]/3;
20     if(prefix[n]%3!=0){
21         printf("0n");
22         return 0;
23     }
24     LL ans=0;    
25     for(int i=1; i<=n; ++i)        
26         if(suffix[n-i+1]==s) cntSuf[n-i+1]=cntSuf[n-i+2]+1;
27         else cntSuf[n-i+1]=cntSuf[n-i+2];
28     for(int i=1; i<=n; ++i)
29         if(prefix[i]==s) ans+=cntSuf[i+2];
30     printf("%lldn", ans);
31     return 0;
32 }

 

转载于:https://www.cnblogs.com/hujunzheng/p/3969946.html

最后

以上就是明亮马里奥为你收集整理的codeforce Number of Ways(暴力)的全部内容,希望文章能够帮你解决codeforce Number of Ways(暴力)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部