-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
338 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,42 @@ | ||
#include <iostream> | ||
#include <queue> | ||
#include <vector> | ||
#include <string> | ||
using namespace std; | ||
struct TREE { | ||
int left, right; | ||
}; | ||
struct node{ | ||
int l, r; | ||
}a[100]; | ||
int maxn = -1, ans; | ||
void dfs(int root, int index) { | ||
if(index > maxn) { | ||
maxn = index; | ||
ans = root; | ||
} | ||
if(a[root].l != -1) dfs(a[root].l, index * 2); | ||
if(a[root].r != -1) dfs(a[root].r, index * 2 + 1); | ||
} | ||
int main() { | ||
int n, root = 0; | ||
scanf("%d", &n); | ||
vector<TREE> tree(n); | ||
vector<int> book(n); | ||
for(int i = 0; i < n; i++) { | ||
int n, root = 0, have[100] = {0}; | ||
cin >> n; | ||
for (int i = 0; i < n; i++) { | ||
string l, r; | ||
cin >> l >> r; | ||
if(l == "-") { | ||
tree[i].left = -1; | ||
if (l == "-") { | ||
a[i].l = -1; | ||
} else { | ||
tree[i].left = stoi(l); | ||
book[tree[i].left] = 1; | ||
a[i].l = stoi(l); | ||
have[stoi(l)] = 1; | ||
} | ||
if(r == "-"){ | ||
tree[i].right = -1; | ||
if (r == "-") { | ||
a[i].r = -1; | ||
} else { | ||
tree[i].right = stoi(r); | ||
book[tree[i].right] = 1; | ||
} | ||
} | ||
for(int i = 0; i < n; i++) { | ||
if(book[i] == 0) { | ||
root = i; | ||
break; | ||
} | ||
} | ||
queue<int> q; | ||
q.push(root); | ||
int cnt = 0, lastnode = 0; | ||
while(!q.empty()) { | ||
int node = q.front(); | ||
q.pop(); | ||
if(node != -1) { | ||
lastnode = node; | ||
cnt++; | ||
}else { | ||
if(cnt != n) | ||
printf("NO %d", root); | ||
else | ||
printf("YES %d", lastnode); | ||
return 0; | ||
a[i].r = stoi(r); | ||
have[stoi(r)] = 1; | ||
} | ||
q.push(tree[node].left); | ||
q.push(tree[node].right); | ||
} | ||
while (have[root] != 0) root++; | ||
dfs(root, 1); | ||
if (maxn == n) | ||
cout << "YES " << ans; | ||
else | ||
cout << "NO " << root; | ||
return 0; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,27 @@ | ||
include <iostream> | ||
#include <iostream> | ||
using namespace std; | ||
int main() { | ||
int N; | ||
cin >> N; | ||
int N, row = 0; | ||
char c; | ||
cin >> c; | ||
//计算行数row,只计算一半的行数,不包括最中间的那个一个符号 | ||
int row = 0; | ||
for (int i = 1; i < N; i++) { | ||
cin >> N >> c; | ||
for (int i = 0; i < N; i++) { | ||
if ((2 * i * (i + 2) + 1) > N) { | ||
row = i - 1; | ||
break; | ||
} | ||
} | ||
// 打印上半部分 | ||
for (int i = row; i >= 1; i--) { | ||
for (int k = row - i; k >= 1; k--) { | ||
cout << " "; | ||
} | ||
for (int j = i * 2 + 1; j >= 1; j--) { | ||
cout << c; | ||
} | ||
for (int k = row - i; k >= 1; k--) cout << " "; | ||
for (int j = i * 2 + 1; j >= 1; j--) cout << c; | ||
cout << endl; | ||
} | ||
// 打印中间的那个符号 | ||
for (int i = 0; i < row; i++) { | ||
cout << " "; | ||
} | ||
for (int i = 0; i < row; i++) cout << " "; | ||
cout << c << endl; | ||
// 打印下半部分 | ||
for (int i = 1; i <= row; i++) { | ||
for (int k = row - i; k >= 1; k--) { | ||
cout << " "; | ||
} | ||
for (int j = i * 2 + 1; j >= 1; j--) { | ||
cout << c; | ||
} | ||
for (int k = row - i; k >= 1; k--) cout << " "; | ||
for (int j = i * 2 + 1; j >= 1; j--) cout << c; | ||
cout << endl; | ||
} | ||
// 输出还剩下几个符号没有用 | ||
cout << (N - (2 * row * (row + 2) + 1)); | ||
cout << (N - (2 * row * (row + 2) + 1)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.