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写是真鸡儿爽,
import java.util.*;
import java.math.*; public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger base = new BigInteger("32");
int t = sc.nextInt();
int n;
int cas = 0;
while (t-- > 0) {
n = sc.nextInt();
System.out.printf("Case #%d: ", ++cas);
System.out.println(base.pow(n));
}
}
}

用C++模拟也可以,

大数模板来一发,

 /*
整数大数
int数组实现
*/
#include <bits/stdc++.h>
using namespace std; #define MAXN 9999//万进制
#define DLEN 4//4位 class BigNum{
//private:
public:
int a[];//可以控制大数位数(500*4)
int len;//大数长度
public:
BigNum(){//构造函数
len=;
memset(a,,sizeof(a));
}
BigNum(const int);//将int转化为大数
BigNum(const char *);//将字符串转化为大数
BigNum(const BigNum &);//拷贝构造函数
BigNum &operator=(const BigNum &);//重载赋值运算符,大数之间赋值 BigNum operator+(const BigNum &)const;//大数+大数
BigNum operator-(const BigNum &)const;//大数-大数
BigNum operator*(const BigNum &)const;//大数*大数
BigNum operator/(const int &)const;//大数/int BigNum operator^(const int &)const;//幂运算
int operator%(const int &)const;//取模
bool operator>(const BigNum &)const;//大数与大数比较
bool operator>(const int &)const;//大数与int比较 void print();//输出大数
}; BigNum::BigNum(const int b){//将int转化为大数
int c,d=b;
len=;
memset(a,,sizeof(a));
while(d>MAXN){
//c=d-(d/(MAXN+1))*(MAXN+1);
c=d%(MAXN+);//取出后四位
d=d/(MAXN+);//
a[len++]=c;
}
a[len++]=d;
}
BigNum::BigNum(const char *s){//将字符串转化为大数
int t,k,index,l,i,j;
memset(a,,sizeof(a));
l=strlen(s);
len=l/DLEN;
if(l%DLEN)++len;
index=;
for(i=l-;i>=;i-=DLEN){
t=;
k=i-DLEN+;
if(k<)k=;
for(j=k;j<=i;++j)
t=t*+s[j]-'';
a[index++]=t;
}
}
BigNum::BigNum(const BigNum &T):len(T.len){//拷贝构造函数
int i;
memset(a,,sizeof(a));
for(i=;i<len;++i)
a[i]=T.a[i];
}
BigNum &BigNum::operator=(const BigNum &n){//重载复制运算符,大数之间赋值
int i;
len=n.len;
memset(a,,sizeof(a));
for(i=;i<len;++i)
a[i]=n.a[i];
return *this;
} BigNum BigNum::operator+(const BigNum &T)const{//大数+大数
BigNum t(*this);
int i,big;//位数
big=T.len>len?T.len:len;
for(i=;i<big;++i){
t.a[i]+=T.a[i];
if(t.a[i]>MAXN){
++t.a[i+];
t.a[i]-=MAXN+;
}
}
if(t.a[big]!=)t.len=big+;
else t.len=big;
return t;
}
BigNum BigNum::operator-(const BigNum &T)const{//大数-大数
int i,j,big;
bool flag;
BigNum t1,t2;//t1大的,t2小的
if(*this>T){
t1=*this;
t2=T;
flag=;//前面的大
}
else{
t1=T;
t2=*this;
flag=;//前面的小
}
big=t1.len;
for(i=;i<big;++i){
if(t1.a[i]<t2.a[i]){
j=i+;
while(t1.a[j]==)++j;
--t1.a[j--];
while(j>i)t1.a[j--]+=MAXN;
t1.a[i]+=MAXN+-t2.a[i];
}
else t1.a[i]-=t2.a[i];
}
while(t1.a[t1.len-]==&&t1.len>){
--t1.len;
--big;
}
if(flag)t1.a[big-]=-t1.a[big-];//前面的小,结果为负
return t1;
}
BigNum BigNum::operator*(const BigNum &T)const{//大数*大数
BigNum ret;
int i,j,up;
int temp,temp1;
for(i=;i<len;++i){
up=;
for(j=;j<T.len;++j){
temp=a[i]*T.a[j]+ret.a[i+j]+up;
if(temp>MAXN){
//temp1=temp-temp/(MAXN+1)*(MAXN+1);
temp1=temp%(MAXN+);
up=temp/(MAXN+);
ret.a[i+j]=temp1;
}
else{
up=;
ret.a[i+j]=temp;
}
}
if(up!=)ret.a[i+j]=up;
}
ret.len=i+j;
while(ret.a[ret.len-]==&&ret.len>)--ret.len;
return ret;
}
BigNum BigNum::operator/(const int &b)const{//大数/int
BigNum ret;
int i,down=;
for(i=len-;i>=;--i){
ret.a[i]=(a[i]+down*(MAXN+))/b;
down=a[i]+down*(MAXN+)-ret.a[i]*b;
}
ret.len=len;
while(ret.a[ret.len-]==&&ret.len>)--ret.len;
return ret;
} BigNum BigNum::operator^(const int &n)const{//幂运算
BigNum t,ret();
int i;
if(n<)exit(-);
if(n==)return ;
if(n==)return *this;
int m=n;
while(m>){
t=*this;
for(i=;i<<<=m;i<<=){
t=t*t;
}
m-=i;
ret=ret*t;
if(m==)ret=ret*(*this);
}
return ret;
}
int BigNum::operator%(const int &b)const{//取模
int i,d=;
for(i=len-;i>=;--i){
d=((d*(MAXN+))%b+a[i])%b;
}
return d;
}
bool BigNum::operator>(const BigNum &T)const{//大数与大数比较
int ln;
if(len>T.len)return true;
else if(len==T.len){
ln=len-;
while(a[ln]==T.a[ln]&&ln>=)--ln;
if(ln>=&&a[ln]>T.a[ln])return true;
else return false;
}
else return false;
}
bool BigNum::operator>(const int &t)const{//大数与int比较
BigNum b(t);
return *this>b;
} void BigNum::print(){//输出大数
int i;
printf("%d",a[len-]);
for(i=len-;i>=;--i){
printf("%.4d",a[i]);//%.4d代表4位,不够前面补0
}
printf("\n");
} //int main(){
// char str1[]="2",str2[]="22222222222222222222222222222222222222222222";
// int c=2;
// //scanf("%s%s",str1,str2);
// BigNum a,b,t;
// a=BigNum(str1);
// b=BigNum(str2);
// printf("a=");a.print();
// printf("b=");b.print();
// printf("c=%d\n",c);
// printf("\n");
//
// t=a+b;
// printf("a+b=");t.print();
// t=a-b;
// printf("a-b=");t.print();
// t=a*b;
// printf("a*b=");t.print();
// t=a/c;
// printf("a/c=");t.print();
// printf("\n");
//
// t=a^c;
// printf("a^c=");t.print();
// t=a%c;
// printf("a%%c=");t.print();
//
// a>b?printf("a>b\n"):printf("a<=b\n");
// a>c?printf("a>c\n"):printf("a<=c\n");
//
// return 0;
//} int main()
{
// printf("%.4d\n", 4);
// printf("%04d\n", 4);
int t;
int n;
BigNum base = BigNum();
BigNum ans;
int cas = ;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
//printf("%d\n", (int)pow(32, n));
ans = base ^ n;
printf("Case #%d: ", ++cas);
ans.print();
//printf("len = %d\n", ans.len * 4);
}
return ;
}
 

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. Python— 匿名函数

    匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的  “一句话函数” #初始代码 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = ...

  2. pyhon时间输出

    参考博客:http://www.cnblogs.com/xisheng/p/7634125.html http://www.cnpythoner.com/post/89.html 有些时候想要输出,但 ...

  3. bootstrap-select 使用笔记 设置选中值及手动刷新

    直接笔记: 1.页面刚加载完填充select选项数据时,需要手动刷新一下组件,否则没有选项值.(组件初始化时,li 与 option 分离的,需要刷新一下(据说)) $.post('/cpms/tod ...

  4. 解决PowerDesigner 反向工程没有注释(备注)

    1. 列注释 原来代码: {OWNER, TABLE, S, COLUMN, DTTPCODE, LENGTH, SIZE, PREC, COMPUTE, NOTNULL, IDENTITY, DOM ...

  5. spark学习(2)--hadoop安装、配置

    环境: 三台机器 ubuntu14.04 hadoop2.7.5 jdk-8u161-linux-x64.tar.gz (jdk1.8) 架构: machine101 :名称节点.数据节点.Secon ...

  6. Python 2 一些实用模块的使用

    time模块,sys模块,os模块,random模块, shutil模块, json & pickle 模块,re模块 time模块: 在Python中,通常有这几种方式来表示时间:1)时间戳 ...

  7. java的服务端与客户端通信(2)

    一.Socket连接与HTTP连接   1.1Socket套接字 套接字(socket)是通信的基石,是支持TCP/IP协议的网络通信的基本操作单元.它是网络通信过程中端点的抽象表示,包含进行网络通信 ...

  8. Linux Shell基础 位置参数变量、预定义变量

    位置参数变量 在 Linux 的命令行中,当一条命令或脚本执行时,后面可以跟多个参数,我们使用位置参数变量来表示这些参数.其中,$0 代表命令行本身,$1 代表第 1 个参数,$2 代表第 2 个参数 ...

  9. Squid 反向代理配置

    Squid 反向代理配置 1.删除主配置文件重写写入配置 rm -f /etc/squid/squid.conf 2.重新写入配置反向代理 vim /etc/squid/squid.conf # 监听 ...

  10. library-type:fr-unstanded vs fisrt-stand vs second-stanrd

    建库时是否是链特异性建库. Tophat2: --library-type The default is unstranded (fr-unstranded). If either fr-firsts ...