Codeforces - 466C - Number of Ways - 组合数学
生活随笔
收集整理的這篇文章主要介紹了
Codeforces - 466C - Number of Ways - 组合数学
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
https://codeforces.com/problemset/problem/466/C
要把數(shù)據(jù)分為均等的非空的三組,那么每次確定第二個(gè)分割點(diǎn)的時(shí)候把(除此之外的)第一個(gè)分割點(diǎn)的數(shù)目加上就可以了。記得最后給第三組留至少一個(gè)。
#include<bits/stdc++.h> using namespace std; #define ll long longint n; int a[500005];int main(){scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d",&a[i]);ll sum=0;for(int i=0;i<n;i++){sum+=a[i];}if(sum%3!=0){puts("0");return 0;}ll d=sum/3;int z1=0;ll cnt=0;ll cur=0;int inc=0;int i=0;while(i<n){cur+=a[i];if(cur==d){z1++;inc=1;}else{inc=0;}if(z1>=1){if(cur==2ll*d){if(i<=n-2){//至少把最后一個(gè)n-1留給第三組if(inc)cnt+=z1-1;elsecnt+=z1;//printf("cnt=%lld i=%d\n",cnt,i); }}}i++;}printf("%lld\n",cnt); }?
轉(zhuǎn)載于:https://www.cnblogs.com/Yinku/p/10397267.html
總結(jié)
以上是生活随笔為你收集整理的Codeforces - 466C - Number of Ways - 组合数学的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 洗车气泵需要灌气吗?
- 下一篇: 汽车spec是什么意思