前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >河工院首届工业设计大赛程序组(挑战赛)题解

河工院首届工业设计大赛程序组(挑战赛)题解

作者头像
浪漫主义狗
发布于 2024-08-07 04:15:42
发布于 2024-08-07 04:15:42
9900
代码可运行
举报
文章被收录于专栏:HAUE_LYS'BlogHAUE_LYS'Blog
运行总次数:0
代码可运行

本文最后更新于 91 天前,其中的信息可能已经有所发展或是发生改变。

寻找ACMer

思想:

  • 签到题
  • 按照题意遍历字符串,不断向后寻找包含 ACMer 完整字符串的数量即可

std标程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);

void solve(){

    string s; cin >> s;
    int idx = 0;
    int ans = 0;
    while(s.find("ACMer", idx) != -1) {
        ans ++; idx = s.find("ACMer", idx) + 1;
    }
    cout << ans << endl;

}

int main(){

    IOS;

    int _ = 1;

    // cin >> _;

    while(_ --){
        solve();
    }

    return 0;

}

欧拉幻树苗

思想:

  • 树形DP
  • 始化每一个节点为独立的连通分量,即每个节点自身就是一个树的根。
  • 读取树的结构,确保我们可以通过 g 数组访问到每个节点的孩子节点。
  • 读取特殊边,并使用并查集合并特殊边的两个端点。由于题目保证特殊边的两个端点深度相同,合并这些端点不会导致环的出现。
  • 然后开始广度优先搜索。从根节点(节点1)开始,用队列来记录接下来需要访问的节点。
  • 对于当前节点 t,如果它是叶子,将 find(t) 的路径数加到答案中(即cnt[find(t)]),因为从叶子节点可以直接走到根节点。
  • 遍历当前节点t的所有孩子节点,将父节点到当前节点的路径数累加到孩子节点上(需要通过find函数找到孩子节点所在的连通分量),然后将这些孩子节点加入队列中以进行下一轮搜索。
  • 当队列为空时,所有节点都被访问过,搜索结束。最后输出计算的答案 ans。

std标程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int N   =   1e6  +  3;
const int INF   =   0x3f3f3f3f, mod   =   1e9  +  7;
const double eps   =   1e-6, PI   =   acos(-1);

int f[N], cnt[N];  // f数组用于并查集,cnt数组用于记录路径数

vector<int> g[N];  // g数组用来存储树的结构

int find(int x){
    return f[x] == x ? x : f[x]  =  find(f[x]);
}

void solve() {
    int n, m; cin >> n >> m;
    for(int i = 1; i <= n; i ++) f[i] = i; // 初始化
    for(int i = 1; i < n; i ++){
        int x, y; cin >> x >> y; // 读取树的结构
        g[y].push_back(x); // 假设每条边是从子节点指向父节点
    }
    for(int i = 1; i <= m; i ++){
        int x, y; 
        cin >> x >> y; // 输入特殊边
        f[find(x)] = find(y); // 合并特殊边的端点
    }
    queue<int> q;
    q.push(1);
    cnt[1] = 1; // 根节点的路径数为1
    int ans = 0; // 结果变量
    while(!q.empty()){
        int t = q.front();
        q.pop();
        if(g[t].empty()) (ans += cnt[find(t)]) %= mod; // 如果t是叶子节点,累加路径数
        for(auto i:g[t]){
            (cnt[find(i)] += cnt[find(t)]) %= mod; // 将当前节点的路径数累加到其孩子节点
            q.push(i); // 将孩子节点加入队列
        }
    }
    cout << ans; 
}

int main(){

    IOS;

    int _   =   1;
    //cin >> _;
    while(_ --){
        solve();
    }

    return 0;
}

疯狂蓝桥杯

本题主要考察四舍五入,C语言中是四舍六入,但是需要四舍五入,则在结果后面加上0.001即可。

std标程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include<bits/stdc++.h>

using namespace std;
#define int long long 
signed main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n,m,x,y;
        cin>>n>>m>>x>>y;
        int z=n*y,zz=m*x;
        int zzz=z*zz/__gcd(z,zz);
        int i=zzz/z,j=zzz/zz;
        double s=sqrt(n*n*i*i+m*m*j*j) * 2; 
        s+=0.001;
        printf("%.2lf\n",s);
    } 
    return 0;
} 

