(A - 整数划分 HYSBZ - 1263)(数组模拟大数乘法)

题目链接:https://cn.vjudge.net/problem/HYSBZ-1263

题目大意:中文题目

具体思路:先进了能的拆成3,如果当前剩下的是4,就先不减去3,直接乘4,如果还剩2的话,也乘2。

如果当n==4的时候,我们将n拆成2*2.如果当n>=5的时候,如果按照4拆的话,显然不如3*2的数大.

AC代码:

 1 #include<iostream>
 2 #include<stack>
 3 #include<stdio.h>
 4 #include<cstring>
 5 #include<string>
 6 #include<cmath>
 7 #include<algorithm>
 8 using namespace std;
 9 # define ll long long
10 const int maxn = 3e4+2000;
11 int sto[maxn];
12 int p=5010;
13 void cal(int t)
14 {
15     sto[p]*=t;
16     for(int i=p; i>=2; i--){
17         sto[i-1]=t*sto[i-1]+sto[i]/10;
18         sto[i]%=10;
19     }
20 }
21 int main()
22 {
23     int n;
24     scanf("%d",&n);
25     sto[p]=3;
26     n-=3;
27     while(n){
28         if(n==4){
29             cal(4);n-=4;
30         }
31         else  if(n==2){
32             cal(2);n-=2;
33 
34         }
35         else{
36             cal(3);
37             n-=3;
38         }
39     }
40     p=1;
41     while(sto[p]==0)
42         p++;
43         printf("%d\n",5010-p+1);
44     for(int i=p; i<=min(p+100-1,5010); i++)//要求输出前100位
45     {
46         printf("%d",sto[i]);
47     }
48     printf("\n");
49     return 0;
50 }

猜你喜欢

转载自www.cnblogs.com/letlifestop/p/10307188.html