【补】2022.7.6———HZOI【这次应该叫高二上一调】划水记

T1 匹配 T2 回家 T3 寿司

写在前面

一直题好多改不过来,所以一直没有写、这都到月底了,就先不咕惹

码风奇怪请见谅

代码注释较多,看得难受可以删掉,我就不删了

成绩综述

 理论上,Rank11 然而我是菜鸡所以我当然是打暴力打出来的

T1 匹配

初见以为牛棚回声,牛棚回声这diao题我现在都还没写出来

然而赛时强行map映射,笑看MLE

这其实就是一个极水的字符串题,KMPhash均可过

裸的字符串匹配

然而学长说少用hash

赛时MLE(73pts)



#include <iostream>
#include <iomanip>
#include <map>
#include <cstring>
#define GMY (520&1314)
#define FBI_OPENTHEDOOR(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout);
#define ll long long
#define IFDEF__ios_FASTIO_ return
#define ENDIF__ios_FASTIO_ return
#define re register int
#define char_phi signed
#define MARK cout << "###"
#define _MARK "@@@"
#define LMARK "!!!~~~"
#define ZY " qwq "
#define _ " "
#define Endl cout << endl
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define N 100005
#define CASE 11
using namespace std;
#define FASTIO
int T, la, lb, cnt, final_ans, conster = N-1;
char a[N], b[N], c[N], an[N];
map<string,bool> mp;
inline void Fastio_setup(){     
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    double __FAS__INT128;
    #ifdef FASTIO
    IFDEF__ios_FASTIO_;cin >> __FAS__INT128;
    cout << setprecision(3) << setiosflags(ios::fixed) << __FAS__INT128 << endl;
    cout << __FAS__INT128 << endl;
    cout.unsetf(ios::fixed);
    cout << fixed << setprecision(3) << __FAS__INT128 << endl;
    ENDIF__ios_FASTIO_;
    #endif
}
void work(){
    // 这题是CF的题?
    // 【牛棚回声】的说!!!()()()()
    // 【牛棚回声】我到现在都还没做完
    // 嗐 这就是kmp hash一类的吧 当然我板子忘掉了
    // 所以开map映射
    // ~~笑看MLE~~
    // la = lb 的情况还没想好
    mp.clear();
    final_ans = 0;
    for(re i = 1 ; i <= conster ; ++ i){
        a[i] = b[i] = c[i] = an[i] = 0;
    }
    cin >> la >> lb;
    cin >> a+1;
    b[0] = ' '; c[0] = ' ';
    for(re i = 1 ; i <= lb ; ++ i){
        b[i] = a[i], c[i] = a[i];
        mp[c] = true;
        // for(re j = 0 ; j <= strlen(c+1) ; ++ j){
        //     cout << c[j];
        // }
        // cout << _MARK << mp[c] << endl;
    }
    if(la != lb){
        c[lb+1] = a[lb+1];
        mp[c] = true;
    }
    cin >> b[lb+1];
    an[0] = ' ';
    // cout << "b: ";
    // for(re i = 1 ; i <= lb+1 ; ++ i) cout << b[i];
    // Endl;
    for(re le = lb+1 ; le >= 1 ; -- le){
        an[le+1] = 0, cnt = 0;
        // cout << "starter: " << la-le+1 << endl;
        for(re i = lb-le+2 ; i <= lb+1 ; ++ i){
            an[++ cnt] = b[i];
        }
        // Endl;
        // for(re j = 0 ; j <= strlen(an+1) ; ++ j){
        //     cout << an[j];
        // }
        // Endl;
        if(mp[an] == true){
            final_ans = le;
            break;
        }
    }
    // Endl; Endl;
    if(final_ans == 0){
        cout << "0" << endl;
        return ;
    }
    cout << final_ans << endl;
    // 怎么这样 恍恍惚惚地样例和创的样例都过了
}
// #define CHAR_PHI_AND_GMY
char_phi main(){
    #ifdef CHAR_PHI_AND_GMY
    FBI_OPENTHEDOOR(a);
    #endif
    Fastio_setup();
    cin >> T;
    while(T --){
        work();
    }
    return GMY;
}

ACのHash

#include <iostream>
#include <iomanip>
#define GMY (520&1314)
#define FBI_OPENTHEDOOR(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout);
#define ll long long
#define IFDEF__ios_FASTIO_ return
#define ENDIF__ios_FASTIO_ return
#define re register int
#define char_phi signed
#define MARK cout << "###"
#define _MARK "@@@"
#define LMARK "!!!~~~"
#define ZY " qwq "
#define _ " "
#define Endl cout << endl
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define N 150005
#define ull unsigned long long
using namespace std;
#define FASTIO
const ull base = 233;
int T, la, lb, final_ans, i, j;
ull ha, hb;
char a[N], b[N];
ull bs[N];
inline void Fastio_setup(){     
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    double __FAS__INT128;
    #ifdef FASTIO
    IFDEF__ios_FASTIO_;cin >> __FAS__INT128;
    cout << setprecision(3) << setiosflags(ios::fixed) << __FAS__INT128 << endl;
    cout << __FAS__INT128 << endl;
    cout.unsetf(ios::fixed);
    cout << fixed << setprecision(3) << __FAS__INT128 << endl;
    ENDIF__ios_FASTIO_;
    #endif
}
void work(){
    // 我來改考試題了的說
    // 話說這題是hash,我又該複習了罷,不過我都忘掉hash和kmp的用法和作用了。。
    // さくらの方法
    cin >> la >> lb;
    cin >> a+1;
    // for(re i = 1 ; i <= conster ; ++ i) a[i] = b[i] = 0;// cin的時候好像不清空數組
    for(re doer = 1 ; doer <= lb ; ++ doer) b[doer] = a[doer];
    cin >> b[lb+1]; ++ lb;
    ha = hb = final_ans = 0, i = 1, j = lb;//搞一個雙指針
    while(i <= la && j >= 1){
        ha = ha*base + a[i] - 'a';
        // hb = hb*base + b[j] - 'a';\
            這裡差點寫錯!後綴也是順着走的說
        hb += (b[j] - 'a')*bs[lb-j];// 十分之好理解的說
        if(ha == hb) final_ans = i;// 直接等於而且不break 因爲相當於是從小到大枚舉長度的\
                                      實際上還可以優化的說,不過hash已經足夠優秀了吧?O(n)左右
        ++ i, -- j;
    }
    cout << final_ans << endl;
}
// #define CHAR_PHI_AND_GMY
char_phi main(){
    #ifdef CHAR_PHI_AND_GMY
    FBI_OPENTHEDOOR(a);
    #endif
    Fastio_setup();
    bs[0] = 1;
    for(re doer = 1 ; doer <= N-3 ; ++ doer) bs[doer] = bs[doer-1] * base;
    cin >> T;
    while(T --){
        work();
    }
    return GMY;
}

T2 回家

一道类似tarjan

然而赛时并不这么认为  赛时光想着爆搜了  思路在代码里  50ptsT掉了

所以这道题先莽一个tarjan,求割点

然而并非所有割点都是必经点

所以从n节点开始,回溯的时候判断该点是否可以获得n节点的标记

不会证明这个跟回溯顺序的关系,然而手模确实能过

所以要看严谨证明我真不会,可以去看看其他dalao的博客

赛时TLE 50pts

 

