Friend
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2240 Accepted Submission(s): 1122
Problem Description
Friend number are defined recursively as follows.
(1) numbers 1 and 2 are friend number;
(2) if a and b are friend numbers, so is ab+a+b;
(3) only the numbers defined in (1) and (2) are friend number.
Now your task is to judge whether an integer is a friend number.
(1) numbers 1 and 2 are friend number;
(2) if a and b are friend numbers, so is ab+a+b;
(3) only the numbers defined in (1) and (2) are friend number.
Now your task is to judge whether an integer is a friend number.
Input
There are several lines in input, each line has a nunnegative integer a, 0<=a<=2^30.
Output
For the number a on each line of the input, if a is a friend number, output “YES!”, otherwise output “NO!”.
Sample Input
3 13121 12131
Sample Output
YES! YES! NO!
题解:找了半天规律还是没照出来。。。
代码:
1 #include<stdio.h> 2 int main(){ 3 int n; 4 while(~scanf("%d",&n)){ 5 if(!n){puts("NO!");continue;} 6 n++; 7 while(n%2==0||n%3==0){ 8 if(!(n%2))n/=2; 9 else n/=3; 10 } 11 n==1?puts("YES!"):puts("NO!"); 12 } 13 return 0;}
Problem A
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 71 Accepted Submission(s) : 11
Problem Description
In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles?
Here is a sample tiling of a 2x17 rectangle.
Here is a sample tiling of a 2x17 rectangle.
Input
Input is a sequence of lines, each line containing an integer number 0 <= n <= 250.
Output
For each line of input, output one integer number in a separate line giving the number of possible tilings of a 2xn rectangle.
Sample Input
2 8 12 100 200
Sample Output
3 171 2731 845100400152152934331135470251 1071292029505993517027974728227441735014801995855195223534251
代码:
1 #include<stdio.h> 2 #include<string.h> 3 #define MAX(x,y)(x>y?x:y) 4 const int MAXN=10010; 5 char c[MAXN]; 6 char dp[501][MAXN]; 7 void bignum(char *a,char *b){ 8 int A[MAXN],B[MAXN],C[MAXN]; 9 memset(A,0,sizeof(A));memset(B,0,sizeof(B)); 10 memset(C,0,sizeof(C)); 11 int t1=strlen(a),t2=strlen(b); 12 for(int i=0,j=t1-1;j>=0;i++,j--)A[i]=a[j]-'0'; 13 for(int i=0,j=t2-1;j>=0;i++,j--)B[i]=b[j]-'0'; 14 int t=MAX(t1,t2); 15 for(int i=0;i<t;i++){ 16 C[i]=A[i]+B[i]+C[i]; 17 if(C[i]>9)C[i]-=10,C[i+1]++; 18 if(C[t])t++; 19 } 20 int i,j; 21 for(i=0,j=t-1;j>=0;i++,j--){ 22 c[i]=C[j]+'0'; 23 } 24 c[i]='