2019.11.07考试解题报告

时间:2019-11-07
本文章向大家介绍2019.11.07考试解题报告,主要包括2019.11.07考试解题报告使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

总结

期望得分:\(50 + 20 + 0 = 70\)
实际得分:\(50 + 5 + 0 = 55\)

大神\(zhx\):考试要先打暴力.

于是我困在\(T2\)\(20\)分暴力中无法自拔。。调\(T2\)暴力花了一个小时……其实吧。。我想写\(T3\),然而连怎么建这棵树都不会,所以就肝\(T2\)\(20\)分一直到死。。\(T1\)是个沙比题,人均\(100\)分,这场考试人均\(100+\),我就是倒着数的那个。。心里满是失落,又实在不会这些题。。没救了


思路&&代码

T1

\(50\)分:

直接\(n^2\)暴力找度为\(1\)的点,每次找到就将这个点和它连边的点度都减\(1\),然后把答案存下来最后输出(代码中的\(sub1\)

另外的\(10\)分:

因为保证了\(u==1\),所以我们可以直接输出\(n-2\)\(1\)

\(100\)分:

考虑用一个优先队列,把度为\(1\)的结点的编号放入队列中,保证每次取出的编号最小,然后直接枚举这些点的连边,让连边的点度数\(--\),如果此时度数变为\(1\)则入队,如果此时度数大于等于\(1\)则输出这个点,这样就做完了

#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int A = 5e5 + 11;
const int B = 1e6 + 11;

inline int read() {
    char c = getchar(); int x = 0, f = 1;
    for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for( ; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
    return x * f;
}

int n, m;
struct node { int to, nxt; } e[A];
bool flag = 1;
int cnt = 0, tot = 0, head[A], du[A], ans[A], vis[A];
priority_queue <int, vector<int>, greater<int> > Q;

inline void add(int from, int to) {
    e[++cnt].to = to;
    e[cnt].nxt = head[from];
    head[from] = cnt;
}

namespace sub1 {
    void solve(int id) {
        vis[id] = 1;
        int to = e[head[id]].to;
        if(!vis[to]) {
            du[to]--; if(du[to] == 0) vis[to] = 1;
            ans[++tot] = to; head[id] = e[head[id]].nxt;
        } else {
            while(vis[to] && to != 0) {
                head[id] = e[head[id]].nxt;
                to = e[head[id]].to;
            }
            ans[++tot] = to; if(du[to] == 0) vis[to] = 1;
            du[to]--; head[id] = e[head[id]].nxt;
        }
        return;
    }
    void Main() {
        vis[0] = 1;
        for(int i = 1; i <= n - 2; i++)
            for(int j = 1; j <= n; j++)
                if(du[j] == 1) {
                    du[j]--;
                    solve(j);
                    break;
                }
        for(int i = 1; i <= tot; i++) cout << ans[i] << " ";
        return;
    }
}

int main() {
    freopen("prufer.in", "r", stdin);
    freopen("prufer.out", "w", stdout);
    n = read();
    for(int i = 1, u, v; i < n; i++) {
        u = read(), v = read();
        add(u, v), add(v, u);
        if(u != 1) flag = 0;
        du[u]++, du[v]++;
    }
    
    if(n <= 3000) return sub1::Main(), 0;

    if(flag) {
        cout << 1;
        for(int i = 2; i <= n - 2; i++) cout << " 1";
        puts("");
        return 0;
    }   
    
    for(int i = 1; i <= n; i++) if(du[i] == 1) Q.push(i);
    for(int i = 1; i <= n; i++) {
        int u = Q.top(); Q.pop();
        for(int j = head[u]; j; j = e[j].nxt) {
            int to = e[j].to;
            du[to]--;
            if(du[to] == 1) Q.push(to);
            if(du[to] >= 1) cout << to << " ";
        }
    }
    puts("");
    return 0;
}
/*
6
1 3
1 5
3 2
3 6
5 4

3 5 1 3
*/

T2

\(20\)分:

暴搜,只能从左往右搜,所以记录一下上次用的是哪一个,这次枚举直接从上次用的下一个开始枚举,保证从左往右

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

const int A = 1e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;

inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for( ; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
    return x * f;
}

int n, m, ans, vis[A], a[A];
char s[A];
int c[4000][4000];

void dfs(int cnt, int last) {
    if(cnt > n + 1) return;
    if((cnt - 1) % 2 == 0 && cnt - 1 != 0) {
        int now = cnt - 1;
        int zuo = 0, you = 0, cao = 0;
        for(int i = 1; i <= now / 2; i++) {
            if(a[i] == 2) {
                cao = 1;
                break;
            }
            if(a[i] == 1) zuo++;
        }
        for(int i = now / 2 + 1; i <= now; i++) {
            if(a[i] == 1) {
                cao = 1;
                break;
            }
            if(a[i] == 2) you++;
        }
        if(!cao && zuo == you && zuo + you == now) ans++;
    }
    for(int i = last + 1; i <= n; i++) {
        if(!vis[i]) {
            vis[i] = 1;
            a[cnt] = (s[i] == '(' ? 1: 2);
            dfs(cnt + 1, i);
            vis[i] = 0;
        }
    }
}

signed main() {
    freopen("beauty.in", "r", stdin);
    freopen("beauty.out", "w", stdout);
    scanf("%s", s + 1);
    n = strlen(s + 1);
    if(n <= 20) {
        dfs(1, 0);
        cout << ans % mod << '\n';
        return 0;
    }
    return 0;
}

$$

T3

原文地址:https://www.cnblogs.com/loceaner/p/11812526.html