Friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1350    Accepted Submission(s): 634

Problem Description
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 n 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.

1. Alice is a nice girl, so her subset is a superset of Bob's.
2. Bob is a naughty boy, so his subset is a superset of Carol's.
3. Dave is a handsome boy, so his subset is a superset of Eve's.
4. Eve is an evil girl, so her subset is a superset of Frank's.
5. Gloria is a cute girl, so her subset is a superset of Henry's.
6. Henry is a tall boy, so his subset is a superset of Irene's.
7. Alice is a nice girl, so her subset is a superset of Eve's.
8. Eve is an evil girl, so her subset is a superset of Carol's.
9. Dave is a handsome boy, so his subset is a superset of Gloria's.
10. Gloria is a cute girl, so her subset is a superset of Frank's.
11. 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 T(T≤20) denoting the number of test cases.

For each test case, the first line contains an integer n(0≤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
 
Source
 
 
 
找规律?很容易能想到?反正我没想到。
32的n次方,
首先大数用JAVA写是真鸡儿爽,
  1. import java.util.*;
  2. import java.math.*;
  3.  
  4. public class Main {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. BigInteger base = new BigInteger("32");
  8. int t = sc.nextInt();
  9. int n;
  10. int cas = 0;
  11. while (t-- > 0) {
  12. n = sc.nextInt();
  13. System.out.printf("Case #%d: ", ++cas);
  14. System.out.println(base.pow(n));
  15. }
  16. }
  17. }

用C++模拟也可以,

