hdu 5241 Friends(找规律?)
Friends
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1350 Accepted Submission(s): 634
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.
For each test case, the first line contains an integer n(0≤n≤3000), denoting the number of languages.
0
2
Case #2: 1024
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(找规律?)的更多相关文章
- HDU 2086 A1 = ? (找规律推导公式 + 水题)(Java版)
Equations 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 ——每天在线,欢迎留言谈论. 题目大意: 有如下方程:Ai = (Ai-1 ...
- hdu 5047 大数找规律
http://acm.hdu.edu.cn/showproblem.php?pid=5047 找规律 信kuangbin,能AC #include <stdio.h> #include & ...
- hdu 5106 组合数学+找规律
http://acm.hdu.edu.cn/showproblem.php?pid=5106 给定n和r,要求算出[0,r)之间所有n-onebit数的和,n-onebit数是所有数位中1的个数. 对 ...
- Doom HDU - 5239 (找规律+线段树)
题目链接: D - Doom HDU - 5239 题目大意:首先是T组测试样例,然后n个数,m次询问,然后每一次询问给你一个区间,问你这个这段区间的加上上一次的和是多少,查询完之后,这段区间里 ...
- hdu 4708(暴力+找规律)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4708 思路:由于N不大,并且我们可以发现通过旋转得到的4个对角线的点的位置关系,以及所要旋转的最小步数 ...
- hdu 4759 大数+找规律 ***
题目意思很简单. 就是洗牌,抽出奇数和偶数,要么奇数放前面,要么偶数放前面. 总共2^N张牌. 需要问的是,给了A X B Y 问经过若干洗牌后,第A个位置是X,第B个位置是Y 是不是可能的. Ja ...
- HDU 5084 HeHe --找规律
题意: 给出矩阵M,求M*M矩阵的r行c列的数,每个查询跟前一个查询的结果有关. 解法: 观察该矩阵得知,令ans = M*M,则 ans[x][y] = (n-1-x行的每个值)*(n-1+y列的每 ...
- HDU 1847 (博弈 找规律) Good Luck in CET-4 Everybody!
为了提高题解质量还是简单证明一下:3的倍数是必败状态. 如果n % 3 = 1,那么拿走1个石子:如果n % 3 = 2,那么拿走两个石子,都将转移到3的倍数的状态.所以每个必胜状态都有一个后继是必败 ...
- HDU 2897 (博弈 找规律) 邂逅明下
根据博弈论的两条规则: 一个状态是必胜状态当且仅当有一个后继是必败状态 一个状态是必败状态当且仅当所有后继都是必胜状态 然后很容易发现从1开始,前p个状态是必败状态,后面q个状态是必胜状态,然后循环往 ...
- hdu 4455 Substrings(找规律&DP)
Substrings Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
随机推荐
- mprotect() failed: Cannot allocate memory
遇到这个问题是在測试项目的性能时发现的,每一个对象分配一页大小的空间然后mprotect() 保护起来,当系统分配3W多个页的时候会出现这个问题. google到在一份邮件列表中也曾提到该问题.htt ...
- Linux中的grep和cut
提取行: grep --color 着色 -v 不包含 提取列: cut -f 列号 提取第几列 -d 分隔符 以什么为分隔符,默认是制表键 局限性:如果分隔符不那 ...
- Linux中权限管理之sudo权限
1.suodo的操作对象是系统命令 2.root把本来只能是超级用户执行的命令赋予普通用户执行 3.设置sudo权限 命令:visudo 找到: ## Allow root to run any co ...
- Linux学习笔记(1)linux的开关机及重启
linux的启动流程 一.启动 (1)电源 开关 (2)选择启动方式:FLOPPY/BIOS/CDROM(软盘/bios启动/光盘) 基于MBR引导方式 [1]MBR:最多只能划分4个主分区,逻辑 ...
- 剑指offer 面试51题
面试51题: 题目:数组中的逆序对 题目描述 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数P.并将P对1000000007 ...
- KVM虚拟化虚拟机支持虚拟化
一.开启的时候需要关闭所有虚拟机: 首先检查 KVM host(宿主机/母机)上的kvm_intel模块是否打开了嵌套虚拟机功能(默认是开启的): 1.modinfo kvm_intel | grep ...
- Redis慢查询,redis-cli,redis-benchmark,info
一.慢查询: 1.慢查询的作用:通过慢查询分析,找到有问题的命令进行优化. 2.慢查询的redis的配置参数: slowlog-log-slower-than 慢查询预设阈值(单位是微秒1秒=1000 ...
- C++ IPv4与IPv6的兼容编码(转,出自http://blog.csdn.net/ligt0610/article/details/18667595)
这里不再对IPv6 socket相关编程的基础知识进行讲解,只提供一个IP协议无关的服务端和客户端的代码,仅供参考. 服务端代码: #include <iostream> #include ...
- iMX6 yocto平台QT交叉编译环境搭建
转:https://blog.csdn.net/morixinguan/article/details/79351909 . /opt/fsl-imx-fb/4.9.11-1.0.0/environm ...
- Hadoop单机搭建
单机Hadoop搭建 1.下载hadoop-2.7.3.tar.gz http://www.apache.org/dyn/closer.cgi/hadoop/common/hadoop-2.7.3/h ...