Inception Ⅰ

用数组(如st)记录每个数字出现的次数,从1枚举到 (m + 1)/ 2 (不含),所有 st[i] * st[m - i]的和,注意要开long long~

std标程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <iostream>

using namespace std;

const int N = 1e6 + 20;
int n, m, st[N];
long long ans;

int main()
{
    int x;
    cin >> n >> m;

    for(int i = 1; i <= n; i ++)
    {
        cin >> x;
        st[x] ++;
    }

    for(int i = 0; i < m - i; i ++)
    {
        ans += (long long)st[i] * st[m - i];
    }

    cout << ans;
    return 0;
}

Inception Ⅱ

循环枚举判断是否存在连续三个字母/四个元素组成的回文数组,(易证所有长度大于2的回文都包含这两种回文之一),定义数组记录下标为 i 的元素向后找最近的回文数组右端点的距离,如 1 1 2 2 1,对应记录数组应为 4,3,0,0,0。对每次查找的时间复杂度缩小到O(1)。

std标程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <iostream>

using namespace std;

const int N = 1e6 + 20;
int n, q[N], s[N];

int main()
{
    int t;
    scanf("%d %d", &n, &t);

    for (int i = 1; i <= n; i ++)
    {
        scanf("%d", &q[i]);
    }

    for (int i = 1; i <= n; i ++)
    {
        //偶数回文
        if (i + 3 <= n)
        {
            if(q[i] == q[i + 3] && q[i + 1] == q[i + 2]) s[i] = 3;
        }
        //奇数回文
        if (i + 2 <= n)
        {
            if (q[i] == q[i + 2]) s[i] = 2;
        }
    }

    int f = 0;
    for (int i = n; i > 0; i --)
    {
        if (s[i] && !f) f = 1;
        if (f && !s[i]) s[i] = s[i + 1] + 1;
    }

    int l, r;
    while(t --)
    {
        scanf("%d %d", &l, &r);

        if (!s[l]) printf("NO\n");
        else if (l + s[l] <= r) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}

Inception Ⅲ

易证,当 n == 1 或 n == 2 时,图腾陀螺可一步取胜,除此之外,Belinra均可胜利(想什么呢,这可是Belinra的主场,给你先手是客套,怎么可能让你轻易取胜)

std标程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <iostream>

using namespace std;

int main()
{
    int n; cin >> n;
    if (n == 1 || n == 2) cout << "None life is but a dream .";
    else cout << "Wake up now !";
    return 0;
}

憧憬成为AK大神

思想:

  • 贪心
  • 有题目可知,到了某一个点都不能可能再往回走(回头一定不是最优解,否则在原来就已经进去AK了)
  • 先对页面编号排序,然后用一个大根堆来维护从起始页面切换到当前这个页面的已AK的场次所消耗的时间
  • 如果所有的时间消耗(切换界面的时间+对应场次让出的时间)已大于规定的时间,则该方向上的时间不可避免
  • 所以只能少切换界面,因为每一场比赛都AK一次,即将让出时间最大的页面跳过即可

std标程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);

priority_queue<LL> q;

PLL a[N];

bool cmp(PLL &a, PLL b) {
    return a.fi < b.fi;
}

LL n, m, ans, res, sum, idx;

void solve(){
    cin >> n >> m;
    for (int i = 0; i <= n; i ++) {
        LL x, y; cin >> x >> y;
        a[++ idx].fi = x;
        a[idx].se = y;
    }
    sort(a + 1, a + n + 1, cmp);
    for(int i = 1; i <= n; i ++) {
        res += a[i].fi - a[i - 1].fi; //切换到 i 页面所用时间 
        q.push(a[i].se); // sum 的欲望 
        sum ++;
        res += a[i].se;
        while(!q.empty() && res > m) //如果用的时间多于m,直接ak掉 
        {
            sum --;
            res -= q.top();
            q.pop();
        }
        if(res > m) break; 
        ans = max(ans, sum); 
    }
    cout << ans << endl;
}

