当前位置: 代码迷 >> 综合 >> 紫书 例题 10-23 UVa 10213(欧拉公式+高精度)
  详细解决方案

紫书 例题 10-23 UVa 10213(欧拉公式+高精度)

热度:20   发布时间:2023-09-20 20:49:10.0

用欧拉公式V-E+F=2

V是顶点数,E是边数,F是面数

具体推导见https://blog.csdn.net/QWsin/article/details/53635397

要用高精度

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;const int MAXN = 112;
struct bign
{int len, d[MAXN];void clean() 	{ while(len > 1 && !d[len-1]) len--; }   //去零 bign() 			{ memset(d, 0, sizeof(d)); len = 1; }bign(int num) 	{ *this = num; }                         //bign a = 123(int) bign(char* num) { *this = num; }                         //bign a = "123"bign operator = (const char* num)                        //a = "123"{memset(d, 0, sizeof(d));len = strlen(num);REP(i, 0, len) d[i] = num[len-i-1] - '0';clean();return *this;}bign operator = (int num)                               //a = 123(int) {char s[20];sprintf(s, "%d", num);*this = s;return *this;}bign operator + (const bign& b)                        //加法 {bign c = *this;	int i;for(i = 0; i < b.len; i++){c.d[i] += b.d[i];if(c.d[i] > 9) c.d[i] %= 10, c.d[i+1]++; }while(c.d[i] > 9) c.d[i] %= 10, c.d[i+1]++; c.len = max(len, b.len) + 1;c.clean();return c;}bign operator - (const bign& b)                       //减法 {bign c = *this; int i;for(i = 0; i < b.len; i++){c.d[i] -= b.d[i];if(c.d[i] < 0) c.d[i] += 10, c.d[i+1]--; }while(c.d[i] < 0) c.d[i++] += 10, c.d[i]--; c.clean();return c;}bign operator * (const bign& b) const              //乘法,记得这里有const {bign c; c.len = len + b.len;REP(i, 0, len)REP(j, 0, b.len)c.d[i+j] += d[i] * b.d[j];REP(i, 0, c.len-1)c.d[i+1] += c.d[i] / 10, c.d[i] %= 10;c.clean();return c;}bign operator / (const bign& b)                    //除法 {bign c = *this, a = 0;int i, j;for(i = len - 1; i >= 0; i--){a = a * 10 + d[i];for(j = 0; j < 10; j++) if(a < b*(j+1)) break;c.d[i] = j;a = a - b * j; }c.clean();return c;}	bign operator % (const bign& b)                    //模 {bign a = 0;int i, j;for(i = len - 1; i >= 0; i--){a = a * 10 + d[i];for(j = 0; j < 10; j++) if(a < b*(j+1)) break;a = a - b * j; }return a;}bign operator += (const bign& b)                 //+= {*this = *this + b;return *this; }bool operator <(const bign& b) const{if(len != b.len) return len < b.len;for(int i = len - 1; i >= 0; i--)if(d[i] != b.d[i])return d[i] < b.d[i];return false;}bool operator >(const bign& b)  const {return b < *this;}bool operator <=(const bign& b) const {return !(b < *this);}bool operator >=(const bign& b) const {return !(*this < b);}bool operator !=(const bign& b) const {b < *this || *this < b;}bool operator ==(const bign& b) const {return !(b < *this || *this < b);}
};istream&  operator >> (istream& in, bign &x)
{int a;in>>a;x=a;return in;    
}
ostream&  operator << (ostream& out,const bign &x)
{for(int i = x.len - 1; i >= 0; i--)printf("%d", x.d[i]);return out;
}int main()
{int T;scanf("%d", &T);while(T--){bign n;cin >> n; n = n * n * n * n + (bign)23 * n * n - bign(6) * n * n * n - (bign)18 * n;cout << n / 24 + (bign)1 << endl; }return 0;
}