hdu 5047 大數 平面區域劃分公式

2021-06-29 00:57:51 字數 3094 閱讀 4958

首先吐槽一下,這道題的時間卡得真是醉了............

首先見到這個問題,我們應該先想到直線的平面劃分公式,f(n) = 1 + n(n+1)/2

如何理解這個公式呢

有一條直線時,將乙個平面區域劃分為兩塊,之後每在加一條直線,獲得最大劃分區域的方法就是讓每條直線兩兩相交且不重合.

如果當前直線是第i條,那麼它可以和之前的i-1條相交出i-1格二重交點,劃分出i個區域

那麼依據等差數列求和公式得到

f(n) = 1 + n(n+1)/2

那麼回歸到這道題我們得到,m是由兩條平行的射線,和兩條線段組成,但因為姿勢可以任意,所以在與除和它同在乙個m中線外都可以當作直線,

然後我們考慮這同乙個m中缺失的劃分區域劃分數,

因為在m的上有三個不能延伸的兩兩相交的二重交點,如果能夠延伸的化,能延伸出兩條線,也就是能劃分出三個區域,所以3*3=9

所以缺失了9個區域

然後為了防止超時,在不超long long 的情況下不能用大整數,而是改用i64d

#include #include #include using namespace std;

#define maxn 9999

#define maxsize 1010

#define dlen 4

class bignum

bignum(const long long); //將乙個int型別的變數轉化成大數

bignum(const char*); //將乙個字串型別的變數轉化為大數

bignum(const bignum &); //拷貝建構函式

bignum &operator=(const bignum &); //過載賦值運算子,大數之間進行賦值運算

friend istream& operator>>(istream&,bignum&); //過載輸入運算子

friend ostream& operator<<(ostream&,bignum&); //過載輸出運算子

bignum operator+(const bignum &)const; //過載加法運算子,兩個大數之間的相加運算

bignum operator-(const bignum &)const; //過載減法運算子,兩個大數之間的相減運算

bignum operator*(const bignum &)const; //過載乘法運算子,兩個大數之間的相乘運算

bignum operator/(const int &)const; //過載除法運算子,大數對乙個整數進行相除運算

bignum operator^(const int &)const; //大數的n次方運算

int operator%(const int &)const; //大數對乙個int型別的變數進行取模運算

bool operator>(const bignum &t)const; //大數和另乙個大數的大小比較

bool operator>(const int &t)const; //大數和乙個int型別的變數的大小比較

void print(); //輸出大數

};bignum::bignum(const long long b) //將乙個int型別的變數轉化為大數

a[len++]=d;

}bignum::bignum(const char *s) //將乙個字串型別的變數轉化為大數

}bignum::bignum(const bignum &t):len(t.len) //拷貝建構函式

b.a[count]=sum;

count++;

}b.len=count++;

return in;

}ostream& operator<<(ostream& out,bignum& b) //過載輸出運算子

return out;

}bignum bignum::operator+(const bignum &t)const //兩個大數之間的相加運算

}if(t.a[big]!=0)

t.len=big+1;

else t.len=big;

return t;

}bignum bignum::operator-(const bignum &t)const //兩個大數之間的相減運算

else

big=t1.len;

for(i=0; ii)

t1.a[j--]+=maxn;

t1.a[i]+=maxn+1-t2.a[i];

}else t1.a[i]-=t2.a[i];

}t1.len=big;

while(t1.a[len-1]==0 && t1.len>1)

if(flag)

t1.a[big-1]=0-t1.a[big-1];

return t1;

}bignum bignum::operator*(const bignum &t)const //兩個大數之間的相乘

else

}if(up!=0)

ret.a[i+j]=up;

}ret.len=i+j;

while(ret.a[ret.len-1]==0 && ret.len>1)ret.len--;

return ret;

}bignum bignum::operator/(const int &b)const //大數對乙個整數進行相除運算

ret.len=len;

while(ret.a[ret.len-1]==0 && ret.len>1)

ret.len--;

return ret;

}int bignum::operator%(const int &b)const //大數對乙個 int型別的變數進行取模

bool bignum::operator>(const bignum &t)const //大數和另乙個大數的大小比較

else

return false;

}bool bignum::operator>(const int &t)const //大數和乙個int型別的變數的大小比較

void bignum::print() //輸出大數

int main ( )

}}

hdu 5047 大數找規律

找規律信kuangbin,能ac include include include include include include include include include include include include using namespace std 完全大數模板 輸出cin a 輸出...

hdu 5047平面分割

題目大意 給n條樣子像 m 的折線,求它們能把二維平面分成的面最多是多少。解題思路 我們發現直線1條 2平面 2直線 4平面 3直線 7平面.因為第n條直線要與前面n 1條直線都相交,才能使分的平面最多,則新增第n條直線,平面增加n個 所以公式是面f 2 2 3 n 1 n n 2 1 因為題目的是...

hdu 1002大數加法

include includevoid daoxu int str,int n 定義乙個倒序陣列的函式,n為陣列中元素個數 void daoxu int str,int n else 找出最長數 for int i 0 i 0 j printf for maxline 0 maxline print...