int main(){

    IOS;

    int _ = 1;

    // cin >> _;

    while(_ --){
        solve();
    }

    return 0;

}

高精度拼接

由于每添加一个数都需要满足 a % b == 0,故第一次从 0 到 9 枚举,如果存在满足条件的数直接输出即可,紧接着输出 n - 1 个 0,否则输出 -1

std标程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <stdio.h>

int main()
{
    int a, b, c, ans = -1;
    scanf("%d %d %d", &a, &b, &c);
    for (int i = 0; i <= 9; i ++)
    {
        if ((a * 10 + i) % b == 0)
        {
            ans = a * 10 + i;
            break;
        }
    }
    if (ans != -1)
    {
        printf("%d", ans);
        for (int i = 1; i <= c - 1; i ++)
            printf("0");
    }
    else
    {
        printf("-1");
    }
    return 0;
}

逆矩阵

  • 签到题,模拟

std标程:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);

void solve(){
    int n; cin >> n;
    int size = n;
    n *= n;
    vector<vector<int>> ans(size, vector<int>(size, 0));
    int num = 1;
    int top = 0, st = size - 1, left = 0, right = size - 1;
    while(num <= n) {
        for(int i = top; i <= st && num <= n; i++) {
            ans[i][left] = num++;
        }
        left++; 
        for(int i = left; i <= right && num <= n; i++) {
            ans[st][i] = num++;
        }
        st--;
        for(int i = st; i >= top && num <= n; i--) {
            ans[i][right] = num++;
        }
        right--;
        for(int i = right; i >= left && num <= n; i--) {
            ans[top][i] = num++;
        }
        top++;
    }
    for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j++) {
            if (ans[i][j] != 0) {
                cout << ans[i][j] << " ";
            }
        }
        cout << endl;
    }
}

int main(){

    IOS;

    int _ = 1;

    // cin >> _;

    while(_ --){
        solve();
    }

    return 0;

}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-5-06 2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
PL/SQL 联合数组与嵌套表
      通常情况下,在PL/SQL中,处理单行单列的数据可以使用标量变量,而处理单行多列的数据则使用PL/SQL记录是不错的选择。单列多行数据 则由联合数组或嵌套表来完成,其特点是类似于单列数据库表。在Oracle 9i 之前称为PL/SQL索引表,9i 之后称之为联合数组。嵌套表也是集合 类型中的一种,下面分别介绍这两种集合数据类型的使用方法。
Leshami
2018/08/14
1.4K0
通过闪回事务查看数据dml的情况 (r2笔记69天)
昨天有一个网友问我,怎么能够查询一个表中最后一条插入的记录,我大概回复了,可以通过闪回事务来实现,但是得看什么时候插入的数据,也需要一定的运气。 如果通过闪回事务来得到对应的undo_sql,可能多个dml语句对应一个事务,所以我们需要得到的是一个完整的事务的信息,里面包括对应的Undo_sql,这样才算得到比较完整的sql语句。 我在本地自己做了一个测试。 创建一个test表,然后插入一些记录,然后尝试修改一些数据。 SQL> DROP TABLE TEST; Table dropped. SQL>
jeanron100
2018/03/14
5350
ORA-06502 assigning values from SQL to PL/SQL variables
    最近SQL查询返回的结果给PL/SQL变量出现ORA-06502错误。这个错误的描述是ORA-06502: PL/SQL: numeric or value error: character string buffer too small. 显而易见的是字符变量定义的长度不够,加到20,到100,继续06502,汗,咋回事呢?
