Idea: Divide a stick into 3 segments so that it can form a triangle the total number of schemes can be calculated as such, enumerating an edge, and then pushing the formula to calculate the current number of scenarios. The case of a known edge is also introduced with a formula. Use Max and Min and maintain it to reduce the number of cases.
1 #pragmaComment (linker, "/stack:10240000,10240000")2 3#include <iostream>4#include <cstdio>5#include <algorithm>6#include <cstdlib>7#include <cstring>8#include <map>9#include <queue>Ten#include <deque> One#include <cmath> A#include <vector> -#include <ctime> -#include <cctype> the#include <Set> -#include <bitset> -#include <functional> -#include <numeric> +#include <stdexcept> -#include <utility> + A using namespacestd; at - #defineMem0 (a) memset (a, 0, sizeof (a)) - #defineLson L, M, RT << 1 - #defineRson m + 1, R, RT << 1 | 1 - #definedefine_m int m = (L + r) >> 1 - #defineRep0 (A, b) for (int a = 0; a < (b); a++) in #defineRep1 (A, b) for (int a = 1; a <= (b); a++) - #defineAll (a) (a). Begin (), (a). End () to #defineLowbit (x) ((x) & (-(x))) + #defineCONSTRUCTINT4 (name, a, B, C, D) name (int a = 0, int b = 0, int c = 0, int d = 0): A (a), B (b), C (c), D (d) {} - #defineCONSTRUCTINT3 (name, a, B, c) name (int a = 0, int b = 0, int c = 0): A (a), B (b), C (c) {} the #defineConstructInt2 (name, a, b) name (int a = 0, int b = 0): A (a), B (b) {} * #definePCHR (a) Putchar (a) $ #definePstr (a) printf ("%s", a)Panax Notoginseng #defineSint (a) ReadInt (a) - #defineSint2 (A, B) ReadInt (a); ReadInt (b) the #defineSint3 (A, B, c) ReadInt (a); ReadInt (b); ReadInt (c) + #definePint (a) writeint (a) A thetypedefDoubledb; +typedefLong LongLL; -typedef pair<int,int>PII; $typedef multiset<int>MSI; $typedefSet<int>si; -typedef vector<int>VI; -typedef map<int,int>Mii; the - Const intdx[8] = {0,1,0, -1,1,1, -1, -1};Wuyi Const intdy[8] = {1,0, -1,0, -1,1,1, -1}; the Const intMAXN = 1e3 +7; - Const intMAXM = 1e5 +7; Wu Const intMAXV = 1e7 +7; - Const intMax_val = 1e6 +7; About Const intMD = 1e9 +7; $ Const intINF = 1e9 +7; - Const DoublePI = ACOs (-1.0); - Const DoubleEPS = 1e-Ten; - Atemplate<classT>t gcd (t A, T b) {returnb==0? A:GCD (b,a%b);} +template<classT>voidReadInt (T &x) {CharC=getchar (); while(!isdigit (c)) C=getchar (); x=0; while(IsDigit (c)) {x=x*Ten+c-'0'; c=GetChar ();}} thetemplate<classT>voidWriteint (T i) {intp=0;Static intb[ -];if(i = =0) b[p++] =0;Else while(i) {b[p++]=i%Ten; i/=Ten;} for(intj=p-1; j>=0; j--) PCHR ('0'+b[j]);} - $ theLL Work (intAintb) { the if(b <= a)return 0; the returnMax0, (A + B-1) /2-(B-A)/2); the } -LL Work (intMAXV) { inLL ans =0; theREP1 (i, MAXV-1) { theAns + = Work (I, MAXV-i); About } the returnans; the } the inta[1010]; + intMain () { - //freopen ("In.txt", "R", stdin); the intN, M;Bayi while(Cin >> N >>m) { the rep0 (i, m) { the Sint (A[i]); - } -Sort (A, A +m); the intMINV = a[0] -1, MAXV = n-a[m-1]; the if(Minv >maxv) Swap (MINV, MAXV); the if(MINV = =0) Pint (Work (MAXV)); the Else { - if(MINV = =1) { the if(MAXV &1) Pint (0); the ElsePint1); the }94 Else { the if(MINV = = MAXV) Pint (0); the ElsePint (Work (MINV, MAXV)); the }98 } AboutPCHR ('\ n'); - }101 return 0;102}
View Code
[hdu5203] Counting water problems