蓝桥杯真题 杨辉三角形 C++
生活随笔
收集整理的這篇文章主要介紹了
蓝桥杯真题 杨辉三角形 C++
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本來的思路是想用兩個隊列存儲每行的值,但是部分測試用例會運行超時,最后只有40分。
#include<iostream> #include<queue> using namespace std; int N; int site = 0; void display(queue<int> q) {while (!q.empty()) {cout << q.front() << " ";q.pop();}cout << endl; } int main() {int line = 2;cin >> N;if (N == 1) {cout << 1 << endl;return 0;}queue<int> q1;q1.push(1);q1.push(1);queue<int> q2;int flag = 1;//表示隊列q1不為空int a, b;while (true) {line++;if (flag == 1) {q2.push(1); while (q1.size() > 1) {a = q1.front();q1.pop();b &#總結
以上是生活随笔為你收集整理的蓝桥杯真题 杨辉三角形 C++的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android绘制(三):Path结合属
- 下一篇: 小白学git2