Skip to content

泉州一中信息学Blog

信息学奥赛技术分享博客

  • 登录
  • 小学oj
  • 中学oj
  • 测试页面1
  • Toggle search form

南外 Day 11

Posted on 2023年8月11日 By 陈, 梓域 南外 Day 11无评论

T1
超短代码

#include <bits/stdc++.h>
std::map<char, int> fl;
std::string a;
int n;
int main() {
    std::cin >> n >> a;
    for (int i = 0; i < a.size(); i++) fl[a[i]]++;
    for (int i = 0; i < a.size(); i++)
        if (!(fl[a[i]] - 1))
            return !(std::cout << a[i]);
    return !(std::cout << -1);
}

T2
暴力模拟

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define Sig signed
#define ll long long
#define Il inline
#define fup(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define fdown(i, a, b) for (int(i) = (a); (i) >= (b); --(i))
int a, b;
using namespace std;
Il int R() {
    int p = 0, q = 1;
    char ch = getchar();
    while (!isdigit(ch)) q = (ch == &#039;-&#039;) ? -1 : 1, ch = getchar();
    while (isdigit(ch)) p = (p << 3) + (p << 1) + (ch ^ 48), ch = getchar();
    return p * q;
}
int ans, flag;
Sig main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> a >> b;
    flag = a;
    fup(i, a, b) {
        int x = i, s = 0;
        while (x) {
            if (x % 10 == 0 || x % 10 == 6 || x % 10 == 9)
                s++;
            if (x % 10 == 8)
                s += 2;
            x /= 10;
        }
        if (s > ans)
            ans = s, flag = i;
    }
    cout << flag;
    return 0;
}

