有這樣一個序列(1) (1 2 1) (1 2 3 2 1) (1 2 3 4 3 2 1) (1 2 3 … n n-1 … 3 2 1)。
問你第N個數(shù)是什么?
(括號是為了方便大家觀看,請忽略掉括號)
輸入 有多組測試數(shù)據(jù),請?zhí)幚淼轿募Y(jié)束。
每組數(shù)據(jù)給定一個整數(shù)N(1 <= N <= 10^9),表示要查找的數(shù)。
輸出 每組數(shù)據(jù)輸出一個整數(shù),表示序列中的第N個數(shù)。
樣例輸入 1 2 3 樣例輸出 1 1 2
#include<cstdio>#include<cstring>#include<cmath>#include<stack>#include<queue>#include<algorithm>using namespace std;#define INF 0x3f3f3f3f#define ll long long#define maxn 1000000005int a[10005];int main(){ int n; while (~scanf("%d",&n)){ int temp=1; int t; int b; for (int i = 1 ; i <= n ; i+=temp){ temp+=2; if (n > i && n <= i+temp){ t = i; break; } } if (n!=1) n = n-t; if (n > temp/2+1) n=temp%n+1; 冷靜下來找規(guī)律 一開始竟然想打表 一個數(shù)組是不能開得那么大的。。新聞熱點
疑難解答