#include <iostream>
#include <iomanip>
#include <cstring>
#define GMY (520&1314)
#define FBI_OPENTHEDOOR(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout);
#define ll long long
#define IFDEF__ios_FASTIO_ return
#define ENDIF__ios_FASTIO_ return
#define re register int
#define char_phi signed
#define MARK cout << "###"
#define _MARK "@@@"
#define LMARK "!!!~~~"
#define ZY " qwq "
#define _ " "
#define Endl cout << endl
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define CASE 11
#define N 200005
#define M 400005
using namespace std;
#define FASTIO
int T, n, m, star_cnt, pathnum, gmy520, Mer = (M<<1) - 5;
bool vis[N];
int head[M<<1], cnt[N], gmy[N];
struct star{
    int v, nxt;
}e[M<<1];
inline void Fastio_setup(){     
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    double __FAS__INT128;
    #ifdef FASTIO
    IFDEF__ios_FASTIO_;cin >> __FAS__INT128;
    cout << setprecision(3) << setiosflags(ios::fixed) << __FAS__INT128 << endl;
    cout << __FAS__INT128 << endl;
    cout.unsetf(ios::fixed);
    cout << fixed << setprecision(3) << __FAS__INT128 << endl;
    ENDIF__ios_FASTIO_;
    #endif
}
inline void star_add(int u,int v){e[++ star_cnt].v=v, e[star_cnt].nxt=head[u], head[u]=star_cnt;}
// 等会,你别给我整个森林出来..
// 奥 好像森林没啥事 森林搞了相当于没搞()
int dfs(int x){
    if(x == n){
        ++ pathnum;
        return 1;
    }
    vis[x] = true; int res(0);
    for(re i = head[x] ; i ; i = e[i].nxt){
        int v = e[i].v;
        if(vis[v] == true) continue;
        int dealer = dfs(v);
        res += dealer;
    }
    vis[x] = false, cnt[x] += res;
    return res;
}
void work(){
    // 先说一下那个树的那个测试点,md那个分我必拿
    // 我反悔了,我不一定拿
    // 我又不反悔了,阿不,又反悔,阿又没,
    // 树的那个差不多LCA 从学校到他家有几个根节点
    // —————————————————————————————————————大芳起兮云飞扬——————————————————————————————————————————
    // 思路:
    // 朴素地,暴力建vector保存每一条从1—>n的路径,然后一一比较
    // 会T成啥样呢?应该是拿10pts吧
    // 我想想,这个题遍历一下图再挂个CASE铁定能跑
    // 所以正解肯定有遍历图这个操作吧?
    // 啊焯 数据范围下边那行小字什么意思 "请注意优化常数"
    // nm?这题需要卡常?正解这么慢?卡我?
    // 好吧,我其实是一个搜索渣的(爆搜应该会写) 遍历图这种东西..
    // 便利一边图找到每一个路径,同时对于每一个节点如果return的是true那就++cnt[x],表示到过他一次;\
       记录有几条路径到n为num(最终节点到过几次)
    // 然后最后统计cnt[i] == num的节点个数就是答案
    // 然后题目说了不包括1号节点和n号节点啊喂
    // 然后口胡就搞完了。你问我代码实现?这个..
    // 外面晚霞好美 我出去看看
    // 啊不是,我去手模一下(doge)
    // ———————————————————————————————————ten minutes later———————————————————————————————————————
    // 晚霞好漂亮的 我也推出来力
    // 就是遍历的说 然后return的不是bool型,而是int型\
       因为可能有好多路径经过这个边,但用bool的就可能少统计了\
       就第一个样例就是,还有防重边的功能
    // 然后数据范围里那个"注意"里换行符是啥,是endl吗
    cin >> n >> m; gmy520 = n-1;
    star_cnt = pathnum = gmy[0] = 0;
    // memset(head, 0, sizeof(head)), memset(e, 0, sizeof(e));// 吾真真不愿意用memset也
    for(re i = 1 ; i <= Mer ; ++ i)
        head[i] = e[i].v = e[i].nxt = 0;
    for(re i = 1 ; i <= n+1 ; ++ i)
        cnt[i] = gmy[i] = vis[i] = 0;//vis实际上不用清空吧 不过以防万一我写上

    for(re i = 1, uu, vv ; i <= m ; ++ i){
        cin >> uu >> vv;
        star_add(uu, vv), star_add(vv, uu);
        // cout << "###" <<uu << _ << vv << endl;
    }
    dfs(1);
    // cout << "pathnum: " << pathnum << endl;
    for(re i = 2 ; i <= gmy520 ; ++ i){// 其实应该到n-1,但是我懒得写了,我也怕会因为这个T了(毕竟要缩小常数嘛)\
                                     算了还是写一下吧
        if(cnt[i] == pathnum){
            gmy[++ gmy[0]] = i;
        }
        // cout << "{" << i << ", " << cnt[i] << "} ";
    }
    // Endl;
    // 想起个事 cout能不能设置输出的先后顺序 赛后有时间查一下
    cout << gmy[0] << endl;
    for(re i = 1 ; i <= gmy[0] ; ++ i){
        cout << gmy[i] << _;
    }
    cout << endl;
    // 样例又都过了耶
    // 不过狡猾的样例是骗不过我的!我知道!还有T!清空数组的说!
    // 嘿嘿
    // 唔..不知道对不对..好害怕的说
}
// #define CHAR_PHI_AND_GMY
char_phi main(){
    Fastio_setup();
    #ifdef CHAR_PHI_AND_GMY
    FBI_OPENTHEDOOR(a);
    #endif
    cin >> T;
    while(T --){
        work();
    }
    return GMY;
}

AC

 

