当年中二,零碎模板
0x01gmath
/** 占坑待填 20171004* Bigint高精度* 数据结构模板* 图论算法模板* 数学完善*///头文件模板#include #include #include #include #include #include #include #include #include #include #include #include #include
vs, cmp[N]; int vis[N], book[N], cnt; void dfs(int u){ if(vis[u])return ; vis[u] = 1; for(int i = 0; i < G[u].size(); i++)dfs(G[u][i]); vs.push_back(u); } void rdfs(int u){ if(book[u])return ; book[u] = cnt; cmp[cnt].push_back(u); for(int i = 0; i < rG[u].size(); i++)rdfs(rG[u][i]); }};struct Bigint{ vector
s; int is_minus; Bigint(long long num = 0, int ok = 1){ *this = num; is_minus = ok;}//构造函数,元素初始值为0 Bigint operator = (long long num){ s.clear(); do{ s.push_back(num%10); num /= 10; }while(num > 0); return *this; } Bigint operator = (const string& str){ s.clear(); for(int i = str.size()-1; i >= 0; i--) if(str[i] == '-')is_minus = -1; else s.push_back(str[i]-'0'); } Bigint operator + (const Bigint& b)const{ Bigint c; c.s.clear(); Bigint n = *this, m = b; if(n.is_minus==-1 && m.is_minus==1){ c = m-n; }else if(n.is_minus==1 && m.is_minus==-1){ c = n-m; }else { if(n.is_minus==-1 && m.is_minus==-1) c.is_minus = -1; int x = 0, len = max(n.s.size(),m.s.size());//x是进位 for(int i = 0; i < len; i++){ if(len >= n.s.size())n.s.push_back(0);//不够长的话补0 if(len >= m.s.size())m.s.push_back(0); c.s.push_back(n.s[i]+m.s[i]+x); x = c.s[i]/10; c.s[i] %= 10; } if(x)c.s.push_back(x);//最高进位 len = c.s.size()-1; while(c.s[len]==0 && len>0)len--; c.s.resize(len+1); } return c; } Bigint operator - (const Bigint& b)const{ Bigint n = *this, m = b; int ok = 1; //保证被减数大于减数 if(n.s.size()