• 5.27 indeed 第三次网测


    1. 第一题, 没有看

    2. 暴力枚举。每一个部分全排列, 然后求出最大的请求数。

     1 #include<bits/stdc++.h>
     2 #define pb push_back
     3 typedef long long ll;
     4 using namespace std;
     5 typedef pair<int, int> pii;
     6 const int maxn = 1e3 + 10;
     7 
     8 int n;
     9 int t;
    10 vector<int> a[10];
    11 int res = 0;
    12 void work(int p, int s, int c) {
    13     if(p >= t) {
    14         res = max(res, c);
    15         return;
    16     }
    17 
    18     do {
    19         int st = s;
    20         int ct = c;
    21         for (int i = 0; i < 3; i++) {
    22             if(st >= a[p][i]) {
    23                 st -= a[p][i];
    24                 ct++;
    25             }
    26         }
    27         work(p + 1, st, ct);
    28     } while(next_permutation(a[p].begin(), a[p].end()));
    29 }
    30 void solve() {
    31     cin >> n >> t;
    32     int x;
    33     for (int i = 0; i < t; i++) {
    34         for (int j = 0; j < 3; j++) {
    35             cin >> x;
    36             a[i].pb(x);
    37         }
    38         sort(a[i].begin(), a[i].end());
    39     }
    40     work(0, n, 0);
    41     cout << res << endl;
    42 }
    43 
    44 int main() {
    45     freopen("test.in", "r", stdin);
    46     //freopen("test.out", "w", stdout);
    47     ios::sync_with_stdio(0);
    48     cin.tie(0); cout.tie(0);
    49     solve();
    50     return 0;
    51 }
    View Code

    3. 二叉树, 求路径, 其实很简单, 每个节点只有一个父亲, 然后记录是左还是右, 从目标节点向上走到根节点即可。或者是dfs也可以。

     1 #include<bits/stdc++.h>
     2 #define pb push_back
     3 typedef long long ll;
     4 using namespace std;
     5 typedef pair<int, int> pii;
     6 const int maxn = 1e5 + 10;
     7 int n;
     8 int a[maxn][2];
     9 int k;
    10 vector<char> p;
    11 bool work(int x) {
    12     if(x == k) return 1;
    13     if(a[x][0]) {
    14         if(work(a[x][0])) {
    15             p.pb('L');
    16             return 1;
    17         }
    18     }
    19     if(a[x][1]) {
    20         if(work(a[x][1])) {
    21             p.pb('R');
    22             return 1;
    23         }
    24     }
    25     return 0;
    26 }
    27 void solve() {
    28     scanf("%d%d", &n, &k);
    29     int x, y;
    30     for (int i = 1; i <= n; i++) {
    31         scanf("%d%d", &x, &y);
    32         a[i][0] = x; a[i][1] = y;
    33     }
    34 
    35     work(1);
    36     reverse(p.begin(), p.end());
    37     for (char c : p)
    38         printf("%c", c);
    39     printf("
    ");
    40 }
    41 
    42 int main() {
    43     freopen("test.in", "r", stdin);
    44     //freopen("test.out", "w", stdout);
    45     ios::sync_with_stdio(0);
    46     cin.tie(0); cout.tie(0);
    47     solve();
    48     return 0;
    49 }
    View Code

    4. 这个题,刚开始,我以为是找环,然后是环的长度,对每一个节点,用步数求环的余数即可,但是一些节点不在环上,但是他可以到达环,这些点比较难处理。

    后来,就想到,我把每一步走到哪里全记录下来就可以了,然后利用lca的数据结构,父亲的父亲, 然后对每一个点的步数进行二分,就可以得到最后的答案了。

    #include<bits/stdc++.h>
    #define pb push_back
    typedef long long ll;
    using namespace std;
    typedef pair<int, int> pii;
    const int maxn = 1e5 + 10;
    int n;
    int a[maxn];
    int dp[maxn][70];
    ll ti;
    void solve() {
        scanf("%d%lld", &n, &ti);
        //ti--;
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            dp[i][0] = a[i];
            //cout << dp[i][0] << endl;
        }
        for (int j = 1; j < 70; j++) {
            for (int i = 1; i <= n; i++) {
                dp[i][j] = dp[dp[i][j - 1] ][j - 1];
            }
        }
        for (int i = 1; i <= n; i++) {
            int cur = i;
            for (int j = 63; j >= 0; j--) {
                if(ti & (1ll << j)) {
                    cur = dp[cur][j];
                    //cout << i << " " << j << " " << cur << endl;
                }
    
            }
            printf("%d
    ", cur);
        }
    
    }
    
    int main() {
        freopen("test.in", "r", stdin);
        //freopen("test.out", "w", stdout);
        ios::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        solve();
        return 0;
    }
  • 相关阅读:
    从Java角度理解Angular之入门篇:npm, yarn, Angular CLI
    大数据开发实战:Stream SQL实时开发一
    大数据开发实战:Spark Streaming流计算开发
    大数据开发实战:Storm流计算开发
    大数据开发实战:Hadoop数据仓库开发实战
    数据仓库中的拉链表
    java通过jdbc连接impala
    impala-shell常用命令
    Kudu-java数据库简单操作
    拉链表--实现、更新及回滚的具体实现( 转载)
  • 原文地址:https://www.cnblogs.com/y119777/p/6930507.html
Copyright © 2020-2023  润新知