//                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  \
                                            求                                                                                                                                                                                                                                    \
                                            是                                                                                                                                                                                                                                    \
                                            创                                                                                                                                                                                                                                    \
                                            新                                                                                                                                                                                                                                    
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm>
#define GMY (520&1314)
#define FBI_OPENTHEDOOR(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout);
#define ll long long
#define IFDEF__ios_FASTIO_ return
#define ENDIF__ios_FASTIO_ return
#define re register int
#define char_phi signed
#define MARK cout << "###"
#define _MARK "@@@"
#define LMARK "!!!~~~"
#define ZY " qwq "
#define _ " "
#define Endl cout << endl
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define CASE 11
#define N 200005
#define M 400005
using namespace std;
int T, n, m, star_cnt, tarjan_id;
bool pd[N];
int head[M<<1], dfn[N], low[N], g[N];
struct star{
    int v, nxt;
}e[M<<1];
// set<int> gd;
// set<int> s[N];
#define FASTIO
inline void Fastio_setup(){     
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    double __FAS__INT128;
    #ifdef FASTIO
    IFDEF__ios_FASTIO_;cin >> __FAS__INT128;
    cout << setprecision(3) << setiosflags(ios::fixed) << __FAS__INT128 << endl;
    cout << __FAS__INT128 << endl;
    cout.unsetf(ios::fixed);
    cout << fixed << setprecision(3) << __FAS__INT128 << endl;
    ENDIF__ios_FASTIO_;
    #endif
}
inline void star_add(int u,int v){e[++ star_cnt].v=v, e[star_cnt].nxt=head[u], head[u]=star_cnt;}
void tarjan(int x, int rt){
    dfn[x] = low[x] = ++ tarjan_id;
    // int son(0);
    for(re i = head[x] ; i ; i = e[i].nxt){
        if(dfn[e[i].v] == 0){
            tarjan(e[i].v, rt);
            low[x] = MIN(low[x], low[e[i].v]);
            if(low[e[i].v] >= dfn[x] && x != rt && pd[e[i].v] == true) // 找到了一个割点
                g[++ g[0]] = x;
            // if(x == rt) ++ son;
    // MARK;
            if(pd[e[i].v] == true) pd[x] = true;
        }
        else {
            low[x] = MIN(low[x], dfn[e[i].v]);
        }
    }
    // if(x == rt && son >= 2) g[++ g[0]] = x; // rt就是1,但题目说了1不算必经点
}
void work(){
    // 原來這道題是跑Tarjan的說..
    // 看來我還是比較笨,賽時連這麼顯然的方法都想不出
    // ∴不是簡單的Tarjan找割點 要判斷一下⌈子樹⌋(搜索樹的子樹吧)
    // 對於某一個割點,他的⌈子樹⌋中如果包含n節點那麼就是一個必經點了
    // 不過子樹怎麼判斷?
    // 一個樸素的想法是記錄每一個割點的子樹..最後再判斷
    // 應該會T掉吧??
    // 但是我先開好多set先按這種搞一下
    // 然後Kaguya給了我啓示
    // 直接搞一個布尓型返回值就ok嘛
    // 確實
    // 所以開打了
    cin >> n >> m;
    g[0] = star_cnt = tarjan_id = 0;
    for(re i = 1, uu, vv ; i <= m ; ++ i){
        cin >> uu >> vv;
        star_add(uu, vv), star_add(vv, uu);
    }
    pd[n] = true;
    tarjan(1, 1);// 就算是森林也不用去管 直接不判斷dfn[i]==0了
    // 又看到了fengwu大佬的blog 然后想搞一个pd数组
    cout << g[0] << endl;
    sort(g+1, g+g[0]+1);
    for(re i = 1 ; i <= g[0] ; ++ i)
        cout << g[i] << _;
    Endl;
    for(re i = 1 ; i <= n ; ++ i){
        g[i] = low[i] = dfn[i] = pd[i] = head[i] = false;
    }
    for(re i = 1 ; i <= star_cnt ; ++ i){
        e[i].v = e[i].nxt = 0;
    }
}
// #define CHAR_PHI_AND_GMY
char_phi main(){
    Fastio_setup();
    #ifdef CHAR_PHI_AND_GMY
    FBI_OPENTHEDOOR(a);
    #endif
    cin >> T;
    while(T --){
        work();
    }
    return GMY;
}

T3 寿司

还不会,咕掉

posted @   char_phi  阅读(10)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示