大数模板来一发,

  1. /*
  2. 整数大数
  3. int数组实现
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. #define MAXN 9999//万进制
  9. #define DLEN 4//4位
  10.  
  11. class BigNum{
  12. //private:
  13. public:
  14. int a[];//可以控制大数位数(500*4)
  15. int len;//大数长度
  16. public:
  17. BigNum(){//构造函数
  18. len=;
  19. memset(a,,sizeof(a));
  20. }
  21. BigNum(const int);//将int转化为大数
  22. BigNum(const char *);//将字符串转化为大数
  23. BigNum(const BigNum &);//拷贝构造函数
  24. BigNum &operator=(const BigNum &);//重载赋值运算符,大数之间赋值
  25.  
  26. BigNum operator+(const BigNum &)const;//大数+大数
  27. BigNum operator-(const BigNum &)const;//大数-大数
  28. BigNum operator*(const BigNum &)const;//大数*大数
  29. BigNum operator/(const int &)const;//大数/int
  30.  
  31. BigNum operator^(const int &)const;//幂运算
  32. int operator%(const int &)const;//取模
  33. bool operator>(const BigNum &)const;//大数与大数比较
  34. bool operator>(const int &)const;//大数与int比较
  35.  
  36. void print();//输出大数
  37. };
  38.  
  39. BigNum::BigNum(const int b){//将int转化为大数
  40. int c,d=b;
  41. len=;
  42. memset(a,,sizeof(a));
  43. while(d>MAXN){
  44. //c=d-(d/(MAXN+1))*(MAXN+1);
  45. c=d%(MAXN+);//取出后四位
  46. d=d/(MAXN+);//
  47. a[len++]=c;
  48. }
  49. a[len++]=d;
  50. }
  51. BigNum::BigNum(const char *s){//将字符串转化为大数
  52. int t,k,index,l,i,j;
  53. memset(a,,sizeof(a));
  54. l=strlen(s);
  55. len=l/DLEN;
  56. if(l%DLEN)++len;
  57. index=;
  58. for(i=l-;i>=;i-=DLEN){
  59. t=;
  60. k=i-DLEN+;
  61. if(k<)k=;
  62. for(j=k;j<=i;++j)
  63. t=t*+s[j]-'';
  64. a[index++]=t;
  65. }
  66. }
  67. BigNum::BigNum(const BigNum &T):len(T.len){//拷贝构造函数
  68. int i;
  69. memset(a,,sizeof(a));
  70. for(i=;i<len;++i)
  71. a[i]=T.a[i];
  72. }
  73. BigNum &BigNum::operator=(const BigNum &n){//重载复制运算符,大数之间赋值
  74. int i;
  75. len=n.len;
  76. memset(a,,sizeof(a));
  77. for(i=;i<len;++i)
  78. a[i]=n.a[i];
  79. return *this;
  80. }
  81.  
  82. BigNum BigNum::operator+(const BigNum &T)const{//大数+大数
  83. BigNum t(*this);
  84. int i,big;//位数
  85. big=T.len>len?T.len:len;
  86. for(i=;i<big;++i){
  87. t.a[i]+=T.a[i];
  88. if(t.a[i]>MAXN){
  89. ++t.a[i+];
  90. t.a[i]-=MAXN+;
  91. }
  92. }
  93. if(t.a[big]!=)t.len=big+;
  94. else t.len=big;
  95. return t;
  96. }
  97. BigNum BigNum::operator-(const BigNum &T)const{//大数-大数
  98. int i,j,big;
  99. bool flag;
  100. BigNum t1,t2;//t1大的,t2小的
  101. if(*this>T){
  102. t1=*this;
  103. t2=T;
  104. flag=;//前面的大
  105. }
  106. else{
  107. t1=T;
  108. t2=*this;
  109. flag=;//前面的小
  110. }
  111. big=t1.len;
  112. for(i=;i<big;++i){
  113. if(t1.a[i]<t2.a[i]){
  114. j=i+;
  115. while(t1.a[j]==)++j;
  116. --t1.a[j--];
  117. while(j>i)t1.a[j--]+=MAXN;
  118. t1.a[i]+=MAXN+-t2.a[i];
  119. }
  120. else t1.a[i]-=t2.a[i];
  121. }
  122. while(t1.a[t1.len-]==&&t1.len>){
  123. --t1.len;
  124. --big;
  125. }
  126. if(flag)t1.a[big-]=-t1.a[big-];//前面的小,结果为负
  127. return t1;
  128. }
  129. BigNum BigNum::operator*(const BigNum &T)const{//大数*大数
  130. BigNum ret;
  131. int i,j,up;
  132. int temp,temp1;
  133. for(i=;i<len;++i){
  134. up=;
  135. for(j=;j<T.len;++j){
  136. temp=a[i]*T.a[j]+ret.a[i+j]+up;
  137. if(temp>MAXN){
  138. //temp1=temp-temp/(MAXN+1)*(MAXN+1);
  139. temp1=temp%(MAXN+);
  140. up=temp/(MAXN+);
  141. ret.a[i+j]=temp1;
  142. }
  143. else{
  144. up=;
  145. ret.a[i+j]=temp;
  146. }
  147. }
  148. if(up!=)ret.a[i+j]=up;
  149. }
  150. ret.len=i+j;
  151. while(ret.a[ret.len-]==&&ret.len>)--ret.len;
  152. return ret;
  153. }
  154. BigNum BigNum::operator/(const int &b)const{//大数/int
  155. BigNum ret;
  156. int i,down=;
  157. for(i=len-;i>=;--i){
  158. ret.a[i]=(a[i]+down*(MAXN+))/b;
  159. down=a[i]+down*(MAXN+)-ret.a[i]*b;
  160. }
  161. ret.len=len;
  162. while(ret.a[ret.len-]==&&ret.len>)--ret.len;
  163. return ret;
  164. }
  165.  
  166. BigNum BigNum::operator^(const int &n)const{//幂运算
  167. BigNum t,ret();
  168. int i;
  169. if(n<)exit(-);
  170. if(n==)return ;
  171. if(n==)return *this;
  172. int m=n;
  173. while(m>){
  174. t=*this;
  175. for(i=;i<<<=m;i<<=){
  176. t=t*t;
  177. }
  178. m-=i;
  179. ret=ret*t;
  180. if(m==)ret=ret*(*this);
  181. }
  182. return ret;
  183. }
  184. int BigNum::operator%(const int &b)const{//取模
  185. int i,d=;
  186. for(i=len-;i>=;--i){
  187. d=((d*(MAXN+))%b+a[i])%b;
  188. }
  189. return d;
  190. }
  191. bool BigNum::operator>(const BigNum &T)const{//大数与大数比较
  192. int ln;
  193. if(len>T.len)return true;
  194. else if(len==T.len){
  195. ln=len-;
  196. while(a[ln]==T.a[ln]&&ln>=)--ln;
  197. if(ln>=&&a[ln]>T.a[ln])return true;
  198. else return false;
  199. }
  200. else return false;
  201. }
  202. bool BigNum::operator>(const int &t)const{//大数与int比较
  203. BigNum b(t);
  204. return *this>b;
  205. }
  206.  
  207. void BigNum::print(){//输出大数
  208. int i;
  209. printf("%d",a[len-]);
  210. for(i=len-;i>=;--i){
  211. printf("%.4d",a[i]);//%.4d代表4位,不够前面补0
  212. }
  213. printf("\n");
  214. }
  215.  
  216. //int main(){
  217. // char str1[]="2",str2[]="22222222222222222222222222222222222222222222";
  218. // int c=2;
  219. // //scanf("%s%s",str1,str2);
  220. // BigNum a,b,t;
  221. // a=BigNum(str1);
  222. // b=BigNum(str2);
  223. // printf("a=");a.print();
  224. // printf("b=");b.print();
  225. // printf("c=%d\n",c);
  226. // printf("\n");
  227. //
  228. // t=a+b;
  229. // printf("a+b=");t.print();
  230. // t=a-b;
  231. // printf("a-b=");t.print();
  232. // t=a*b;
  233. // printf("a*b=");t.print();
  234. // t=a/c;
  235. // printf("a/c=");t.print();
  236. // printf("\n");
  237. //
  238. // t=a^c;
  239. // printf("a^c=");t.print();
  240. // t=a%c;
  241. // printf("a%%c=");t.print();
  242. //
  243. // a>b?printf("a>b\n"):printf("a<=b\n");
  244. // a>c?printf("a>c\n"):printf("a<=c\n");
  245. //
  246. // return 0;
  247. //}
  248.  
  249. int main()
  250. {
  251. // printf("%.4d\n", 4);
  252. // printf("%04d\n", 4);
  253. int t;
  254. int n;
  255. BigNum base = BigNum();
  256. BigNum ans;
  257. int cas = ;
  258. scanf("%d", &t);
  259. while (t--) {
  260. scanf("%d", &n);
  261. //printf("%d\n", (int)pow(32, n));
  262. ans = base ^ n;
  263. printf("Case #%d: ", ++cas);
  264. ans.print();
  265. //printf("len = %d\n", ans.len * 4);
  266. }
  267. return ;
  268. }
 

hdu 5241 Friends(找规律?)的更多相关文章

  1. HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)

    Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...

  2. hdu 5047 大数找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...

  3. hdu 5106 组合数学+找规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5106 给定n和r,要求算出[0,r)之间所有n-onebit数的和,n-onebit数是所有数位中1的个数. 对 ...

  4. Doom HDU - 5239 (找规律+线段树)

     题目链接: D - Doom  HDU - 5239  题目大意:首先是T组测试样例,然后n个数,m次询问,然后每一次询问给你一个区间,问你这个这段区间的加上上一次的和是多少,查询完之后,这段区间里 ...

  5. hdu 4708(暴力+找规律)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数 ...

  6. hdu 4759 大数+找规律 ***

    题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y  问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...

  7. HDU 5084 HeHe --找规律

    题意: 给出矩阵M,求M*M矩阵的r行c列的数,每个查询跟前一个查询的结果有关. 解法: 观察该矩阵得知,令ans = M*M,则 ans[x][y] = (n-1-x行的每个值)*(n-1+y列的每 ...

  8. HDU 1847 (博弈 找规律) Good Luck in CET-4 Everybody!

    为了提高题解质量还是简单证明一下:3的倍数是必败状态. 如果n % 3 = 1,那么拿走1个石子:如果n % 3 = 2,那么拿走两个石子,都将转移到3的倍数的状态.所以每个必胜状态都有一个后继是必败 ...

  9. HDU 2897 (博弈 找规律) 邂逅明下

    根据博弈论的两条规则: 一个状态是必胜状态当且仅当有一个后继是必败状态 一个状态是必败状态当且仅当所有后继都是必胜状态 然后很容易发现从1开始,前p个状态是必败状态,后面q个状态是必胜状态,然后循环往 ...

  10. hdu 4455 Substrings(找规律&DP)

    Substrings Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

随机推荐

  1. Linux三剑客之老二-------sed命令详解

    sed命令 文件 编辑 本文索引 [隐藏] sed的选项.命令.替换标记 选项 参数 sed命令 sed替换标记 sed元字符集 sed用法实例 替换操作:s命令 全面替换标记g 定界符 删除操作:d ...

  2. MySQL中too many connections超出最大连接数的处理方法

    MySQL最大连接数的问题 在MySQL的源码中,默认最大的连接数是16384 {"max_connections", OPT_MAX_CONNECTIONS, "The ...

  3. 解决\build\outputs\apk\dream-debug.apk does not exist on disk错误

    \build\outputs\apk\dream-debug.apk does not exist on disk.错误,apk一直装不到手机里. 最有效的解决方法:Build>Buid APK

  4. Python之正则表达式与常用模块(Day19)

    一.正则表达式:匹配字符串的一种规则 正则表达式的在线测试工具: http://tool.chinaz.com/regex/ 字符组: 正则 待匹配字符 匹配结果 说明 [0123456789] 8 ...

  5. python中颜色设置

    实现过程: 终端的字符颜色使用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关. 转义序列是以ESC开头,即用\033来表示(ESC是ASCII码用十进制表示是27,用八进制表示就是033 ...

  6. 【整理学习Hadoop】Hadoop学习基础之二:分布式

      分布式系统就是将系统的应用层,数据层或其它部分构架成分布(物理和逻辑上的都可以)状(通常是网状).分布式系统通常是为了增强系统的可扩展性.稳定性和执行效率.比如在线游戏通常就是分布系统,里面所谓的 ...

  7. 解释python中join()和split()函数

    join能让我们将指定字符添加至字符串中 a=') print(a) print(type(a)) #1,2,3,4,5,6 #<class 'str'> split()能让我们用指定字符 ...

  8. Hibernate学习---关联关系映射

    关联关系是用到的最多的一种关系,非常重要,在内存中反映为实体关系,映射到DB中主键外键关系,实体间的关联,即对外键的维护,关联关系的发生,即对外键数据的改变. 在这里就不赘述什么是外键什么是主键了. ...

  9. 乐思启慧教学系列—Bootstrap布局规则

    1外层变化,内层相应变化规则 col-md-6 col-md-4 外层6变成12,扩大了2倍,里面就得缩小2倍(除以2), 只有这样才能保持外部变化了,内部依然对齐 col-md-12 col-md- ...

  10. java基础—— Collections.sort的两种用法

    package com.jabberchina.test; import java.util.ArrayList; import java.util.Collections; import java. ...