日常訓練17-10-15
阿新 • • 發佈:2017-10-16
net editor space sort clu 朋友的朋友 ++ target c++
題目鏈接:here
Text Editor
Gym - 101504F
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, -1View Code, 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 }View Code
日常訓練17-10-15