HDU 5241 Friends(大数+快速幂)
FriendsTime Limit: 2000/1000 MS (Java/Others)????Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1356????Accepted Submission(s): 639
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? 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?
For each test case,the first line contains an integer?
?
Output
For each test case,output ''Case #t:'' to represent this is the t-th case. And then output the answer.
?
Sample Input
?
Sample Output
?
Source
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest
?
Recommend
题意 :(原帖here)? 这道题看输入输出第一想法就是把N为1的输出手推出来,然后推了两次都没推对 T.T。 对于每一种语言来说,这种语言谁会谁不会是的方案数一定,而且语言之间相互独立的,互相之间通过乘法原理来计算方案数,这样就一定是某一个数的n次方? 我只想说做的时候真心没想到竟然是这么一道“有内涵”的题目,还是被学弟学妹手把手教会的,真心没想到。。。 之前的模板都乱了,今天发现之前整理的这个还是挺好的!!!here #include<iostream> #include<stdio.h> #include<stdlib.h> #include<string.h> using namespace std; #define MAXN 9999//万进制 #define DLEN 4//4位 class BigNum { private: int a[40000];///可以控制大数位数(500*4) int len;///大数长度 public: BigNum() ///构造函数 { len=1; memset(a,sizeof(a)); } BigNum(const int b) ///将int转化为大数 { int c,d=b; len=0; memset(a,sizeof(a)); while(d>MAXN) { ///c=d-(d/(MAXN+1))*(MAXN+1); c=d%(MAXN+1);///取出后四位 d=d/(MAXN+1);// a[len++]=c; } a[len++]=d; } BigNum operator*(const BigNum &T)const //大数*大数 { BigNum ret; int i,j,up; int temp,temp1; for(i=0; i<len; ++i) { up=0; for(j=0; 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+1); up=temp/(MAXN+1); ret.a[i+j]=temp1; } else { up=0; ret.a[i+j]=temp; } } 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; } void print() //输出大数 { int i; printf("%d",a[len-1]); for(i=len-2; i>=0; --i) { printf("%.4d",a[i]);///%.4d代表4位,不够前面补0 } printf("n"); } }; int main() { //freopen("out.txt","w",stdout); int n,T,Case=1; scanf("%d",&T); while(T--) { scanf("%d",&n); BigNum a(32),ans(1); while(n>0) { if(n&1) ans=ans*a; if(n==0) break; a=a*a; n=n>>1; } printf("Case #%d: ",Case++); ans.print(); } return 0; } Java都忘差不多了,不过代码相当清爽!!! import java.util.*; import java.math.*; public class Main { static public void main(String[]args) { Scanner cin = new Scanner(System.in); int T = cin.nextInt(); for (int i = 1; i <= T; i++) { int n = cin.nextInt(); System.out.printf("Case #%d: ",i); System.out.println(BigInteger.valueOf(32).pow(n)); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |