国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

hdu-5241

2019-11-08 18:35:36
字體:
來源:轉載
供稿:網友

Mike has many friends. Here are nine of them: Alice, Bob, Carol, Dave, Eve, Frank, Gloria, Henry and Irene.

Mike is so skillful that he can master nn languages (aka. PRogramming languages).

His nine friends are all weaker than he. The sets they can master are all subsets of Mike’s languages.

But the relations between the nine friends is very complex. Here are some clues.

Alice is a nice girl, so her subset is a superset of Bob’s. Bob is a naughty boy, so his subset is a superset of Carol’s. Dave is a handsome boy, so his subset is a superset of Eve’s. Eve is an evil girl, so her subset is a superset of Frank’s. Gloria is a cute girl, so her subset is a superset of Henry’s. Henry is a tall boy, so his subset is a superset of Irene’s. Alice is a nice girl, so her subset is a superset of Eve’s. Eve is an evil girl, so her subset is a superset of Carol’s. Dave is a handsome boy, so his subset is a superset of Gloria’s. Gloria is a cute girl, so her subset is a superset of Frank’s. Gloria is a cute girl, so her subset is a superset of Bob’s.

Now Mike wants to know, how many situations there might be. Input The first line contains an integer TT(T≤20T≤20) denoting the number of test cases.

For each test case, the first line contains an integer nn(0≤n≤30000≤n≤3000), denoting the number of languages.

Output For each test case, output ”Case #t:” to represent this is the t-th case. And then output the answer. Sample Input 2 0 2 Sample Output Case #1: 1 Case #2: 1024

解題思路:答案為32的n次方,我也不知道為什么是這個答案,我是看別人的題解才知道的,據說是看出來,我只想說6666. 通過這題我總結了乘法大數算法,令d[i]為一個大數的第i位,從右開始,第一位(個位)為0位,則有大數a,b,的乘積為大數c,c.d[i + j] = a.d[i]*b.d[j];但是這樣之后c的每一位可能大于9,所以需要對每一位進行取余(與10),并且向高位進行進位,直到a.len + b.len。最后從最高位(a.len + b.len)開始向低位判斷,c到底有多少位,注意在重載^運算符時,不要一個一個乘,要用快速冪思想,不然這一題會超時。

#include<bits/stdc++.h>using namespace std;const int maxn = 1e5;class bignum{public: int d[maxn];//每一位 int len;//數的長度 bignum() { memset(d,0,sizeof(d)); } bignum(int x) { int l = 0; memset(d,0,sizeof(d)); while(x) { d[l++] = x%10; x /= 10; } len = l; } bignum Operator * (const bignum &res) const { bignum ans; for(int i = 0; i < this->len; i++) { for(int j = 0; j < res.len; j++) { ans.d[i + j] += d[i]*res.d[j]; } } for(int i = 0; i < this->len + res.len; i++) { ans.d[i + 1] += ans.d[i]/10; ans.d[i] %= 10; } int Len = this->len + res.len; while(Len > 1&&ans.d[Len - 1] == 0) { Len--; } ans.len = Len; return ans; } bignum operator ^ (const int x) const { bignum ans(1); bignum res; res.len = this->len; int term = x; for(int i = 0; i < this->len; i++) { res.d[i] = this->d[i]; } while(term) { if(term&1) ans = ans*res; term >>= 1; res = res*res; } return ans; } void print() { for(int i = len - 1; i >= 0; i--) { printf("%d",d[i]); } printf("/n"); }};int main(){ int T; int Case = 1; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); bignum term(32); term = term^n; printf("Case #%d: ",Case++); term.print(); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 左云县| 陵水| 息烽县| 宝鸡市| 秦皇岛市| 葫芦岛市| 惠州市| 旬邑县| 青浦区| 惠安县| 福泉市| 吉木萨尔县| 新宁县| 长乐市| 子洲县| 保山市| 南陵县| 固原市| 泾源县| 卓资县| 祁东县| 肃北| 隆安县| 桐城市| 龙井市| 刚察县| 青海省| 遂昌县| 镇雄县| 申扎县| 奉贤区| 西峡县| 富平县| 阜南县| 仙桃市| 汉中市| 加查县| 建平县| 伊宁县| 定襄县| 金昌市|