Skip to content

泉州一中信息学Blog

信息学奥赛技术分享博客

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

长乐集训Day7

Posted on 2023年10月3日 By 王子晔, 王子晔 长乐集训Day7无评论

NOIP2023 国庆集训 A 组 Day7

A. 字母还原(restore)

水题,由于第一种加密方式最容易得出字符串s,所以我们枚举三个串,哪一个可能是s经过第一种加密得来的.然后再枚举k进行验证剩下两个串即可

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10100;
string s[3];
char a[]="abcdefghijklmnopqrstuvwxyz",c[N];
inline ll read() 
{
    ll x = 0, f = 1;
    char c = getchar();
    while (!isdigit(c) && c != &#039;-&#039;) c = getchar();
    if (c == &#039;-&#039;)
        f = -1, c = getchar();
    while (isdigit(c)) x = x * 10 + c - &#039;0&#039;, c = getchar();
    return f * x;
}
int check(char x[],string y,int z,int o)
{
    for(int i=0;i<z;i++)
    {
        if(a[(y[i]-&#039;a&#039;+o+26)%26]!=x[i])
        {
            return 0;
        }
    }
    return 1;
}
int main()
{
    freopen("restore.in", "r", stdin);
    freopen("restore.out", "w", stdout);
    int n=read();
    cin>>s[0]>>s[1]>>s[2];
    for(int i=0;i<3;i++)
    {
        c[n]=&#039;\0&#039;;
        for(int j=0;j<n;j++)
        {
            c[j]=s[i][n-1-j];
        }
        for(int j=0;j<3;j++)
        {
            if(j!=i)
            {
                for(int k=0;k<=6;k++)
                {
                    if(check(c,s[j],n,k))
                    {
                        for(int l=0;l<3;l++)
                        {
                            if(l!=i&&l!=j)
                            {
                                if(check(c,s[l],n,-k))
                                {
                                    cout<<c<<endl;
                                    return 0;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return 0;
}

B. 棋盘染色(board)

暴力模拟三十分

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1010;
const int N1=100100;
ll ans;
int a[N][N1];
inline ll read() 
{
    ll x = 0, f = 1;
    char c = getchar();
    while (!isdigit(c) && c != &#039;-&#039;) c = getchar();
    if (c == &#039;-&#039;)
        f = -1, c = getchar();
    while (isdigit(c)) x = x * 10 + c - &#039;0&#039;, c = getchar();
    return f * x;
}
int main()
{
    freopen("board.in","r",stdin);
    freopen("board.out","w",stdout);
    int n=read(),m=read(),q=read();
    while(q--)
    {
        int x=read(),y=read(),z=read();
        if(x==0)
        {
            if(z==0)
            {
                for(int i=1;i<=m;i++)
                {
                    a[i][y]=0;
                }
            }
            if(z==1)
            {
                for(int i=1;i<=m;i++)
                {
                    a[i][y]=1;
                }
            }
        }
        if(x==1)
        {
            if(z==0)
            {
                for(int i=1;i<=n;i++)
                {
                    a[y][i]=0;
                }
            }
            if(z==1)
            {
                for(int i=1;i<=n;i++)
                {
                    a[y][i]=1;
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j])
            {
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

C. 为你写串(string)

水题,易得一个 a 到达末尾的步数为该字符到末尾之间 b 的个数。可以发现每个 a 在操作过程中相对位置不会改变,所以必须等后一个 a 到达末端,该 a 才能到最后。那么每个 a 到达末尾的步数事实上已经固定了,为了方便,我们倒序将 a 移动至末尾,并记录移动后 b 的数量即可。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000100;
const ll mod = 1000000007;
ll a[N];
ll ans = 0;
char s[N];
inline ll read() {
    ll x = 0, f = 1;
    char c = getchar();
    while (!isdigit(c) && c != &#039;-&#039;) c = getchar();
    if (c == &#039;-&#039;)
        f = -1, c = getchar();
    while (isdigit(c)) x = x * 10 + c - &#039;0&#039;, c = getchar();
    return f * x;
}
int main() {
    freopen("string.in", "r", stdin);
    freopen("string.out", "w", stdout);
    scanf("%s", s);
    int n = strlen(s), m = 0, o = 0;
    s[n] = &#039;a&#039;;
    for (int i = n - 1, j = n; i >= 0; --i) {
        if (s[i] == &#039;a&#039;) {
            a[++m] = j - i - 1;
            j = i;
        }
    }
    for (int i = 1; i <= m; ++i) {
        ans = (ans + a[i]) % mod;
        a[i + 1] = (a[i] * 2 + a[i + 1]) % mod;
    }
    cout << ans << endl;
    return 0;
}

D. 货物分组(package)

无优化DP30分

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+100;
int a[N],dp[N],sum[N];
inline ll read() 
{
    ll x = 0, f = 1;
    char c = getchar();
    while (!isdigit(c) && c != &#039;-&#039;) c = getchar();
    if (c == &#039;-&#039;)
        f = -1, c = getchar();
    while (isdigit(c)) x = x * 10 + c - &#039;0&#039;, c = getchar();
    return f * x;
}
int main()
{
    freopen("package.in", "r", stdin);
    freopen("package.out", "w", stdout);
    memset(dp,0x3f,sizeof(dp));
    int n=read(),m=read();
    for(int i=1;i<=n;i++)
    {
        a[i]=read();
    }
    for(int i=1;i<=n;i++)
    {
        sum[i]=sum[i-1]+a[i];
    }
    dp[0]=sum[n];
    for(int i=1;i<=n;i++)
    {
        int cnt=0,maxx=0,minn=INT_MAX;
        for(int j=i;j>=1;j--)
        {
            cnt+=a[j];
            maxx=max(maxx,a[j]);
            minn=min(minn,a[j]);
            if(cnt>m) 
            {
                break;
            }
            dp[i]=min(dp[i],dp[j-1]+maxx-minn);
        }
        dp[i]+=sum[n]-sum[i];
    }
    printf("%lld",dp[n]);
    return 0;
}

今天260

训练日志

文章导航

Previous Post: 长乐Day 5
Next Post: 长乐集训 Day 5

发表回复 取消回复

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

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