我发这题只是想说明:有时候确实需要用水题来找找自信的~
代码如下:
1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 using namespace std; 5 typedef long long ll; 6 7 int num[1000+5] = {0,3,3,5,4,4,3,5,5,4,3,6,6,8,8,7,7,9,8,8,6}; 8 int sum[1000+5]; 9 10 void init() 11 { 12 for(int i=21;i<=29;i++) num[i] = 6 + num[i-20]; 13 num[30] = 6; 14 for(int i=31;i<=39;i++) num[i] = 6 + num[i-30]; 15 num[40] = 5;num[50] = 5;num[60] = 5;num[70] = 7;num[80] = 6;num[90] = 6; 16 for(int i = 40;i<=99;i++) 17 { 18 if(i%10==0) continue; 19 else num[i] = num[i-i%10] + num[i%10]; 20 } 21 num[100] = 10; 22 for(int i=101;i<=999;i++) 23 { 24 if(i%100==0) 25 { 26 num[i] = num[i/100] + 7; 27 } 28 else 29 { 30 num[i] = 3; 31 num[i] += num[i-i%100] + num[i%100]; 32 } 33 } 34 num[1000] = 11; 35 for(int i=1;i<=1000;i++) sum[i] = sum[i-1] + num[i]; 36 } 37 38 int main() 39 { 40 init(); 41 int T;scanf("%d",&T); 42 while(T--) 43 { 44 int n;scanf("%d",&n); 45 printf("%d\n",sum[n]); 46 } 47 }
时间: 2024-11-07 21:43:07