• 日常训练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
  • 相关阅读:
    点击图片跳转详情
    offsetwidth/clientwidth的区别
    css中让元素隐藏的多种方法
    js中的||、&&与!用法
    怎么区分静态网页和动态网页
    我的第一篇博客--新手勿喷
    2015腾讯暑期实习生面试
    ring0 与 ring3 层之间的交互
    驱动层得到进程的完整路径
    WinDbg调试流程的学习及对TP反调试的探索
  • 原文地址:https://www.cnblogs.com/yijiull/p/7674792.html
Copyright © 2020-2023  润新知