9 条题解

  • 3
    @ 2021-12-15 19:27:40
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    char ans[10000];
    int d = 10000;
    int n;
    int main() {
    	cin >> n;
    	memset(ans, -1, 10000);
    	ans[0] = 2;
    	for (int i = 1; i < n; i++) {
    
    		for (int j = 0; ans[j] != -1; j++) {
    			ans[j] *= 2;
    		}
    		for (int j = 0; ans[j] != -1; j++) {
    
    			if (ans[j] > 9) {
    				if (ans[j + 1] == -1) {
    					ans[j + 1] = 0;
    				}
    				ans[j + 1] += ans[j] / 10;
    				ans[j] %= 10;
    			}
    
    		}
    	}
    	int sum = 0;
    	for (int i = 0; ans[i] != -1; i++) {
    		sum++;
    	}
    	for (int i = sum - 1; i >= 0; i--) {
    		cout << (char)(ans[i] + '0');
    	}
    
    	return 0;
    }
    
    • 2
      @ 2023-11-25 20:59:40

      #include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; int a[N],len,x; int main() { cin >> n; a[++len]=1; while(n--) { for(int i = 1; i <= len;i++) { a[i] = a[i]*2+x; x = a[i]/10; a[i] %= 10; } if(x) a[++len]=x; x = 0; } for(int i = len;i >= 1;i--) { cout <<a[i]; }

      return 0;
      

      }

      • 1
        @ 2023-11-25 20:59:47
        #include<iostream>
        #include<cstdio>
        #include<iomanip>
        #include<cmath>
        #include<cstring>
        #include<string>
        #include<stack>
        #include<queue>
        #define LL long long
        const int N=1e3+10;
        const int INT=0x3f3f3f3f;
        using namespace std;
        int a[N],n,len,x;
        int main(){
        	cin>>n;
        	a[++len]=1;
        	while(n--){
        		for(int i=1;i<=len;i++){
        			a[i]=a[i]*2+x;
        			x=a[i]/10;
        			a[i]%=10;
        		}
        		if(x){
        			a[++len]=x;
        		}
        		x=0;
        	}
        	for(int i=len;i>=1;i--){
        		cout<<a[i];
        	}
        	return 0;
        }
        
        • 1
          @ 2023-10-25 20:29:17

          #include <iostream> #include <string> #include <cstring> #include <algorithm> using namespace std; char ans[10000]; int d = 10000; int n; int main() { cin >> n; memset(ans, -1, 10000); ans[0] = 2; for (int i = 1; i < n; i++) {

          for (int j = 0; ans[j] != -1; j++) {
          		ans[j] *= 2;
          	}
          	for (int j = 0; ans[j] != -1; j++) {
          
          		if (ans[j] > 9) {
          			if (ans[j + 1] == -1) {
          				ans[j + 1] = 0;
          			}
          			ans[j + 1] += ans[j] / 10;
          			ans[j] %= 10;
          		}
          
          	}
          }
          int sum = 0;
          for (int i = 0; ans[i] != -1; i++) {
          	sum++;
          }
          for (int i = sum - 1; i >= 0; i--) {
          	cout << (char)(ans[i] + '0');
          }
          
          return 0;
          

          }

          • 0
            @ 2024-3-17 16:01:40
            #include <iomanip>
            #include <cmath>
            #include <cstdio>
            #include <cstring>
            #include <algorithm>
            #include <string>
            using namespace std;
            const int N=1e5+10;
            const int INF=0x3f3f3f3f;
            string a,b;
            int lena,lenb,lenc,a1[N],b1[N],c1[N],x;
            int main(){
            	cin>>a>>b;
            	lena=a.size();
            	lenb=a.size();
            	for(int i=0;i<lena;i++){
            		a1[i]=a[lena-i-1]-'0';
            	}
            	for(int i=0;i<lenb;i++){
            		b1[i]=b[lenb-i-1]-'0';
            	}
            	for(int i=0;i<lenb;i++){
            		x=0;
            		for(int j=0;j<lena;j++){
            			c1[i+j]+=a1[j]*b1[i]+x;
            			x=c1[i+j]/10;
            			c1[i+j]%=10;
            		}
            		c1[lena+i]=x;
            	}
            	lenc=lena+lenb;
            	while(c1[lenc]==0&&lenc>0){
            		lenc--;
            	}
            	for(int i=lenc;i>=0;i--){
            		cout<<c1[i];
            	}
            return 0;
            }
            
            
            • 0
              @ 2023-12-24 20:16:27
              #include<bits/stdc++.h>
              using namespace std;
              #define LL long long
              int n,a[105],len;
              int x;
              int main(){
                  cin>>n;
                  a[++len]=1;
                  while(n--){
                  	for(int i=1;i<=len;i++){
                  		a[i]=a[i]*2+x;
                  		x=a[i]/10;
                  		a[i]%=10;
                  	} 
                  	if(x){
                  		a[++len]=x;
                  	}
                  	x=0;
                  }
                  for(int i=len;i>=1;i--){
                  	cout<<a[i];
                  }
              }
              
              • 0

                这道题只要用高精度算法就可以AC

                但是要注意删除前导零和进位,而且数组的第一项要设置为1

                #include<bits/stdc++.h>
                using namespace std;
                int a[100000];
                int len=2,x;
                int r,y;
                int main(){
                	cin>>r;a[1]=1;
                	while(r--){
                		for(int i=1;i<=len;i++){
                			a[i]=a[i]*2+x;
                			x=a[i]/10;
                			a[i]%=10;
                		}
                		if(x!=0)a[++len]=x;
                		x=0;
                	}while(a[len]==0){
                		len--;
                	}
                	for(int i=len;i>=1;i--)cout<<a[i];
                	return 0;
                }
                
                • 0
                  @ 2023-11-25 21:01:48
                  #include<iostream>
                  #include<cstdio>
                  #include<cmath>
                  #include<algorithm>
                  #include<string>
                  #include<cstring>
                  const int INF=0x3f3f3f3f;
                  const int N=1e5+10;
                  using namespace std;
                  int a[N],n,len,x;
                  int main(){
                  	cin>>n;
                  	a[++len]=1;
                  	while(n--)
                  	{
                  		for(int i =1;i<=len;i++ )
                  		{
                  			a[i]=a[i]*2+x;
                  			x=a[i]/10;
                  			a[i]%=10;
                  		}
                  		if(x)
                  		a[++len]=x;
                  		x=0;
                  	}
                  	for(int i=len;i>=1;i--)
                  	{
                  		cout<<a[i];
                  	}
                  	return 0;
                  }
                  
                  • -1
                    @ 2023-9-26 22:36:18
                    #include <stdio.h>
                    #include <string.h>
                    int main()
                    {
                           int n;
                           scanf("%d",&n);
                           int a[35];
                           memset(a,0,sizeof(a));
                           a[1]=1;
                           int i,j,len=1;
                           for(i=1;i<=n;i++)
                           {
                               int cf=0;
                                  for (j=1;j<=len;j++)
                                   {
                                          a[j]=a[j]*2+cf;
                                          cf=a[j]/10;
                    
                                          a[j]=a[j]%10;
                                   }
                                   while (cf!=0)
                                   {
                                          a[++len]=cf%10;
                                          cf/=10;
                                   }
                            }
                         for (i=len;i>=1;i--)
                                     printf("%d",a[i]);
                         printf("\n");
                         return 0;
                    }
                    
                    • @ 2023-9-26 22:36:39

                      当N=100时,2的N次方是一个很大的数,超出了一个长整数的表数范围。因此,为了保存2的N次方,可以定义一个数组int a[35];,每个数组元素a[i]保存结果整数的1位数,例如,保存整数1024时,a[0]=4,a[1]=2,a[2]=0,a[3]=1,并记整数的位数len=4。这样一个整数乘以2,可以将每个数组元素乘以2,同时进行进位处理即可。

                      
                      
                  • 1

                  信息

                  ID
                  1194
                  时间
                  1000ms
                  内存
                  128MiB
                  难度
                  7
                  标签
                  递交数
                  543
                  已通过
                  135
                  上传者