日常训练17-10-15
Posted yijiull
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了日常训练17-10-15相关的知识,希望对你有一定的参考价值。
题目链接:here
Text Editor
emmm...又是链表都写不溜=_=||
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e6+10; 4 int L[maxn], R[maxn]; 5 char s[maxn]; 6 char ans[maxn]; 7 8 int main(){ 9 //freopen("in.txt", "r", stdin); 10 memset(L, -1, sizeof(L)); 11 memset(R, -1, sizeof(R)); 12 scanf("%s", s); 13 int now = 0; 14 int cnt = 0; 15 int n = strlen(s); 16 for(int i = 0; i < n; i++){ 17 if(s[i] == ‘L‘){ 18 if(L[now] != -1) now = L[now]; 19 }else if(s[i] == ‘R‘){ 20 if(R[now] != -1) now = R[now]; 21 }else { 22 cnt++; 23 L[cnt] = now; 24 R[cnt] = R[now]; 25 if(R[now] != -1) L[R[now]] = cnt; 26 R[now] = cnt; 27 now = cnt; 28 ans[now] = s[i]; 29 } 30 } 31 for(int i = R[0]; i!=-1; i = R[i]){ 32 printf("%c", ans[i]); 33 } 34 puts(""); 35 }
Friends of Friends
Gym - 101504G题意:问x的朋友的朋友是谁.
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 55; 4 int g[maxn][maxn]; 5 int vis[maxn]; 6 int ans[maxn]; 7 int cnt = 0; 8 int main(){ 9 int n, x; 10 scanf("%d %d", &n, &x); 11 for(int i = 1; i <= n; i++){ 12 int m; 13 scanf("%d", &m); 14 for(int j = 0; j < m; j++){ 15 int u; 16 scanf("%d", &u); 17 g[i][u] = 1; 18 } 19 } 20 for(int i = 1; i <= n; i++){ 21 if(g[x][i]) { 22 vis[i] = 1; 23 } 24 } 25 for(int i = 1; i <= n; i++){ 26 if(vis[i]==1){ 27 for(int j = 1; j <= n; j++){ 28 if(g[i][j]&& !vis[j] && j!= x) { 29 ans[cnt++] = j; 30 vis[j] = 2; 31 } 32 } 33 } 34 } 35 sort(ans, ans+cnt); 36 printf("%d\n", cnt); 37 for(int i = 0; i < cnt; i++){ 38 printf("%d%c", ans[i], i==cnt-1? ‘\n‘:‘ ‘); 39 } 40 }
以上是关于日常训练17-10-15的主要内容,如果未能解决你的问题,请参考以下文章