Leshami
2018/08/14
7870
深入解析:你听说过Oracle数据库的更新重启动吗?
杨廷琨 云和恩墨高级咨询顾问, ITPUB Oracle 数据库管理版版主 ,人称 “杨长老”,十数年如一日坚持进行 Oracle 技术研究与写作,号称 “Oracle 的百科全书”。迄今已经在自己的博客上发表了超过 3000 篇技术文章。2010 年,与 Eygle 共同主编出版了《Oracle DBA 手记》一书,2007 年被 Oracle 公司授予 ACE 称号。
数据和云
2018/07/27
7140
深入解析:你听说过Oracle数据库的更新重启动吗?
【DB笔试面试811】在Oracle中,什么是闪回事务查询(Flashback Transaction Query)?
在Oracle中,什么是闪回事务查询(Flashback Transaction Query)?
AiDBA宝典
2020/06/04
6440
ORA-60死锁的实验
SQL> create table tbl_ora_60 (      id number(5),      name varchar2(5)      ); SQL> insert into tbl_ora_60 values(1, 'a'); 1 row created. SQL> insert into tbl_ora_60 values(2, 'b'); 1 row created. SQL> commit; Commit complete. SQL> select * from tbl_ora_60;         ID NAME ---------- -----          1 a          2 b 实验开始 Session1: SQL> update tbl_ora_60 set name='c' where id=1; 1 row updated. Session2: SQL> update tbl_ora_60 set name='d' where id=2; 1 row updated. Session1: SQL> update tbl_ora_60 set name='e' where id=2; hang住 Session2: SQL> update tbl_ora_60 set name='f' where id=1; hang住 此时,Session1: SQL> update tbl_ora_60 set name='e' where id=2; update tbl_ora_60 set name='e' where id=2        * ERROR at line 1: ORA-00060: deadlock detected while waiting for resource 说明: Session1                                            Session2 获取id=1的资源锁                                                         获取id=2的资源锁 等待id=2的资源锁                                                         等待id=1的资源锁 id=2的SQL报ORA-60,自动rollback 1、因为id=2的资源锁是Session2先获取的,因此Oracle会自动rollback产生死锁时后需要资源锁的SQL,Session1的更新id=2操作被rollback。 2、从中可以发现,真正报ORA-60错误的SQL获取的资源(此例中id=2),并不是触发死锁产生的那个资源(此例中id=1),此例用的是同一个表的不同行,对不同表的相同行也如此,也可以解释之前夜维出现ORA-60时显示的SQL之间表是不同的原因,因为夜维执行的某个表更新与当前应用执行的某个表更新之间存在互锁的情况,因此可能导致夜维SQL报ORA-60或应用报ORA-60的错误。 此时,Session1: SQL> select * from tbl_ora_60;         ID NAME ---------- -----          1 c          2 b 说明:此处可以证明产生报错后,Oracle自动执行的rollback操作是基于单条SQL,不是整个事务的,所以这里只有id=2的记录被rollback,id=1的执行仍正常。 Session2: SQL> update tbl_ora_60 set name='f' where id=1; hang住 继续,Session1: SQL> commit; Commit complete. Session2: SQL> update tbl_ora_60 set name='f' where id=1; 1 row updated. Session1: SQL> select * from tbl_ora_60;         ID NAME ---------- -----          1 c          2 b 只有id=1更新成功。 Session2: SQL> select * from tbl_ora_60;         ID NAME ---------- -----          1 f          2 d id=1和id=2都更新成功,但未COMMIT。 SQL> commit; Commit complete. Sess
bisal
2019/01/29
5000
SQL在DBA手里-变装篇(9亿+表自关联)
在每天的AWR报告巡检中发现一性能SQL情况,发现 db file sequential read等待事件消耗在User I/O,再看SQL有个UPDATE语句16.81%的IO消耗,然后再查看这张表的数据达到了9亿+,大表还自关联,头痛来袭。
布衣530
2025/01/26
921
SQL在DBA手里-变装篇(9亿+表自关联)
Oracle 触发器详解(trigger)「建议收藏」
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/157665.html原文链接:https://javaforall.cn
全栈程序员站长
2022/09/14
4K0
PL/SQL变长数组
  PL/SQL变长数组时PL/SQL集合数据类型中的一种,其使用方法与PL/SQL嵌套表大同小异,唯一的区别则是变长数组的元素的最大个数是有限 制的。也即是说变长数组的下标固定下限等于1,上限可以扩展。下面给出具体的描述及其使用方法。
