苦逼的周大爷

博客园 首页 联系 订阅 管理

Description

 

    已知递推数列:


试求该数列的第n项,并统计出前n项哪些项最大,最大值是多少?

 

 

Input

 

本题有多组测试数据,第一行是测试数据组数T,下面T行的每一行有一个整数n,表示所求的项。1<=n<=50000。

 

Output

 

输出共有T行,依次对应输入行。每行第一个数是第n项值,第2个数是前n项的最大值,紧接是数m,表示取最大值的项数,随后是m项的下标,注意每个数后应有一个空格。

 

Sample Input

 

1
500

 

Sample Output

 

11 55 2 341 427

我的正确解法:

 1 #include <stdio.h>
 2 #include <math.h>
 3 int n,i,j,k,b[60000],c[60000],s;
 4 int t[60000];
 5 int as(int i)
 6 {
 7     if (i==1) return(1);
 8     if (i>1)
 9     {
10         if (i % 2 == 0) return(as(i/2));
11         if (i % 2 == 1) return(as((i-1)/2)+as((i+1)/2));
12     }
13 }
14 
15 int main()
16 {
17     scanf("%d",&n);
18     for (i=0;i<n;i++) scanf("%d",&t[i]);
19     for (s=0;s<n;s++)
20     {
21     for (j=1;j<=t[s];j++) b[j]=as(j);
22     int max=0;
23     for (i=1;i<=t[s];i++){
24         if (b[i]>max) max=b[i];
25     }
26     int k=0;
27     for (i=1;i<=t[s];i++){
28         if (b[i]==max) {
29             k++;
30             c[k]=i;
31         }
32     }
33     printf("%d %d %d ",b[t[s]],max,k);
34     for (j=1;j<=k;j++) printf("%d ",c[j]);
35     printf("\n");
36 }
37 }

 

posted on 2013-10-14 19:56  苦逼的周大爷  阅读(778)  评论(0编辑  收藏  举报