ZZU 省赛第二题 最强战斗力

View Code
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h>
 4 
 5 int main()
 6 {
 7    int i, j, ncases,n,m,k, T;
 8    int a[200], b[350], c;
 9    
10    scanf("%d",&ncases);
11   while( ncases-- )
12   {
13     scanf("%d",&T);
14     memset(a,0,sizeof(a));
15     for(i=0; i<350; i++)
16       b[i] = 3; 
17       a[0] = 1;
18     if(T%3 == 0)
19     {
20        n = T/3;       
21       for(i=0; i<n; i++)
22       {
23          c = 0;
24         for(j=0; j<200; j++)    
25         {
26            m = a[j]*b[i] + c;
27            a[j] = m%10;
28            c = m/10;  
29         }  
30       }  
31     }
32     else if(T%3 == 1)
33     {
34       n = T/3 - 1;  
35       for(i=0; i<n; i++)
36       {
37            c = 0;
38          for(j=0; j<200; j++)
39          {
40              m = a[j]*b[i] + c;
41              a[j] = m%10;         
42              c = m/10;
43          }  
44       }  
45       for(i=0; i<2; i++)
46       {
47         c = 0;
48         for(j=0; j<200; j++)    
49         {
50            m = a[j]*2 + c;
51            a[j] = m%10;       
52            c = m/10;      
53         }
54       }
55     }             
56     else if(T%3 == 2)
57     {
58        n = T/3; 
59       for(i=0; i<n; i++)
60       {
61                c = 0;
62          for(j=0; j<200; j++)
63          {          
64             m = a[j]*3 + c;
65             a[j] = m%10;
66             c = m/10;
67          }
68       }
69       c = 0;
70       for(j=0; j<200; j++)
71       {
72          m = a[j]*2 + c;
73          a[j] = m%10;
74          c = m/10;
75       }       
76     } 
77     for(k=199; k>=0; k--)
78     {
79       if(a[k] != 0)
80         break;
81    } 
82    for(i=k; i>=0; i--)
83    { 
84      printf("%d",a[i]); 
85    }
86    printf("\n");
87  }
88   return 0;
89 }

 

整数划分问题,就是求竟可能多的3和2

posted @ 2012-05-24 15:34  zhongya  阅读(118)  评论(0编辑  收藏  举报