T3

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define Sig signed
#define ll long long
#define Il inline
#define fup(i,a,b) for(int (i)=(a);(i)<=(b);++(i))
#define fdown(i,a,b) for(int (i)=(a);(i)>=(b);--(i))
using namespace std;
Il int R()
{
    int p=0,q=1;
    char ch=getchar();
    while(!isdigit(ch)) q=(ch==&#039;-&#039;)?-1:1,ch=getchar();
    while(isdigit(ch)) p=(p<<3)+(p<<1)+(ch^48),ch=getchar();
    return p*q;
}
const int N=2500,M=2*N,L=1e5+10;
ll n,b[L],g[L],ansb[L],ansg[L],ans,k;
Sig main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    n=R();
    fup(i,1,n) b[i]=R(),ansb[b[i]+M]++;
    fup(i,1,n) g[i]=R(),ansg[g[i]+M]++;
    for(int i=N+M;i>=N;i--)
    {

        for(int j=N+M;j>=N;j--)
        {
            if(((i-M)>0&&(j-M)<0)||((i-M)<0&&(j-M)>0))
            {
                if(!ansb[i]) break;
                if(i+j<2*M)
                {
                    ans+=min(ansb[i],ansg[j]);
                    k=min(ansb[i],ansg[j]);
                    ansb[i]-=k;
                    ansg[j]-=k;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

贪心吧
男找高配女找低
男找低配女找高
T4

#include <bits/stdc++.h>
using namespace std;
int n, len, ax[1000], top, fs, id;
string s, ay[1000];
char a;
signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    while (n--) {
        cin >> s;
        len = s.size();
        for (int i = 0; i < len; i++) {
            top++;
            if (s[i] == &#039;:&#039; && s[i + 1] == &#039;:&#039;) {
                i += 2;
                fs = top;
                top++;
            } else if (top != 1)
                i++;
            while (s[i] != &#039;:&#039; && i < len) {
                ay[top] += s[i];
                ax[top]++;
                i++;
            }
            i--;
        }
        id = 9 - top;
        for (int i = 1; i <= top; i++) {
            if (i == fs)
                for (int j = 1; j <= id; j++) {
                    if (i + j - 1 != 8)
                        cout << "0000:";
                    else
                        cout << "0000";
                }
            else {
                for (int j = 1; j <= 4 - ax[i]; j++) cout << "0";
                if (i != top)
                    cout << ay[i] << ":";
                else
                    cout << ay[i];
            }
        }
        cout << &#039;\n&#039;;
        top = fs = id = 0;
        for (int i = 1; i <= 100; i++) {
            ax[i] = 0;
            ay[i] = "";
        }
    }
    return 0;
}

模拟即可
T5
因为很多爆炸都是同时进行的,所以比较水

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll r, c;
ll e[2505], f[2505];
ll ans;
char mp[55][55];
struct Ways {
    ll u, v, w;
} way[1662505];
ll tot;
int cmp(Ways A, Ways B) { return A.w < B.w; }
signed main(void) {
    ios::sync_with_stdio(false);
    cin >> r >> c;
    for (int i = 1; i <= r; i++)
        for (int j = 1; j <= c; j++) cin >> mp[i][j];
    for (int i = 1; i <= r; i++)
        for (int j = 1; j <= c; j++)
            if (mp[i][j] == &#039;X&#039;)
                for (int k = 1; k <= r; k++)
                    for (int l = 1; l <= c; l++)
                        if (mp[k][l] == &#039;L&#039;)
                            way[++tot].u = (i - 1) * c + j, way[tot].v = (k - 1) * c + l,
                            way[tot].w = (i - k) * (i - k) + (j - l) * (j - l);
    sort(way + 1, way + 1 + tot, cmp);
    for (int i = 1; i <= tot; i++) {
        if (!e[way[i].u]) {
            if (!f[way[i].v])
                f[way[i].v] = way[i].w, e[way[i].u] = 1;
            else if (f[way[i].v] == way[i].w)
                ++ans, e[way[i].u] = 1, f[way[i].v] = -1;
        }
    }
    cout << ans;
    return 0;
}

T6
什么玩意儿的奇环数
本来写网络流的写T了,心态炸裂

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define Sig signed
#define ll long long
#define Il inline
#define fup(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define fdown(i, a, b) for (int(i) = (a); (i) >= (b); --(i))
using namespace std;
const int N = 2e5 + 10, inf = 0x3f3f3f3f;
Il int R() {
    int p = 0, q = 1;
    char ch = getchar();
    while (!isdigit(ch)) q = (ch == &#039;-&#039;) ? -1 : 1, ch = getchar();
    while (isdigit(ch)) p = (p << 3) + (p << 1) + (ch ^ 48), ch = getchar();
    return p * q;
}
int n, ans;
int stk[N], tot;
int nxt[N], cost[N], val[N], mark[N];
void work(int x) {
    int ys = inf, mrfz;
    for (int l = nxt[x]; mark[l]; x = l, l = nxt[l]) {
        mark[l] = 0;
        mrfz = max(val[l] - cost[x], 0);
        ans += mrfz;
        ys = min(ys, val[l] - mrfz);
    }
    ans += ys;
}
Sig main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    n = R();
    fup(i, 1, n) nxt[i] = R(), cost[i] = R(), val[i] = cost[i], ++mark[nxt[i]];
    fup(i, 1, n) if (!mark[i]) stk[++tot] = i;
    while (tot) {
        int y = stk[tot--];
        ans += val[y];
        val[nxt[y]] = max(val[nxt[y]] - cost[y], 0);
        if (!(--mark[nxt[y]]))
            stk[++tot] = nxt[y];
    }
    fup(i, 1, n) if (mark[i]) work(i);
    printf("%d", ans);
    return 0;
}

T7
重生吧,我的欧拉

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define Sig signed
#define ll long long
#define Il inline
#define pii pair<int, int>
#define mpr make_pair
#define ft first
#define sd second
#define fup(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define fdown(i, a, b) for (int(i) = (a); (i) >= (b); --(i))
using namespace std;
const int N = 1e6 + 10;
Il int read() {
    int p = 0, q = 1;
    char ch = getchar();
    while (!isdigit(ch)) q = (ch == &#039;-&#039;) ? -1 : 1, ch = getchar();
    while (isdigit(ch)) p = (p << 3) + (p << 1) + (ch ^ 48), ch = getchar();
    return p * q;
}
struct Node {
    int to, nxt;
} node[N << 2];
pii ans[N << 2];
int n, m, tmp = -1, cnt = 1, tot;
int ind[N], hd[N], sk[N], vis[N], S[N], mks[N];
void ins(int u, int v) {
    node[++cnt].nxt = hd[u];
    hd[u] = cnt;
    node[cnt].to = v;
}
void dfs(int x) {
    vis[x] = 1;
    if (ind[x] & 1)
        sk[++sk[0]] = x;
    for (int i = hd[x]; i; i = node[i].nxt)
        if (!vis[node[i].to])
            dfs(node[i].to);
}
void work(int x) {
    S[0] = 1, S[1] = x;
    while (S[0]) {
    Nxtcirc:
        x = S[S[0]];
        for (int &i = hd[x]; i; i = node[i].nxt) {
            if (!mks[i]) {
                mks[i] = mks[i ^ 1] = 1;
                S[++S[0]] = node[i].to;
                goto Nxtcirc;
            }
        }
        sk[++sk[0]] = x;
        --S[0];
    }
}
Sig main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    n = read(), m = read();
    int x, y;
    fup(i, 1, m) x = read(), y = read(), ins(x, y), ins(y, x), ++ind[x], ++ind[y];
    fup(i, 1, n) {
        if (ind[i] && !vis[i]) {
            sk[0] = 0, dfs(i), hd[0] = 0;
            if (!sk[0])
                ins(i, 0), ins(i, 0), ins(0, i), ins(0, i);
            else
                while (sk[0]) ins(sk[sk[0]], 0), ins(0, sk[sk[0]--]);
            work(0);
            while (sk[0] > 1) {
                if (sk[sk[0]])
                    ans[++tot] = mpr(0, sk[sk[0]--]);
                else
                    --sk[0], ans[++tot] = mpr(1, sk[sk[0]--]), ++tmp;
            }
        }
    }
    printf("%d\n%d\n", tmp, ans[1].sd);
    fup(i, 2, tot) printf("%d %d\n", ans[i].ft, ans[i].sd);
    return 0;
}

T8
WA 了,请教各位 DALAO

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define Sig signed
#define ll long long
#define Il inline
#define pii pair<int, int>
#define Vt vector
#define Stk stack
#define mpr make_pair
#define ft first
#define sd second
#define pb push_back
#define fup(i, a, b) for (int(i) = (a); (i) <= (b); ++(i))
#define fdown(i, a, b) for (int(i) = (a); (i) >= (b); --(i))
using namespace std;
const int N = 5e5 + 10;
int n, len, tot, aln, times, sct;
int ch[N << 1][2], rd[N << 1], tn[N << 1];
int dfn[N << 3], low[N << 3], decideb[N << 3];
char cod[N];
Vt<int> ts[N << 3];  // 2-SAT
Stk<int> stk;
Il int read() {
    int p = 0, q = 1;
    char ch = getchar();
    while (!isdigit(ch)) q = (ch == &#039;-&#039;) ? -1 : 1, ch = getchar();
    while (isdigit(ch)) p = (p << 3) + (p << 1) + (ch ^ 48), ch = getchar();
    return p * q;
}
void ins(char s[], int id) {
    int y = 0;
    for (int i = 0; s[i]; ++i) {
        int ach = s[i] - &#039;0&#039;;
        if (s[i] == &#039;?&#039;)
            ach = (id & 1);
        if (!ch[y][ach])
            ch[y][ach] = ++tot;
        y = ch[y][ach];
    }
    if (not rd[y]) {
        rd[y] = tn[y] = ++aln;
        ts[id].pb(rd[y]);
        ts[tn[y]].pb(id ^ 1);
    } else {
        ts[id].pb(tn[y]);
        ts[rd[y]].pb(id ^ 1);
        ts[id].pb(++aln);
        ts[rd[y]].pb(aln);
        rd[y] = aln;
        ts[++aln].pb(id ^ 1);
        ts[aln].pb(tn[y]);
        tn[y] = aln;
    }
}
void dfs(int x, int xp, int yp) {
    if (rd[x]) {
        if (!xp)
            xp = rd[x], yp = tn[x];
        else {
            ts[rd[x]].pb(yp);
            ts[xp].pb(tn[x]);
            ts[xp].pb(++aln);
            ts[rd[x]].pb(aln);
            xp = aln;
            ts[++aln].pb(yp);
            ts[aln].pb(tn[x]);
            yp = aln;
        }
    }
    if (ch[x][0])
        dfs(ch[x][0], xp, yp);
    if (ch[x][1])
        dfs(ch[x][1], xp, yp);
}
void tarjan(int x) {
    dfn[x] = low[x] = ++times;
    stk.push(x);
    for (auto y : ts[x]) {
        if (!dfn[y])
            tarjan(y), low[x] = min(low[x], low[y]);
        else if (!decideb[y])
            low[x] = min(low[x], dfn[y]);
    }
    if (dfn[x] == low[x]) {
        ++sct;
        int y;
        do {
            y = stk.top();
            stk.pop();
            decideb[y] = sct;
        } while (x != y);
    }
}
Sig main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    n = read(), aln = (n + 1) * 2;
    fup(i, 1, n) {
        int vts = i * 2;
        scanf("%s", cod);
        ins(cod, vts);
        len = strlen(cod);
        if (count(cod, cod + len, &#039;?&#039;))
            ins(cod, vts + 1);
        else
            ts[vts + 1].pb(vts);
    }
    dfs(0, 0, 0);
    fup(i, 1, n) {
        int vts = i * 2;
        if (!dfn[vts])
            tarjan(vts);
        if (!dfn[vts + 1])
            tarjan(vts + 1);
        if (decideb[vts] == decideb[vts + 1]) {
            return !(puts("NO"));
        }
    }
    return !(puts("YES"));
}

补完blog
交电脑去了

训练日志

文章导航

Previous Post: 8.10博客(补)
Next Post: 常州集训DAY7

发表回复 取消回复

要发表评论,您必须先登录。

2025年 6月
一 二 三 四 五 六 日
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« 2月    

2024常州 Class Classic OI Problems Contest cqr的长乐集训2023 CZYZ LOC New Game NOI NOIP Password Protected PM_PK Preview Problems Retrospect Selfmade Qusetion STL The end Training Uneasy Problem 蒟蒻 通报

  • 训练日志
  • 链表
  • 入门
  • 模拟
  • dfs序
  • 并查集
  • spfa
  • 最小割
  • 矩阵树定理
  • 仙人掌
  • BSGS
  • 凸包
  • 回文自动机
  • 递推与动归
  • 堆
  • 莫队算法
  • ST表
  • Treap
  • 树套树
  • 可持久化线段树
  • 初赛
  • 搜索
  • 贪心
  • 深度优先搜索
  • 欧拉图
  • dijkstra
  • 费用流
  • 哈夫曼树
  • kruskual
  • 置换
  • 旋转卡壳
  • KMP
  • 区间动归
  • STL
  • 链表
  • 可并堆
  • sply
  • 主席树
  • 可持久化字典树
  • 算法
  • 动态规划
  • 构造
  • 广度优先搜索
  • 最短路
  • floyd
  • 最大流
  • 虚树
  • prim
  • 筛法
  • 半平面交
  • 字典树
  • 背包动归
  • 基础数据结构
  • 分块
  • 线段树
  • 替罪羊树
  • K-DTree
  • 图论
  • 二分法
  • 迭代搜索
  • 拓扑排序
  • 有上下界网络流
  • 生成树
  • 快速幂
  • 后缀数组
  • 树形动归
  • 哈希表
  • 中级数据结构
  • 平衡树
  • 可持久化数据结构
  • 数据结构
  • 三分法
  • 启发式搜索
  • 图的连通
  • 点分治
  • 博弈论
  • AC自动机
  • 状压动归
  • 单调栈
  • 树状数组
  • 高级数据结构
  • OI资料
  • 数学
  • 高精度
  • 差分约束
  • 树上倍增
  • 素数测试
  • 后缀自动机
  • 数位动归
  • 单调队列
  • 新闻
  • 几何
  • 随机化
  • 二分图染色
  • 树链剖分
  • 欧拉函数
  • manacher
  • 斜率优化
  • 离线处理
  • 信息学奥赛学长风采
  • 字符串
  • 二分图匹配
  • prufer编码
  • 卡特兰数
  • 密码学
  • 决策单调
  • 赛后总结
  • 其他
  • 2-SAT
  • 最近公共祖先
  • 矩阵乘法
  • 记忆化搜索
  • 网络流
  • Link cut tree
  • 排列组合
  • 树
  • 高斯消元
  • 乘法逆元
  • 容斥原理
  • 调和级数
  • 概率与期望
  • 模线性方程组
  • 莫比乌斯反演
  • 快速傅里叶变换
  • 扩展欧几里德
  • 最大公约数与最小公倍数

近期文章

  • DP杂题
  • 2025年2月13日模拟赛
  • HLOJ-TEST ROUND 4-T1/T2(构造)- 3
  • HLOJ-TEST ROUND 4-T1/T2(构造)- 2
  • HLOJ-TEST ROUND 4-T1/T2(构造)- 1

近期评论

归档

  • 2025年2月
  • 2025年1月
  • 2024年11月
  • 2024年10月
  • 2024年9月
  • 2024年8月
  • 2024年7月
  • 2024年3月
  • 2024年2月
  • 2024年1月
  • 2023年12月
  • 2023年11月
  • 2023年10月
  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月

Copyright © 2025 泉州一中信息学Blog.

Powered by PressBook WordPress theme