題目:
題解:
/* 1006 等差數列 */
#include
#define debug
#define maxsize 100
int n; /* 資料大小 */
intarray[maxsize]; /* 所有數值 */
int maxcount; /* 最大計數 */
int darray[maxsize]; /* 差值陣列 */
/* 交換陣列位置 */
void swap(int a, int b)
/* 按值順序排列陣列 */
void sort(int s)}}
} /* 判斷數值是否存在於樣本中, 存在返回位置,否則返回0 */
int in_array(int start, int x)
if(x == array[i])
}return
0;}
/* 依次遍歷陣列 */
void get_darray(int start)
}/* 遍歷樣本,獲取最長的等差數列 */
for(i = 0; i < di; i++)
else
}maxcount = (count > maxcount) ? count : maxcount;
}} /* 主函式入口 */
int main(int argc, char *argv)
#endif
/* 獲取資料樣本大小 */
#ifdef debug
fscanf(fp, "%d", &n);
#else
scanf("%d", &n);
#endif
/* 獲取資料樣本 */
for(i = 0; i < n; i++)
/* 排序資料樣本 */
sort(n);
/* 設定最長等差數列初值 */
maxcount = 1;
/* 依次獲取所有可能的等差數列 */
for(i = 0; i < n - 1; i++)
get_darray(i);
printf("%d", maxcount);
#ifdef debug
fclose(fp);
#endif
return
0;}
codevs 1006 等差數列
題目描述 給定n 1 n 100 個數,從中找出盡可能多的數使得他們能夠組成乙個等差數列.求最長的等差數列的長度.輸入描述 第一行是乙個整數n,接下來一行包括了n個數,每個數的絕對值不超過10000000.輸出描述 對於每個輸入資料,輸出你所找出的最長等差數列的長度 樣例輸入73 8456 22樣例...
codevs 1006 等差數列
時間限制 1 s 空間限制 128000 kb 題目等級 gold description 給定n 1 n 100 個數,從中找出盡可能多的數使得他們能夠組成乙個等差數列.求最長的等差數列的長度.輸入描述 input description 第一行是乙個整數n,接下來一行包括了n個數,每個數的絕對值...
codevs 1006 等差數列
題目描述 description 給定n 1 n 100 個數,從中找出盡可能多的數使得他們能夠組成乙個等差數列.求最長的等差數列的長度.輸入描述 input description 第一行是乙個整數n,接下來一行包括了n個數,每個數的絕對值不超過10000000.輸出描述 output descr...