石家庄学院2023年大学生程序设计大赛题解

A、大臣的旅费

floyd求最短路径

#include <iostream>using namespace std;int d[1005][1005];
int n;
int res;int f(int x) {// 等差数列return ((11 + x + 10) * x) / 2;
}void init() {for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {if (i == j) d[i][j] = 0;else d[i][j] = 0x3f3f3f3f;}}
}void floyd() {for (int k = 1; k <= n; k++) {for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {d[i][j] = min(d[i][j], d[i][k] + d[k][j]);}}}
}void add(int x, int y, int q) {d[x][y] = q, d[y][x] = q;
}int main() {cin >> n;int ans;init();for (int i = 0; i < n - 1; i++) {int x, y, q;cin >> x >> y >> q;add(x, y, q);}floyd();for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {ans = max(ans, d[i][j]);}}cout << f(ans);
}

B、汽水瓶

模拟

#include <bits/stdc++.h> 
using namespace std;int solve(int x) {int ans = 0;int n = x;while(1) {if (n < 2) return ans;if (n == 2) n++; ans += n / 3;n = n % 3 + n / 3;} return 0;
}int main() {int n;while(1) {scanf("%d",&n);if(n == 0) break; cout << solve(n) << endl; }return 0;
}

C、奖学金

结构体排序

#include <bits/stdc++.h> 
using namespace std;typedef struct stu {int n;int a;int b;int c;int sum;
} Stu;vector<Stu> v;bool cmp(Stu a, Stu b) {if(a.sum !=  b.sum)return a.sum > b.sum;if (a.a != b.a) return a.a > b.a;if (a.n != b.n) return a.n < b.n;
}int main() {int n;cin >> n;for(int i = 1; i <= n; i++) {int a,b,c;cin >> a >> b >> c;Stu temp;temp.a = a;temp.b = b;temp.c = c; temp.sum = a + b + c;temp.n = i;v.push_back(temp);}	sort(v.begin(), v.end(), cmp);for(int i = 0; i < 5; i++ ) {cout << v[i].n << " " << v[i].a + v[i].b + v[i].c  << endl;}return 0;
}

D、金牌厨师

差分、模拟

#include <bits/stdc++.h> 
using namespace std;int idx[300010];int main() {int n, m;cin >> n >> m;int ans = 0;for(int i = 0; i < n; i++) {int x, y;cin >> x >> y;idx[x]++, idx[y + 1]--;}	for(int i = 1; i <= n; i++) {idx[i] += idx[i - 1];}for(int i = 1; i <= n; i++) {ans = max(ans,min(idx[i], n - i));}cout << ans << endl;return 0;
}

F、机器人行走

字符串处理

#include <bits/stdc++.h> 
using namespace std;typedef long long LL;int dir[4][2] = {{1, 0}, {0,1},{-1,0},{0,-1} 
};int dirNow = 400;int solve() {int x = 0, y = 0;string s;cin >> s;int num = 0;for(int i = 0; i < s.length(); i++) {if(s[i] == 'L' || s[i] == 'R') {x += num * dir[dirNow % 4][0];y += num * dir[dirNow % 4][1];num = 0;if(s[i] == 'L' ) dirNow++;if(s[i] == 'R' ) dirNow--;} else {num *= 10;num += s[i] - '0' ;}} x += num * dir[dirNow % 4][0];y += num * dir[dirNow % 4][1];if(x < 0) x = -x;if(y < 0) y = -y;dirNow = 400;printf("%0.2f\n", sqrt(x * x + y * y));return 0;
}int main()  {int n;cin >> n;while(n--) solve();return 0;
}

G、素数回文

素数筛、回文数字、预处理

