zoukankan      html  css  js  c++  java
  • 日常训练17-10-15

    题目链接: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, -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 }
    View Code

    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
    ", cnt);
    37     for(int i = 0; i < cnt; i++){
    38         printf("%d%c", ans[i], i==cnt-1? '
    ':' ');
    39     }
    40 }
    View Code
  • 相关阅读:
    257. Binary Tree Paths
    324. Wiggle Sort II
    315. Count of Smaller Numbers After Self
    350. Intersection of Two Arrays II
    295. Find Median from Data Stream
    289. Game of Life
    287. Find the Duplicate Number
    279. Perfect Squares
    384. Shuffle an Array
    E
  • 原文地址:https://www.cnblogs.com/yijiull/p/7674792.html
Copyright © 2011-2022 走看看