Skip to content

泉州一中信息学Blog

信息学奥赛技术分享博客

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

赛前集训DAY2

Posted on 2023年10月19日 By 学伟宸 赛前集训DAY2无评论

342->500
有参照标程的以下都直接放标程

T1

埃式筛

#include<bits/stdc++.h>
using namespace std;
int pre[100005],t[100005],n;
bool vis[100005],mpp[100005];
inline void prime(int n){
    int p=1;
    for(int i=2;i<=n;i++){
        if(!vis[i]){
            pre[p]=i;
            mpp[i]=true;
            p++;
            for(int j=1;j<=n/i;j++){
                vis[j*i]=true;
                int q=i*j;
                while(q%i==0){
                    t[i*j]++;
                    q/=i;
                }
            }
        }
        else{
            continue;
        }
    }
}
int main(){
    freopen("lucky.in","r",stdin);
    freopen("lucky.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n;
    prime(100000);
    for(int i=4;i<=n;i++){
        if(mpp[t[i]]==true){
            cout<<i<<endl;
        }
    }
    return 0;
}

T2

签到题,然而没看到字符限制导致乱码
以下标程

#include <cstdio>
#include <cstring>
using namespace std;
char s[210];
int n;

bool check(int x)
{
    if (x == 1 || x == n || s[x] != &#039;-&#039;) return 0;
    if (s[x - 1] >= &#039;a&#039; && s[x - 1] <= &#039;z&#039; && s[x + 1] >= &#039;a&#039; && s[x + 1] <= &#039;z&#039; && s[x - 1] < s[x + 1]) return 1;
    if (s[x - 1] >= &#039;0&#039; && s[x - 1] <= &#039;9&#039; && s[x + 1] >= &#039;0&#039; && s[x + 1] <= &#039;9&#039; && s[x - 1] < s[x + 1]) return 1;
    return 0;
}

int main()
{
    freopen("expand.in", "r", stdin);
    freopen("expand.out", "w", stdout);
    scanf("%s", s + 1); n = strlen(s + 1);
    for(int i = 1; i <= n; i++)
        if (check(i))
            for(int j = s[i - 1] + 1; j < s[i + 1]; j++) putchar(j);
        else putchar(s[i]);
    puts("");
    return 0;
}

T3

优先队列,记得scanf或者快读优化

#include<bits/stdc++.h>
using namespace std;
#define ll int
struct cmp{
    bool operator()(const ll &a,const ll &b){
        return a>b;
    }
};
priority_queue<ll,vector<ll>,cmp> q;
int main(){
    freopen("number.in","r",stdin);
    freopen("number.out","w",stdout);
    ll n,k;
    char s[5];
    scanf("%d",&n);
    for(ll i=1;i<=n;i++){
        scanf("%s",s);
        if(s[0]==&#039;i&#039;){
            scanf("%d",&k);
            q.push(k);
        }
        else{
            printf("%d\n",q.top());
            q.pop();
        }
    }
    return 0;
}

T4

二维前缀和
以下标程

#include<bits/stdc++.h>
using namespace std;
int n,m,a[305][305],ans;
int main()
{
    freopen("paint.in","r",stdin);
    freopen("paint.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            a[i][j]+=a[i][j-1]+(a[i-1][j]-a[i-1][j-1]);
        }
    }
    for(int k=2;k<=min(n,m);k++){
        int c=k*k;
        for(int i=0;i<=n-k;i++){
            for(int j=0;j<=m-k;j++){
                if(abs(2*(a[i+k][j+k]-a[i+k][j]-a[i][j+k]+a[i][j])-c)<=1){
                    ans++;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}

T5

区间DP

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[35],dp[35][35],b[35],n,m,maxx,ans;
ll pw(ll p,ll q){
    ll re=1;
    while(q){
        if(q&1) re*=p;
        q>>=1;
        p*=p;
    }
    return re;
}
int main()
{
    freopen("game.in","r",stdin);
    freopen("game.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    b[0]=1;
    for(ll i=1;i<=m;i++){
        b[i]=2*b[i-1];
    }
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            cin>>a[j];
        }
        maxx=-1;
        for(ll j=1;j<=m;j++){
            for(ll k=m;k>=j;k--){
                dp[j][k]=max(dp[j][k+1]+a[k+1]*b[m-k+j-1],dp[j-1][k]+a[j-1]*b[m-k+j-1]);
            }
            dp[j][j]+=a[j]*b[m];
            maxx=max(maxx,dp[j][j]);
        }
        ans+=maxx;
    }
    cout<<ans;
    return 0;
}

总结

如果CSP-J也这么简单……

训练日志

文章导航

Previous Post: 东海集训 Day2
Next Post: 赛前集训Day2

发表回复 取消回复

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

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