// 预处理#include <iostream>using namespace std;const int N = 1e8 + 5;// primes[]存储所有素数
int primes[N], cnt;
// st[x]存储x是否被筛掉
bool st[N];void get_primes(int n) {for (int i = 2; i <= n; i++) {if (!st[i]) primes[cnt++] = i;for (int j = 0; primes[j] <= n / i; j++) {st[primes[j] * i] = true;if (i % primes[j] == 0) break;}}
}bool check(int x) {string s;while (x) {s += x % 10 + '0';x /= 10;}int l = 0, r = s.length() - 1;while (l <= r) {if (s[l] != s[r]) return false;l++, r--;}return true;
}int main() {get_primes(N);cout << "{";for (int i = 0; i < cnt; i++) {if (check(primes[i])) cout << primes[i] << ",";}cout << "}" << endl;return 0;
}
#include <iostream>
using namespace std;int p[] = {2,3,5,7,11,101,131,151,181,191,313,353,373,383,727,757,787,797,919,929,10301,10501,10601,11311,11411,12421,12721,12821,13331,13831,13931,14341,14741,15451,15551,16061,16361,16561,16661,17471,17971,18181,18481,19391,19891,19991,30103,30203,30403,30703,30803,31013,31513,32323,32423,33533,34543,34843,35053,35153,35353,35753,36263,36563,37273,37573,38083,38183,38783,39293,70207,70507,70607,71317,71917,72227,72727,73037,73237,73637,74047,74747,75557,76367,76667,77377,77477,77977,78487,78787,78887,79397,79697,79997,90709,91019,93139,93239,93739,94049,94349,94649,94849,94949,95959,96269,96469,96769,97379,97579,97879,98389,98689,1003001,1008001,1022201,1028201,1035301,1043401,1055501,1062601,1065601,1074701,1082801,1085801,1092901,1093901,1114111,1117111,1120211,1123211,1126211,1129211,1134311,1145411,1150511,1153511,1160611,1163611,1175711,1177711,1178711,1180811,1183811,1186811,1190911,1193911,1196911,1201021,1208021,1212121,1215121,1218121,1221221,1235321,1242421,1243421,1245421,1250521,1253521,1257521,1262621,1268621,1273721,1276721,1278721,1280821,1281821,1286821,1287821,1300031,1303031,1311131,1317131,1327231,1328231,1333331,1335331,1338331,1343431,1360631,1362631,1363631,1371731,1374731,1390931,1407041,1409041,1411141,1412141,1422241,1437341,1444441,1447441,1452541,1456541,1461641,1463641,1464641,1469641,1486841,1489841,1490941,1496941,1508051,1513151,1520251,1532351,1535351,1542451,1548451,1550551,1551551,1556551,1557551,1565651,1572751,1579751,1580851,1583851,1589851,1594951,1597951,1598951,1600061,1609061,1611161,1616161,1628261,1630361,1633361,1640461,1643461,1646461,1654561,1657561,1658561,1660661,1670761,1684861,1685861,1688861,1695961,1703071,1707071,1712171,1714171,1730371,1734371,1737371,1748471,1755571,1761671,1764671,1777771,1793971,1802081,1805081,1820281,1823281,1824281,1826281,1829281,1831381,1832381,1842481,1851581,1853581,1856581,1865681,1876781,1878781,1879781,1880881,1881881,1883881,1884881,1895981,1903091,1908091,1909091,1917191,1924291,1930391,1936391,1941491,1951591,1952591,1957591,1958591,1963691,1968691,1969691,1970791,1976791,1981891,1982891,1984891,1987891,1988891,1993991,1995991,1998991,3001003,3002003,3007003,3016103,3026203,3064603,3065603,3072703,3073703,3075703,3083803,3089803,3091903,3095903,3103013,3106013,3127213,3135313,3140413,3155513,3158513,3160613,3166613,3181813,3187813,3193913,3196913,3198913,3211123,3212123,3218123,3222223,3223223,3228223,3233323,3236323,3241423,3245423,3252523,3256523,3258523,3260623,3267623,3272723,3283823,3285823,3286823,3288823,3291923,3293923,3304033,3305033,3307033,3310133,3315133,3319133,3321233,3329233,3331333,3337333,3343433,3353533,3362633,3364633,3365633,3368633,3380833,3391933,3392933,3400043,3411143,3417143,3424243,3425243,3427243,3439343,3441443,3443443,3444443,3447443,3449443,3452543,3460643,3466643,3470743,3479743,3485843,3487843,3503053,3515153,3517153,3528253,3541453,3553553,3558553,3563653,3569653,3586853,3589853,3590953,3591953,3594953,3601063,3607063,3618163,3621263,3627263,3635363,3643463,3646463,3670763,3673763,3680863,3689863,3698963,3708073,3709073,3716173,3717173,3721273,3722273,3728273,3732373,3743473,3746473,3762673,3763673,3765673,3768673,3769673,3773773,3774773,3781873,3784873,3792973,3793973,3799973,3804083,3806083,3812183,3814183,3826283,3829283,3836383,3842483,3853583,3858583,3863683,3864683,3867683,3869683,3871783,3878783,3893983,3899983,3913193,3916193,3918193,3924293,3927293,3931393,3938393,3942493,3946493,3948493,3964693,3970793,3983893,3991993,3994993,3997993,3998993,7014107,7035307,7036307,7041407,7046407,7057507,7065607,7069607,7073707,7079707,7082807,7084807,7087807,7093907,7096907,7100017,7114117,7115117,7118117,7129217,7134317,7136317,7141417,7145417,7155517,7156517,7158517,7159517,7177717,7190917,7194917,7215127,7226227,7246427,7249427,7250527,7256527,7257527,7261627,7267627,7276727,7278727,7291927,7300037,7302037,7310137,7314137,7324237,7327237,7347437,7352537,7354537,7362637,7365637,7381837,7388837,7392937,7401047,7403047,7409047,7415147,7434347,7436347,7439347,7452547,7461647,7466647,7472747,7475747,7485847,7486847,7489847,7493947,7507057,7508057,7518157,7519157,7521257,7527257,7540457,7562657,7564657,7576757,7586857,7592957,7594957,7600067,7611167,7619167,7622267,7630367,7632367,7644467,7654567,7662667,7665667,7666667,7668667,7669667,7674767,7681867,7690967,7693967,7696967,7715177,7718177,7722277,7729277,7733377,7742477,7747477,7750577,7758577,7764677,7772777,7774777,7778777,7782877,7783877,7791977,7794977,7807087,7819187,7820287,7821287,7831387,7832387,7838387,7843487,7850587,7856587,7865687,7867687,7868687,7873787,7884887,7891987,7897987,7913197,7916197,7930397,7933397,7935397,7938397,7941497,7943497,7949497,7957597,7958597,7960697,7977797,7984897,7985897,7987897,7996997,9002009,9015109,9024209,9037309,9042409,9043409,9045409,9046409,9049409,9067609,9073709,9076709,9078709,9091909,9095909,9103019,9109019,9110119,9127219,9128219,9136319,9149419,9169619,9173719,9174719,9179719,9185819,9196919,9199919,9200029,9209029,9212129,9217129,9222229,9223229,9230329,9231329,9255529,9269629,9271729,9277729,9280829,9286829,9289829,9318139,9320239,9324239,9329239,9332339,9338339,9351539,9357539,9375739,9384839,9397939,9400049,9414149,9419149,9433349,9439349,9440449,9446449,9451549,9470749,9477749,9492949,9493949,9495949,9504059,9514159,9526259,9529259,9547459,9556559,9558559,9561659,9577759,9583859,9585859,9586859,9601069,9602069,9604069,9610169,9620269,9624269,9626269,9632369,9634369,9645469,9650569,9657569,9670769,9686869,9700079,9709079,9711179,9714179,9724279,9727279,9732379,9733379,9743479,9749479,9752579,9754579,9758579,9762679,9770779,9776779,9779779,9781879,9782879,9787879,9788879,9795979,9801089,9807089,9809089,9817189,9818189,9820289,9822289,9836389,9837389,9845489,9852589,9871789,9888889,9889889,9896989,9902099,9907099,9908099,9916199,9918199,9919199,9921299,9923299,9926299,9927299,9931399,9932399,9935399,9938399,9957599,9965699,9978799,9980899,9981899,9989899};int main() {int a, b;cin >> a >> b; for(int i = 0; i < 781; i ++) {if(p[i] >= a && p[i] <= b) cout << p[i] << endl;}return 0;
}