Leshami
2018/08/14
9340
ORACLE触发器具体解释
触发器是很多关系数据库系统都提供的一项技术。在ORACLE系统里,触发器类似过程和函数,都有声明,运行和异常处理过程的PL/SQL块。
全栈程序员站长
2022/07/13
1.2K0
Oracle 20c 新特性:区块链表提供基于 Oracle 的集中式区块应用
导读:区块链表是仅插入表(Only-Insert),将行组织成许多链。通过使用加密哈希将链中除第一行之外的每一行链接到链中的前一行。
数据和云
2020/02/24
8220
Oracle 20c 新特性:区块链表提供基于 Oracle 的集中式区块应用
Oracle PL/SQL入门语法点
PL_SQL:带有分支和循环,面向过程 匿名块: declare(可选,声明各种变量和游标的地方) begin(必要的,从此开始执行) exception(抓取到异常后执行的) end; [sql] view plaincopy set serveroutput on;(默认是关闭) --最简单的PL/SQL语句块 begin dbms_output.put_line('HelloWorld!'); end; --最简单的语句块 declare v_name varchar2(20); be
java干货
2021/02/19
5050
PL/SQL --> INSTEAD OF 触发器
INSTEAD OF 触发器常用于管理编写不可更新的视图,INSTEAD-OF触发器必须是行级的。
Leshami
2018/08/07
6450
NULL 值与索引(一)
    NULL值是关系数据库系统布尔型(true,false,unknown)中比较特殊类型的一种值,通常称为UNKNOWN或空值,即是未知的,不确定的。由于 NULL存在着无数的可能,因此NULL值也不等于NULL值,所以与NULL值相关的操作同样都为NULL值。正是基于这样一个特性,对于NULL值列上的B 树索引导致了is null/is not null不走索引的情形,下面描述了NULL值与索引以及索引NULL列上的执行计划,如何使得NULL值走索引的情形。 注:本文仅仅讨论的是B树索引上的NULL值,位图索引不在此范围之内。 一、null值与索引的关系
Leshami
2018/08/14
1.6K0
一道SQL考题的思考
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
bisal
2019/12/10
3950
一道SQL考题的思考
Oracle数据库之第四篇
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
海仔
2019/10/22
9810
变与不变: Undo构造一致性读的例外情况
嘉年华听了恩墨学院的一个主题:《重现ORA-01555 细说Oracle 12c Undo数据管理》,吕星昊老师介绍了UNDO的概念以及ORA-1555的产生,并介绍了12c以来Oracle的UNDO相关的新特性。
数据和云
2018/12/18
4340
变与不变: Undo构造一致性读的例外情况
plsql编程语言_编程语言有哪些
–pl/sql编程语言 –pl/sql编程语言是对sql语言的扩展,是的sql语言具有过程化编程的特性 –pl/sql编程语言比一般的过程化编程语言,更加灵活高效 –pl/sql编程语言主要用来编写存储过程和存储函数等。
全栈程序员站长
2022/09/27
14.1K0
对比 PL/SQL profiler 剖析结果
      使用PL/SQL PROFILER 剖析PL/SQL代码是快速定位PL/SQL代码段最有效的方法。在上一篇文章使用PL/SQL PROFILER 定位 PL/SQL 瓶颈代码中描述了安装PROFILER,并给出了剖析的示例。本文参照了Tom大师的代码来对比剖析前后的性能并附上其代码。
Leshami
2018/08/13
5860
关于字符串匹配查找的总结(43天)
判断一个字符型字段中出现某个字符超过3次的数据行,如果为了简单达到目的,可以直接使用Like来做, SQL> select content from clob_test where content like '%is%is%is%'; CONTENT -------------------------------------------------------------------------------- this is a test,and it is very useful 但是可能在实际应用中,
jeanron100
2018/03/13
9340
相关推荐
PL/SQL 联合数组与嵌套表
更多 >
LV.4
vivo后台开发工程师
目录
  • 寻找ACMer
    • std标程:
  • 欧拉幻树苗
    • std标程:
  • 疯狂蓝桥杯
    • std标程:
  • Inception Ⅰ
    • std标程:
  • Inception Ⅱ
    • std标程:
  • Inception Ⅲ
    • std标程:
  • 憧憬成为AK大神
    • std标程:
  • 高精度拼接
    • std标程:
  • 逆矩阵
    • std标程:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档