luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/NOEL #727

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Cây thông Noel - Luyện Code Online

https://luyencode.net/problem/NOEL

Conan286 commented 2 years ago

code AC cho mn tham khảo: https://github.com/huykhalac/1000baicpp/blob/main/caythongnoel.cpp

vanhoc98 commented 2 years ago

Thế để in ra cây thông noel theo chiều cao nhập vào bằng C# thì làm ntn ạ

ghost commented 2 years ago

Đây là lời giải của mình đã AC. Nếu bạn đã cố gắng mà chưa làm được thì có thể tham khảo lời giải của mình.

Xem code AC

```cpp #include #define FOR(i, l, r) for(int i = l; i <= r; ++i) #define FOD(i, l, r) for(int i = l; i >= r; --i) #define ll long long #define ug unsigned long long using namespace std; // Topic variable. int n; // Auxiliary variable. char L[100][100]; char t = '#', x = 'x', c = '.'; int wth, hig, top1, top2, top3, mid; //___________________ bool check(char k) { return k == t || k == x; } void setup() { wth = 2*n + 3; hig = wth + n; // 3*n + 3. top1 = 1; top2 = n + 1; top3 = 2*top2; mid = wth / 2 + 1; L[top1][mid] = t; L[top2][mid] = t; L[top3][mid] = t; } void solve() { FOR(i, 1, hig) { if (i == top1 || i == top2 || i == top3) { FOR(j, 1, wth) { if (L[i][j] != t) { cout << c; } else { cout << t; } } } else { FOR(j, 1, wth) { if (L[i][j] != t && L[i][j] != x) { if (check(L[i][j-1]) && check(L[i-1][j])) { L[i][j] = x; } else { if (L[i-1][j-1] == t || L[i-1][j+1] == t) { L[i][j] = t; } else { L[i][j] = c; } } } cout << L[i][j]; } } cout << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; setup(); solve(); return 0; } ``` // Code by Obitidev, from THPT Doi Can.