[华为oj]iNOC产品部-杨辉三角的变形

             1

         1  1  1

      1  2  3  2  1

   1  3  6  7  6  3  1

1  4  10 16 19  16 10  4  1

以上三角形的数阵,第一行只有一个数1,以下每行的每个数,是恰好是它上面的数,左上角数到右上角的数,3个数之和(如果不存在某个数,认为该数就是0)。

求第n行第一个偶数出现的位置。如果没有偶数,则输出-1。例如输入3,则输出2,输入4则输出3。

 1 #include <iostream>
 2 #include <deque>
 3 
 4 using namespace std;
 5 
 6 static deque<int> deInt;
 7 
 8 void getOddPos(int count)
 9 {
10     count=count-1;
11 
12     deInt.push_front(0);
13     deInt.push_front(0);
14     deInt.push_back(0);
15     deInt.push_back(0);
16 
17     deque<int> temp;
18     for(int i=1;i<static_cast<int>(deInt.size())-1;i++)
19     {
20         int t=deInt.at(i-1)+deInt.at(i)+deInt.at(i+1);
21         if(count<=0)
22         {
23             if(t%2==0)
24             {
25                 cout<<i<<endl;
26                 return;
27             }
28         }
29         temp.push_back(t);
30     }
31     if(count<=0)
32     {
33         cout<<-1<<endl;
34         return;
35     }
36 
37     deInt.clear();
38     deInt.insert(deInt.begin(),temp.begin(),temp.end());
39     temp.clear();
40     getOddPos(count);
41 }
42 
43 int main()
44 {
45     deInt.push_back(1);
46     int r;
47     cin>>r;
48     if(r==1)
49         cout<<-1;
50     else
51     {
52         --r;
53         getOddPos(r);
54     }
55 }
原文地址:https://www.cnblogs.com/lsr-flying/p/4776740.html