[HDU4927] Series 1 && 高精度+组合数
2015-02-03 21:48
253 查看
高精度模板 存档
#include<cstdio> #include<algorithm> #include<cstring> #include<vector> #include<cstring> #define SF scanf #define PF printf using namespace std; typedef long long LL; const int MAXL = 300; const int L = 10000; struct Hp { int Len, A[MAXL+10]; Hp (int x = 0) { memset(A, 0, sizeof(A)); Len = 0; while(x) { A[Len++] = x % L; x /= L; } } Hp fix() { while( Len && !A[Len-1]) Len--; return *this; } Hp operator = (int x) { memset(A, 0, sizeof(A)); Len = 0; while(x) { A[Len++] = x % L; x /= L; } return *this; } int operator [] (const int &pos) const { return A[pos]; } int & operator [] (const int &pos) { return A[pos]; } Hp operator + (const Hp &b) const { Hp c; c.Len = max(Len, b.Len) + 1; int add = 0; for(int i = 0; i < c.Len; i++) { add += A[i] + b[i]; c[i] = add % L; add /= L; } return c.fix(); } Hp operator - (const Hp &b) const { Hp c; c.Len = max(Len, b.Len); int del = 0; for(int i = 0; i < c.Len; i++) { del += A[i] - b[i]; c[i] = del; del = 0; if(c[i] < 0) { int tmp = (-c[i] - 1) / L + 1; c[i] += tmp * L; del -= tmp; } } return c.fix(); } Hp operator * (const Hp &b) const { Hp c; c.Len = Len + b.Len; for(int i = 0; i < Len; i++) { int mul = 0; for(int j = 0; j <= b.Len; j++) { mul += A[i] * b[j] + c[i + j]; c[i + j] = mul % L; mul /= L; } } return c.fix(); } Hp operator / (const int &b) const { Hp c; c.Len = Len; int over = 0; for(int i = Len-1; i >= 0; i--) { over = over * L + A[i]; c[i] = over / b; over %= b; } return c.fix(); } Hp operator += (const Hp &b) { *this = *this + b; return *this; } Hp operator -= (const Hp &b) { *this = *this - b; return *this; } Hp operator *= (const Hp &b) { *this = *this * b; return *this; } Hp operator /= (const int &b) { *this = *this / b; return *this; } bool operator < (const Hp &b) const { if(Len != b.Len) return Len < b.Len; for(int i = Len-1; i >= 0; i--) if(A[i] != b[i]) return A[i] < b[i]; return false; } bool operator > (const Hp &b) const { return b < *this; } bool operator <= (const Hp &b) const { return !(b < *this); } bool operator >= (const Hp &b) const { return !(*this < b); } bool operator != (const Hp &b) const { return b < *this || *this < b; } bool operator == (const Hp &b) const { return !(b < *this) && !(*this < b); } }; int a[L+10]; void print(const Hp &A) { PF("%d", A[A.Len-1]); for(int i = A.Len-2; i >= 0; i--) PF("%04d", A[i]); puts(""); } int main() { int T; SF("%d", &T); while(T--) { int n; Hp ans = 0, add = 0, del = 0, C = 1; SF("%d", &n); for(int i = n; i >= 1; i--) SF("%d", &a[i]); for(int i = 1; i <= n; i++) { if(i > 1) C = C * (n - i + 1) / (i - 1); if(i & 1) add += C * a[i]; else del += C * a[i]; } if(add < del) { putchar('-'); ans = del - add; } else ans = add - del; print(ans); } }
相关文章推荐
- HDU4927 Series 1(14年多校练习G题)高精度模板
- hdu4927 Series 1(组合+公式 Java大数高精度运算)
- hdu4927 Series 1(组合+公式 Java大数高精度运算)
- HDU4927 Series 1 高精度
- C# Keywords Series 1 abstract&as
- HDU 5351 MZL's Border(找规律+高精度)
- bzoj2656 数列 高精度&递推
- C++ Knowledge series Conversion & Constructor & Destructor
- UVa 10247 Complete Tree Labeling (组合数学&高精度)
- HYSBZ/BZOJ 1005 [HNOI2008] 明明的烦恼 - Prufer编码&组合数学&高精度 此乃神题!
- 字串数(高精度组合数)
- 求组合数取模(杨辉三角打表 & 求逆元(扩展欧几里得、费马小定理、欧拉定理、线性求法) & Lucas)
- What Types of Database Questions are Asked in Interview for Testing Positions? – Testing Q&A Series
- 数论基础之组合数&计数问题
- HDU4927-Series 1-组合数学加java大数
- (C#)计算字符串排列组合数 如"abcd"组合数为24 "aabb"组合数为6
- C# Keywords Series 8 interface&virtual&abstract&override&new
- nyoj 32 组合数<水>
- POJ 3233 && NYOJ 298 Matrix Power Series(矩阵快速幂)
- hdu4927 Series 1(大数加减乘除)