J、漫漫上学路

模拟

#include <bits/stdc++.h> 
using namespace std;typedef long long LL;int main()  {LL r, y, g;cin >> r >> y >> g;LL ans = 0;int n;cin >> n;while(n--) {LL k, t;cin >> k >> t;if (k == 0) {ans += t;} else if (k == 1) {ans += t;} else if (k == 3) {;} else {// k == 2ans += t + r;}}cout << ans << endl;return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/3283.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Golang对接Ldap(保姆级教程:概念搭建实战)

Golang对接Ldap&#xff08;保姆级教程&#xff1a;概念&搭建&实战&#xff09; 最近项目需要对接客户的LDAP服务&#xff0c;于是趁机好好了解了一下。LDAP实际是一个协议&#xff0c;对应的实现&#xff0c;大家可以理解为一个轻量级数据库。用户查询。比如&#xff…

各种类型游戏的乐趣与魅力

游戏已经成为人们生活中不可或缺的一部分。从家庭娱乐到专业电竞&#xff0c;游戏行业呈现出多姿多彩的景象&#xff0c;吸引着亿万玩家的目光。而游戏的多样性正是其中一大魅力所在。让我们一起探索各种类型游戏的乐趣与魅力吧&#xff01; 动作游戏&#xff1a; 动作游戏以快…

力扣HOT100 - 114. 二叉树展开为链表

解题思路&#xff1a; class Solution {List<TreeNode> list new ArrayList<>();public void flatten(TreeNode root) {recur(root);for (int i 1; i < list.size(); i) {TreeNode pre list.get(i - 1);TreeNode cur list.get(i);pre.left null;pre.right…

使用Shell终端访问Linux

一、实验目的 1、熟悉Linux文件系统访问命令&#xff1b; 2、熟悉常用 Linux Shell的命令&#xff1b; 3、熟悉在Linux文件系统中vi编辑器的使用&#xff1b; 4、进一步熟悉虚拟机网络连接模式与参数配置&#xff01; 二、实验内容 1、使用root帐号登陆到Linux的X-windows…

【Qt 学习笔记】Qt常用控件 | 输入类控件 | Combo Box的使用及说明

博客主页&#xff1a;Duck Bro 博客主页系列专栏&#xff1a;Qt 专栏关注博主&#xff0c;后期持续更新系列文章如果有错误感谢请大家批评指出&#xff0c;及时修改感谢大家点赞&#x1f44d;收藏⭐评论✍ Qt常用控件 | 输入类控件 | Combo Box的使用及说明 文章编号&#xff…

【Qt 学习笔记】Qt常用控件 | 显示类控件 | LCD Number的使用及说明

博客主页&#xff1a;Duck Bro 博客主页系列专栏&#xff1a;Qt 专栏关注博主&#xff0c;后期持续更新系列文章如果有错误感谢请大家批评指出&#xff0c;及时修改感谢大家点赞&#x1f44d;收藏⭐评论✍ Qt常用控件 | 显示类控件 | LCD Number的使用及说明 文章编号&#xf…

梳理 Pytorch 19个方面,70个核心操作全总结!

最新写了很多关于 Pytorch 的文章&#xff0c;喜欢可以从0开始学习&#xff1a; 小白学 PyTorch 系列&#xff1a;这一次&#xff0c;我准备了 20节 PyTorch 中文课程小白学 PyTorch 系列&#xff1a;54个超强 pytorch 操作小白学 PyTorch 系列&#xff1a;9个技巧让你的 PyTo…

wps屏幕录制怎么用?分享使用方法!

数字化时代&#xff0c;屏幕录制已成为我们学习、工作和娱乐中不可或缺的一部分。无论是制作教学视频、分享游戏过程&#xff0c;还是录制网络会议&#xff0c;屏幕录制都能帮助我们轻松实现。WPS作为一款功能强大的办公软件&#xff0c;其屏幕录制功能也备受用户青睐。本文将详…

代码随想录:二叉树15-17

目录 404.左叶子之和 题目 代码&#xff08;后序递归&#xff09; 代码&#xff08;前序迭代&#xff09; 513.找树左下角的值 题目 代码&#xff08;层序迭代&#xff09; 112.路径总和 题目 代码&#xff08;前序迭代&#xff09; 112.路径总和II 题目 代码&…

记录如何用php将多个字符替换成同一个字符

在PHP中&#xff0c;如果你想要将多个不同的字符替换成同一个字符&#xff0c;可以使用str_replace()函数。这个函数可以接收一个包含需要被替换的字符的数组&#xff0c;以及一个表示替换目标的字符串。 以下是使用str_replace()进行多字符替换的基本示例&#xff1a; $text…

Linux读写文件

前言 学习了文件系统&#xff0c;就能理解为什么说Linux下一切皆文件。 语言层面的操作 在c语言的学习中我们可以使用fopen()函数对文件进行操作。 int main() {//FILE * fp fopen("./log.txt", "w");//FILE * fp fopen("./log.txt", "…

TablePlus for Mac/Win:开启高效数据开发新纪元

在当今数字化时代&#xff0c;数据的重要性日益凸显。无论是企业还是个人&#xff0c;都需要一款强大而实用的本地原生数据开发软件来提升工作效率。而 TablePlus for Mac/Win 正是这样一款卓越的工具&#xff0c;它为用户带来了全新的体验&#xff0c;让数据开发变得更加轻松、…

第1次作业

目录 重点内容提要一、误差度量二、浮点数系统三、误差传播四、数值稳定性 作业解析 重点内容提要 一、误差度量 二、浮点数系统 三、误差传播 四、数值稳定性 作业解析

快速部署 Garnet

快速部署 Garnet Garnet 是 Microsoft Research 推出的一种新型远程缓存存储&#xff0c;其设计速度极快、可扩展且延迟低。 Garnet 在单个节点内是线程可扩展的。它还支持分片集群执行、复制、检查点、故障转移和事务。它可以在主内存以及分层存储&#xff08;例如 SSD 和 Az…

2024/4/25 红外遥控代码

51完结撒花&#xff01;&#xff01;&#xff01; 这块如果IR听不懂可以看看那个状态机的相关视频。 Int0.c #include <REGX52.H>void Int0_Init(void) {IT01;IE00;EX01;EA1;PX01; }//void Int0_Routine(void) interrupt 0 //{ // Num; //} Timer0.c #include …

C#中=> “Lambda运算符”

在C#中&#xff0c;> 符号被称为“Lambda运算符”或“Lambda箭头”。它用于连接Lambda表达式中的参数列表和表达式主体&#xff0c;表示函数的输入和输出关系。因此&#xff0c;Lambda运算符充当了将参数映射到表达式的箭头。 Lambda运算符的左侧是参数列表&#xff0c;它们…

GRASSHOPPER电池Expression

Grasshopper中如果要实现简单的条件if语句的效果&#xff0c;可以使用电池Expression。 举例&#xff1a;获取两个数的差值&#xff0c;永远用大数减去小数

代码随想录算法训练营day45

70. 爬楼梯 &#xff08;进阶&#xff09; 五部曲&#xff1a; dp数组下标及含义&#xff1a;爬到有i个台阶的楼顶&#xff0c;有dp[i]种方法dp数组初始化&#xff1a;dp[0]1递推公式&#xff1a;dp[i] dp[i - j]遍历方向&#xff1a;target放在外循环&#xff0c;将nums放在…

OpenUI在windows下部署使用

OpenUI OpenUI是一个基于Python的AI对话平台&#xff0c;支持接入多种AI模型。 通过聊天的方式来进行UI设计&#xff0c;你可以通过文字来描述你想要的UI界面&#xff0c;OpenUI可以帮你实时进行渲染出效果 安装OpenUI 这里预设你的电脑上已安装git、Python和pip&#xff0…

Migrations

Entity Framework的Migrations工具是一个版本控制和数据库迁移的系统&#xff0c;它允许开发者以编程方式管理数据库模式的变更。 在使用Entity Framework时&#xff0c;开发者可以通过代码先行&#xff08;Code First&#xff09;的方式定义数据模型&#xff0c;然后使用Migr…